SlideShare a Scribd company logo
NodeJS Cassandra driver 
DuyHai DOAN, Technical Advocate 
@doanduyhai
Shameless self-promotion! 
@doanduyhai 
2 
Duy Hai DOAN 
Cassandra technical advocate 
• talks, meetups, confs 
• open-source devs (Achilles, …) 
• Cassandra technical point of contact 
duy_hai.doan@datastax.com
Agenda! 
@doanduyhai 
3 
C* quick intro 
• Cluster, Replication, Consistency, Data Model 
NodeJS Driver 
• Architecture, Streaming, API 
Live DEMO!
Cassandra history! 
@doanduyhai 
4 
NoSQL database 
• created at Facebook 
• open-sourced since 2008 
• current version = 2.1 
• column-oriented ☞ distributed table
Cassandra in 5 points! 
@doanduyhai 
5 
• Linear scalability 
• Continuous availability (≈100% up-time) 
• Multi-data centers 
• Consistent performance (99% percentile) 
• Operational simplicity
Cassandra quick intro! 
Cluster 
Replication 
Consistency
Cluster! 
@doanduyhai 
7 
Random: hash of #partition → token = hash(#p) 
Hash: ]0, 2127-1] 
Each node: 1/8 of ]0, 2127-1] 
n1 
n2 
n3 
n4 
n5 
n6 
n7 
n8
Linear scalability! 
@doanduyhai 
8 
n1 
n2 
8 nodes 10 nodes 
n3 
n4 
n5 
n6 
n7 
n8 
n1 
n2 
n3 n4 
n5 
n6 
n7 
n9 n8 
n10
Failure tolerance! 
@doanduyhai 
9 
Replication Factor (RF) = 3 
n1 
n2 
n3 
n4 
n5 
n6 
n7 
n8 
1 
2 
3
Coordinator node! 
Incoming requests (read/write) 
Coordinator node handles the request 
Every node can be coordinator àmasterless 
@doanduyhai 
n1 
n2 
n3 
n4 
n5 
n6 
n7 
n8 
1 
2 
3 
coordinator 
request
Consistency! 
@doanduyhai 
11 
Tunable at runtime 
• ONE 
• QUORUM (strict majority w.r.t. RF) 
• ALL 
Apply both to read & write
Write consistency! 
Write ONE 
• write request to all replicas in // 
• wait for ONE ack before returning to 
client 
• other acks later, asynchronously 
@doanduyhai 
n1 
n2 
n3 
n4 
n5 
n6 
n7 
n8 
1 
2 
3 
coordinator
Write consistency! 
Write QUORUM 
• write request to all replicas in // 
• wait for QUORUM acks before 
returning to client 
• other acks later, asynchronously 
@doanduyhai 
n1 
n2 
n3 
n4 
n5 
n6 
n7 
n8 
1 
2 
3 
coordinator
Read consistency! 
Read ONE 
• read from one node among all replicas 
• contact the least-loaded node (stats) 
@doanduyhai 
n1 
n2 
n3 
n4 
n5 
n6 
n7 
n8 
1 
2 
3 
coordinator
Read consistency! 
Read QUORUM 
• read from one least-loaded node 
• AND request digest from other 
replicas to reach QUORUM 
• return most up-to-date data to client 
• repair if digest mismatch n1 
@doanduyhai 
n2 
n3 
n4 
n5 
n6 
n7 
n8 
1 
2 
3 
coordinator
Consistency trade-off! 
@doanduyhai 
16
CRUD Operations! 
@doanduyhai 
17 
INSERT INTO users(login, name, age) VALUES(‘jdoe’, ‘John DOE’, 33); 
UPDATE users SET age = 34 WHERE login = jdoe; 
DELETE age FROM users WHERE login = jdoe; 
SELECT age FROM users WHERE login = jdoe;
DDL! 
@doanduyhai 
18 
CREATE TABLE users ( 
login text, 
name text, 
age int, 
… 
PRIMARY KEY(login)); 
partition key (#partition)
Cassandra NodeJS Driver! 
Architecture! 
Streaming! 
API!
Connection pooling! 
@doanduyhai 
20 
n3 
n2 
n4 
Client 
Pool1 
Pool2 
Pool3 
CallBack1 
CallBack2 
CallBack3
Request Pipelining! 
@doanduyhai 
21 
Client Cassandra
Request Pipelining! 
@doanduyhai 
22 
Client Cassandra 
StreamID 
StreamID
Nodes Discovery! 
@doanduyhai 
23 
n2 
n3 
n4 
n5 
n6 
n7 
n8 
Control Connection 
n1 Client
Round Robin Load Balancing! 
@doanduyhai 
24 
n2 
n3 
n4 
n5 
n6 
n7 
n8 
n1 Client 
1 
2 
3 
4
DC Aware Load Balancing! 
@doanduyhai 
25 
Client1 DC1 
⤫ 
Client2 DC2
DC Aware Load Balancing! 
@doanduyhai 
26 
⤫ 
Client1 DC1 
Client2 DC2
Token Aware Load Balancing! 
@doanduyhai 
27 
n2 
n3 
n4 
n5 
n6 
n7 
n8 
1 
n1 Client 
2 
3 
⤫
Combining Load Balancing Policies! 
Token Aware 
Round Robin DC Aware Round Robin 
@doanduyhai 
28 
extends 
Load Balancing Policy 
wraps 
Default config
Automatic Failover! 
@doanduyhai 
29 
n3 
n2 
n4 
Client 
Pool1 
Pool2 
Pool3 
Request 
⤫
Other policies! 
@doanduyhai 
30 
Retry policy 
• write/read timeout 
• node unavailable 
Reconnection policy 
• constant schedule 
• exponential schedule
Where do I get the driver ?! 
@doanduyhai 
31 
$ npm install cassandra-driver
Common Usage! 
@doanduyhai 
32 
var cassandra = require('cassandra-driver'); 
var client = new cassandra.Client({contactPoints: [’192.168.0.12', ’node2'], 
keyspace: ’my_keyspace'}); 
var query = 'SELECT email, last_name FROM users WHERE login=?'; 
client.execute(query, [’jdoe'], function(err, result) { 
console.log('got user with email ' + result.rows[0].email); 
});
API! 
@doanduyhai 
33 
Insert/Update 
var query = ‘’INSERT INTO sensor_data(id,date,value) VALUES(?, ?, ?)’’; 
client.query(query, 
[‘mySensor’, ‘2014-10-15 12:00:00’, 34.5], 
{prepare: true, consistency: cassandra.types.consistencies.one}, 
function(err) { //error handling });
API! 
@doanduyhai 
34 
Select 
var query = ‘’SELECT * sensor_data WHERE id = ?’’; 
client.query(query, 
[‘mySensor’], 
{prepare: true, consistency: cassandra.types.consistencies.one}, 
function(err, result) { 
result.rows.forEach(function(row) { 
console.log(‘value = ‘ + row.value); 
}); 
});
API! 
@doanduyhai 
35 
Client creation 
new cassandra.Client( 
{ 
policies: {}, // load balancing, retry, reconnection 
queryOptions: {}, // default consistency, fetchSize 
protocolOptions: {}, // port 
pooling: {}, // #connection/host 
socketOptions: {}, //timeout 
authProvider: {}, //plain text login/password, SSL 
maxPrepared: 500});
Streaming! 
@doanduyhai 
36 
var query = ‘’SELECT * FROM sensor_data‘’; 
var stream = client.stream(query, [ ], {autoPage: true}); 
Default fetchSize = 5000
Streaming! 
@doanduyhai 
37 
stream 
.on(‘end’, function() { 
//no more data 
}) 
.on(‘readable’, function() { 
while (row = this.read()) { 
// do something with the row 
} 
}) 
.on(‘error’, function(err) { 
// process error 
});
Types! 
@doanduyhai 
38 
Cassandra Javascript 
bigint Long (dCodeIO) 
blob Buffer 
boolean Boolean 
counter Long (dCodeIO) 
Decimal Buffer 
Double Number 
Float Number 
int Number 
list Array 
map Object 
set Array 
Cassandra Javascript 
text String 
timestamp Date 
timeuuid String 
uuid String 
varchar* String 
varint* Buffer 
ascii* String
Special types! 
@doanduyhai 
39 
var cassandra = require('cassandra-driver'); 
//generate a new v4 uuid 
var id1 = cassandra.types.uuid(); 
//generate a new v1 uuid 
var id2 = cassandra.types.timeuuid(); 
//big int value 
var bigIntValue = new cassandra.types.Long.fromString("5764607523034211");
Code 
demo
! " 
! 
Q & R
Thank You 
@doanduyhai 
duy_hai.doan@datastax.com

More Related Content

What's hot (20)

PPTX
Kubernetes #4 volume & stateful set
Terry Cho
 
PDF
Asynchronous web apps with the Play Framework 2.0
Oscar Renalias
 
PDF
Load Balancing Applications with NGINX in a CoreOS Cluster
Kevin Jones
 
PDF
How and Why Prometheus' New Storage Engine Pushes the Limits of Time Series D...
Docker, Inc.
 
PPTX
NodeJS Concurrency
pgriess
 
PPTX
Winter is coming? Not if ZooKeeper is there!
Joydeep Banik Roy
 
PPTX
Play + scala + reactive mongo
Max Kremer
 
PDF
Docker 對傳統 DevOps 工具鏈的衝擊 (Docker's Impact on traditional DevOps toolchain)
William Yeh
 
PDF
JavaScript is the new black - Why Node.js is going to rock your world - Web 2...
Tom Croucher
 
PDF
Manchester Hadoop Meetup: Cassandra Spark internals
Christopher Batey
 
KEY
London devops logging
Tomas Doran
 
PDF
Apache Camel in the belly of the Docker whale
Henryk Konsek
 
PPTX
What I learned from FluentConf and then some
Ohad Kravchick
 
PDF
NYC Cassandra Day - Java Intro
Christopher Batey
 
PDF
Massively Scaled High Performance Web Services with PHP
Demin Yin
 
PDF
About Node.js
Artemisa Yescas Engler
 
ODP
Introduction to Mesos
koboltmarky
 
PDF
Networking and Go: An Engineer's Journey (Strangeloop 2019)
Sneha Inguva
 
PDF
Kubernetes internals (Kubernetes 해부하기)
DongHyeon Kim
 
PPTX
A complete guide to Node.js
Prabin Silwal
 
Kubernetes #4 volume & stateful set
Terry Cho
 
Asynchronous web apps with the Play Framework 2.0
Oscar Renalias
 
Load Balancing Applications with NGINX in a CoreOS Cluster
Kevin Jones
 
How and Why Prometheus' New Storage Engine Pushes the Limits of Time Series D...
Docker, Inc.
 
NodeJS Concurrency
pgriess
 
Winter is coming? Not if ZooKeeper is there!
Joydeep Banik Roy
 
Play + scala + reactive mongo
Max Kremer
 
Docker 對傳統 DevOps 工具鏈的衝擊 (Docker's Impact on traditional DevOps toolchain)
William Yeh
 
JavaScript is the new black - Why Node.js is going to rock your world - Web 2...
Tom Croucher
 
Manchester Hadoop Meetup: Cassandra Spark internals
Christopher Batey
 
London devops logging
Tomas Doran
 
Apache Camel in the belly of the Docker whale
Henryk Konsek
 
What I learned from FluentConf and then some
Ohad Kravchick
 
NYC Cassandra Day - Java Intro
Christopher Batey
 
Massively Scaled High Performance Web Services with PHP
Demin Yin
 
About Node.js
Artemisa Yescas Engler
 
Introduction to Mesos
koboltmarky
 
Networking and Go: An Engineer's Journey (Strangeloop 2019)
Sneha Inguva
 
Kubernetes internals (Kubernetes 해부하기)
DongHyeon Kim
 
A complete guide to Node.js
Prabin Silwal
 

Viewers also liked (8)

PDF
NodeJS : Communication and Round Robin Way
Edureka!
 
PDF
Node.js and Cassandra
Stratio
 
PPTX
Cassandra Java APIs Old and New – A Comparison
shsedghi
 
PPTX
Cassandra DataTables Using RESTful API
Simran Kedia
 
PDF
Cassandra at NoSql Matters 2012
jbellis
 
PDF
Application Development with Apache Cassandra as a Service
WSO2
 
PPTX
Using Cassandra with your Web Application
supertom
 
PDF
Developing with Cassandra
Sperasoft
 
NodeJS : Communication and Round Robin Way
Edureka!
 
Node.js and Cassandra
Stratio
 
Cassandra Java APIs Old and New – A Comparison
shsedghi
 
Cassandra DataTables Using RESTful API
Simran Kedia
 
Cassandra at NoSql Matters 2012
jbellis
 
Application Development with Apache Cassandra as a Service
WSO2
 
Using Cassandra with your Web Application
supertom
 
Developing with Cassandra
Sperasoft
 
Ad

Similar to Cassandra NodeJS driver & NodeJS Paris (20)

PDF
Cassandra introduction mars jug
Duyhai Doan
 
PDF
Cassandra introduction apache con 2014 budapest
Duyhai Doan
 
PDF
Introduction to Cassandra & Data model
Duyhai Doan
 
PDF
Cassandra for the ops dos and donts
Duyhai Doan
 
PDF
Cassandra overview
Sean Murphy
 
PDF
Nike Tech Talk: Double Down on Apache Cassandra and Spark
Patrick McFadin
 
PPTX
Cassandra's Sweet Spot - an introduction to Apache Cassandra
Dave Gardner
 
PDF
A Deep Dive into Apache Cassandra for .NET Developers
Luke Tillman
 
PPTX
Apache Cassandra at the Geek2Geek Berlin
Christian Johannsen
 
PDF
Using cassandra as a distributed logging to store pb data
Ramesh Veeramani
 
PDF
An Introduction to Apache Cassandra
Saeid Zebardast
 
PDF
Introduction to Apache Cassandra™ + What’s New in 4.0
DataStax
 
PDF
Introduction to Cassandra
Gokhan Atil
 
PDF
Cassandra and drivers
Ben Bromhead
 
PDF
Cassandra: An Alien Technology That's not so Alien
Brian Hess
 
PPT
5266732.ppt
hothyfa
 
PPTX
BigData Developers MeetUp
Christian Johannsen
 
PDF
About "Apache Cassandra"
Jihyun Ahn
 
PPTX
Netcetera
Scandit
 
PDF
Cassandra and Spark
nickmbailey
 
Cassandra introduction mars jug
Duyhai Doan
 
Cassandra introduction apache con 2014 budapest
Duyhai Doan
 
Introduction to Cassandra & Data model
Duyhai Doan
 
Cassandra for the ops dos and donts
Duyhai Doan
 
Cassandra overview
Sean Murphy
 
Nike Tech Talk: Double Down on Apache Cassandra and Spark
Patrick McFadin
 
Cassandra's Sweet Spot - an introduction to Apache Cassandra
Dave Gardner
 
A Deep Dive into Apache Cassandra for .NET Developers
Luke Tillman
 
Apache Cassandra at the Geek2Geek Berlin
Christian Johannsen
 
Using cassandra as a distributed logging to store pb data
Ramesh Veeramani
 
An Introduction to Apache Cassandra
Saeid Zebardast
 
Introduction to Apache Cassandra™ + What’s New in 4.0
DataStax
 
Introduction to Cassandra
Gokhan Atil
 
Cassandra and drivers
Ben Bromhead
 
Cassandra: An Alien Technology That's not so Alien
Brian Hess
 
5266732.ppt
hothyfa
 
BigData Developers MeetUp
Christian Johannsen
 
About "Apache Cassandra"
Jihyun Ahn
 
Netcetera
Scandit
 
Cassandra and Spark
nickmbailey
 
Ad

More from Duyhai Doan (20)

PDF
Pourquoi Terraform n'est pas le bon outil pour les déploiements automatisés d...
Duyhai Doan
 
PDF
Le futur d'apache cassandra
Duyhai Doan
 
PDF
Big data 101 for beginners devoxxpl
Duyhai Doan
 
PDF
Big data 101 for beginners riga dev days
Duyhai Doan
 
PDF
Datastax enterprise presentation
Duyhai Doan
 
PDF
Datastax day 2016 introduction to apache cassandra
Duyhai Doan
 
PDF
Datastax day 2016 : Cassandra data modeling basics
Duyhai Doan
 
PDF
Sasi, cassandra on the full text search ride At Voxxed Day Belgrade 2016
Duyhai Doan
 
PDF
Apache cassandra in 2016
Duyhai Doan
 
PDF
Spark zeppelin-cassandra at synchrotron
Duyhai Doan
 
PDF
Sasi, cassandra on full text search ride
Duyhai Doan
 
PDF
Cassandra 3 new features @ Geecon Krakow 2016
Duyhai Doan
 
PDF
Algorithme distribués pour big data saison 2 @DevoxxFR 2016
Duyhai Doan
 
PDF
Apache Zeppelin @DevoxxFR 2016
Duyhai Doan
 
PDF
Cassandra 3 new features 2016
Duyhai Doan
 
PDF
Cassandra introduction 2016
Duyhai Doan
 
PDF
Spark cassandra integration 2016
Duyhai Doan
 
PDF
Spark Cassandra 2016
Duyhai Doan
 
PDF
Cassandra introduction 2016
Duyhai Doan
 
PDF
Apache zeppelin the missing component for the big data ecosystem
Duyhai Doan
 
Pourquoi Terraform n'est pas le bon outil pour les déploiements automatisés d...
Duyhai Doan
 
Le futur d'apache cassandra
Duyhai Doan
 
Big data 101 for beginners devoxxpl
Duyhai Doan
 
Big data 101 for beginners riga dev days
Duyhai Doan
 
Datastax enterprise presentation
Duyhai Doan
 
Datastax day 2016 introduction to apache cassandra
Duyhai Doan
 
Datastax day 2016 : Cassandra data modeling basics
Duyhai Doan
 
Sasi, cassandra on the full text search ride At Voxxed Day Belgrade 2016
Duyhai Doan
 
Apache cassandra in 2016
Duyhai Doan
 
Spark zeppelin-cassandra at synchrotron
Duyhai Doan
 
Sasi, cassandra on full text search ride
Duyhai Doan
 
Cassandra 3 new features @ Geecon Krakow 2016
Duyhai Doan
 
Algorithme distribués pour big data saison 2 @DevoxxFR 2016
Duyhai Doan
 
Apache Zeppelin @DevoxxFR 2016
Duyhai Doan
 
Cassandra 3 new features 2016
Duyhai Doan
 
Cassandra introduction 2016
Duyhai Doan
 
Spark cassandra integration 2016
Duyhai Doan
 
Spark Cassandra 2016
Duyhai Doan
 
Cassandra introduction 2016
Duyhai Doan
 
Apache zeppelin the missing component for the big data ecosystem
Duyhai Doan
 

Recently uploaded (20)

PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
July Patch Tuesday
Ivanti
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 

Cassandra NodeJS driver & NodeJS Paris

  • 1. NodeJS Cassandra driver DuyHai DOAN, Technical Advocate @doanduyhai
  • 2. Shameless self-promotion! @doanduyhai 2 Duy Hai DOAN Cassandra technical advocate • talks, meetups, confs • open-source devs (Achilles, …) • Cassandra technical point of contact [email protected]
  • 3. Agenda! @doanduyhai 3 C* quick intro • Cluster, Replication, Consistency, Data Model NodeJS Driver • Architecture, Streaming, API Live DEMO!
  • 4. Cassandra history! @doanduyhai 4 NoSQL database • created at Facebook • open-sourced since 2008 • current version = 2.1 • column-oriented ☞ distributed table
  • 5. Cassandra in 5 points! @doanduyhai 5 • Linear scalability • Continuous availability (≈100% up-time) • Multi-data centers • Consistent performance (99% percentile) • Operational simplicity
  • 6. Cassandra quick intro! Cluster Replication Consistency
  • 7. Cluster! @doanduyhai 7 Random: hash of #partition → token = hash(#p) Hash: ]0, 2127-1] Each node: 1/8 of ]0, 2127-1] n1 n2 n3 n4 n5 n6 n7 n8
  • 8. Linear scalability! @doanduyhai 8 n1 n2 8 nodes 10 nodes n3 n4 n5 n6 n7 n8 n1 n2 n3 n4 n5 n6 n7 n9 n8 n10
  • 9. Failure tolerance! @doanduyhai 9 Replication Factor (RF) = 3 n1 n2 n3 n4 n5 n6 n7 n8 1 2 3
  • 10. Coordinator node! Incoming requests (read/write) Coordinator node handles the request Every node can be coordinator àmasterless @doanduyhai n1 n2 n3 n4 n5 n6 n7 n8 1 2 3 coordinator request
  • 11. Consistency! @doanduyhai 11 Tunable at runtime • ONE • QUORUM (strict majority w.r.t. RF) • ALL Apply both to read & write
  • 12. Write consistency! Write ONE • write request to all replicas in // • wait for ONE ack before returning to client • other acks later, asynchronously @doanduyhai n1 n2 n3 n4 n5 n6 n7 n8 1 2 3 coordinator
  • 13. Write consistency! Write QUORUM • write request to all replicas in // • wait for QUORUM acks before returning to client • other acks later, asynchronously @doanduyhai n1 n2 n3 n4 n5 n6 n7 n8 1 2 3 coordinator
  • 14. Read consistency! Read ONE • read from one node among all replicas • contact the least-loaded node (stats) @doanduyhai n1 n2 n3 n4 n5 n6 n7 n8 1 2 3 coordinator
  • 15. Read consistency! Read QUORUM • read from one least-loaded node • AND request digest from other replicas to reach QUORUM • return most up-to-date data to client • repair if digest mismatch n1 @doanduyhai n2 n3 n4 n5 n6 n7 n8 1 2 3 coordinator
  • 17. CRUD Operations! @doanduyhai 17 INSERT INTO users(login, name, age) VALUES(‘jdoe’, ‘John DOE’, 33); UPDATE users SET age = 34 WHERE login = jdoe; DELETE age FROM users WHERE login = jdoe; SELECT age FROM users WHERE login = jdoe;
  • 18. DDL! @doanduyhai 18 CREATE TABLE users ( login text, name text, age int, … PRIMARY KEY(login)); partition key (#partition)
  • 19. Cassandra NodeJS Driver! Architecture! Streaming! API!
  • 20. Connection pooling! @doanduyhai 20 n3 n2 n4 Client Pool1 Pool2 Pool3 CallBack1 CallBack2 CallBack3
  • 21. Request Pipelining! @doanduyhai 21 Client Cassandra
  • 22. Request Pipelining! @doanduyhai 22 Client Cassandra StreamID StreamID
  • 23. Nodes Discovery! @doanduyhai 23 n2 n3 n4 n5 n6 n7 n8 Control Connection n1 Client
  • 24. Round Robin Load Balancing! @doanduyhai 24 n2 n3 n4 n5 n6 n7 n8 n1 Client 1 2 3 4
  • 25. DC Aware Load Balancing! @doanduyhai 25 Client1 DC1 ⤫ Client2 DC2
  • 26. DC Aware Load Balancing! @doanduyhai 26 ⤫ Client1 DC1 Client2 DC2
  • 27. Token Aware Load Balancing! @doanduyhai 27 n2 n3 n4 n5 n6 n7 n8 1 n1 Client 2 3 ⤫
  • 28. Combining Load Balancing Policies! Token Aware Round Robin DC Aware Round Robin @doanduyhai 28 extends Load Balancing Policy wraps Default config
  • 29. Automatic Failover! @doanduyhai 29 n3 n2 n4 Client Pool1 Pool2 Pool3 Request ⤫
  • 30. Other policies! @doanduyhai 30 Retry policy • write/read timeout • node unavailable Reconnection policy • constant schedule • exponential schedule
  • 31. Where do I get the driver ?! @doanduyhai 31 $ npm install cassandra-driver
  • 32. Common Usage! @doanduyhai 32 var cassandra = require('cassandra-driver'); var client = new cassandra.Client({contactPoints: [’192.168.0.12', ’node2'], keyspace: ’my_keyspace'}); var query = 'SELECT email, last_name FROM users WHERE login=?'; client.execute(query, [’jdoe'], function(err, result) { console.log('got user with email ' + result.rows[0].email); });
  • 33. API! @doanduyhai 33 Insert/Update var query = ‘’INSERT INTO sensor_data(id,date,value) VALUES(?, ?, ?)’’; client.query(query, [‘mySensor’, ‘2014-10-15 12:00:00’, 34.5], {prepare: true, consistency: cassandra.types.consistencies.one}, function(err) { //error handling });
  • 34. API! @doanduyhai 34 Select var query = ‘’SELECT * sensor_data WHERE id = ?’’; client.query(query, [‘mySensor’], {prepare: true, consistency: cassandra.types.consistencies.one}, function(err, result) { result.rows.forEach(function(row) { console.log(‘value = ‘ + row.value); }); });
  • 35. API! @doanduyhai 35 Client creation new cassandra.Client( { policies: {}, // load balancing, retry, reconnection queryOptions: {}, // default consistency, fetchSize protocolOptions: {}, // port pooling: {}, // #connection/host socketOptions: {}, //timeout authProvider: {}, //plain text login/password, SSL maxPrepared: 500});
  • 36. Streaming! @doanduyhai 36 var query = ‘’SELECT * FROM sensor_data‘’; var stream = client.stream(query, [ ], {autoPage: true}); Default fetchSize = 5000
  • 37. Streaming! @doanduyhai 37 stream .on(‘end’, function() { //no more data }) .on(‘readable’, function() { while (row = this.read()) { // do something with the row } }) .on(‘error’, function(err) { // process error });
  • 38. Types! @doanduyhai 38 Cassandra Javascript bigint Long (dCodeIO) blob Buffer boolean Boolean counter Long (dCodeIO) Decimal Buffer Double Number Float Number int Number list Array map Object set Array Cassandra Javascript text String timestamp Date timeuuid String uuid String varchar* String varint* Buffer ascii* String
  • 39. Special types! @doanduyhai 39 var cassandra = require('cassandra-driver'); //generate a new v4 uuid var id1 = cassandra.types.uuid(); //generate a new v1 uuid var id2 = cassandra.types.timeuuid(); //big int value var bigIntValue = new cassandra.types.Long.fromString("5764607523034211");
  • 41. ! " ! Q & R