SlideShare a Scribd company logo
Node.js and Cassandra
For highly concurrent systems
Software as a service
Most common scenario

•
•
•

I/O Bound
o db
o other services
o file system
Low CPU usage
Peaks and valleys
Why Node.js
Why Node.js
Event-based

•
•
•
•

Single threaded
Minimum overhead per connection
Predictable amount of memory under load
Apache / IIS vs Nginx: Process-based vs event-loop

Everything runs in parallel except your code
Why Node.js
Event-based: Apache vs Nginx

source webfaction.com
Why Node.js
Async I/O

•
•

Uses OS network interfaces + fixed thread pool
Time spent: db connections / files
Why Node.js
Javascript: Closures

•
•
•
•

CPS: Continuation passing style
The scope of the outer function -> inner function
Javascript: Functional / Dynamic / Object oriented
... packet manager / os community / V8 / ubiquitous...
Why Node.js
Stream everything

•
•
•
•

Avoid buffering
HTTP: Chunked requests and responses
TCP: Chunks readable in a stream
Stream Piping (UNIX like)
The Driver for Cassandra
The Driver for Cassandra
Features

•
•
•
•
•

Connection pooling to multiple hosts
Load balancing
Automatic failover / retry
Row and field streaming
Queuing: Concurrent connecting / preparing
The Driver for Cassandra
App

Cassandra nodes

A
G

E

D

C

F

H
B
The Driver for Cassandra
Sample: Json Web Api
1

app.get('/user/:id', function (req, res, next){

2

var query = 'SELECT * FROM users WHERE id = ?';

3

cassandra.executeAsPrepared(query, [req.params.id], function (err, result) {

4

if (err) return next(err);

5

var row = result.rows[0];

6

//Response: expose some properties of the user

7

res.json({id: req.params.id, name: row.get('name')});

8
9

});
});
The Driver for Cassandra
How row streaming works
Readable
stream

Transform
stream

Transform
stream

Socket

Protocol

Parser

Chunks

Heade
r and
body
chunk
s

Client

Row
The Driver for Cassandra
Sample: Field streaming
1

app.get('/user/:id/image', function (req, res, next){

2

var query = 'SELECT id, profile_image FROM users WHERE id = ?';

3

cassandra.streamField(query, [req.params.id], function (err, row, image) {

4

if (err) return next(err);

5

//pipe the image stream to the response stream

6

image.pipe(res);

7
8

});
});
The Driver for Cassandra
Sample: Field streaming + image resizing
1

app.get('/user/:id/image', function (req, res, next){

2

var query = 'SELECT id, profile_image FROM users WHERE id = ?';

3

cassandra.streamField(query, [req.params.id], function (err, row, image) {

4

if (err) return next(err);

5

//pipe the image stream to a resizer stream

6

image.pipe(resizer).pipe(res);

7
8

});
});
Moving forward
Next features

•
•

Multiple data centers support.
Cassandra query tracing

Contribute! :)
Thanks!

Jorge Bay Gondra
@jorgebg
jorgebaygondra@gmail.com
github.com/jorgebay/node-cassandra-cql
npm install node-cassandra-cql
A Design Framework for Highly Concurrent Systems by Matt Welsh, Steven D. Gribble, Eric A.
Brewer, and David Culler @ UC Berkeley
Concurrency is not Parallelism (it's better) by Rob Pike @Google Go lang
How the single threaded non blocking IO model works in Node.js

References and further reading

More Related Content

PDF
Cassandra NodeJS driver & NodeJS Paris
PPTX
Using Cassandra with your Web Application
PDF
How you can contribute to Apache Cassandra
PDF
Cassandra Introduction & Features
PPTX
Cassandra & puppet, scaling data at $15 per month
PDF
Cassandra Day SV 2014: Netflix’s Astyanax Java Client Driver for Apache Cassa...
ODP
Cassandra - Tips And Techniques
PDF
ETL With Cassandra Streaming Bulk Loading
Cassandra NodeJS driver & NodeJS Paris
Using Cassandra with your Web Application
How you can contribute to Apache Cassandra
Cassandra Introduction & Features
Cassandra & puppet, scaling data at $15 per month
Cassandra Day SV 2014: Netflix’s Astyanax Java Client Driver for Apache Cassa...
Cassandra - Tips And Techniques
ETL With Cassandra Streaming Bulk Loading

What's hot (20)

PDF
Cassandra Summit 2014: Reading Cassandra SSTables Directly for Offline Data A...
ODP
Intro to cassandra
PDF
Postgres connections at scale
ODP
Introduction to Structured Streaming
PDF
Introduction to Akka-Streams
PDF
[245] presto 내부구조 파헤치기
PPT
Apache cassandra
PDF
Helsinki Cassandra Meetup #2: From Postgres to Cassandra
PPTX
Asynchronous Orchestration DSL on squbs
PDF
Bulk Loading Data into Cassandra
PPTX
Understanding How CQL3 Maps to Cassandra's Internal Data Structure
PDF
Operations, Consistency, Failover for Multi-DC Clusters (Alexander Dejanovski...
PPT
Introduction to apache_cassandra_for_develope
PPTX
JahiaOne - Performance Tuning
PDF
Designing Scalable and Extendable Data Pipeline for Call Of Duty Games
PDF
Mysqlconf2013 mariadb-cassandra-interoperability
PPTX
Learning Cassandra
PDF
Spark / Mesos Cluster Optimization
PDF
Converting a naive flow to akka streams
PPTX
Apache Cassandra Developer Training Slide Deck
Cassandra Summit 2014: Reading Cassandra SSTables Directly for Offline Data A...
Intro to cassandra
Postgres connections at scale
Introduction to Structured Streaming
Introduction to Akka-Streams
[245] presto 내부구조 파헤치기
Apache cassandra
Helsinki Cassandra Meetup #2: From Postgres to Cassandra
Asynchronous Orchestration DSL on squbs
Bulk Loading Data into Cassandra
Understanding How CQL3 Maps to Cassandra's Internal Data Structure
Operations, Consistency, Failover for Multi-DC Clusters (Alexander Dejanovski...
Introduction to apache_cassandra_for_develope
JahiaOne - Performance Tuning
Designing Scalable and Extendable Data Pipeline for Call Of Duty Games
Mysqlconf2013 mariadb-cassandra-interoperability
Learning Cassandra
Spark / Mesos Cluster Optimization
Converting a naive flow to akka streams
Apache Cassandra Developer Training Slide Deck
Ad

Viewers also liked (6)

PDF
Cassandra at NoSql Matters 2012
PDF
NodeJS : Communication and Round Robin Way
PDF
Application Development with Apache Cassandra as a Service
PPTX
Cassandra DataTables Using RESTful API
PPTX
Cassandra Java APIs Old and New – A Comparison
PDF
Developing with Cassandra
Cassandra at NoSql Matters 2012
NodeJS : Communication and Round Robin Way
Application Development with Apache Cassandra as a Service
Cassandra DataTables Using RESTful API
Cassandra Java APIs Old and New – A Comparison
Developing with Cassandra
Ad

Similar to Node.js and Cassandra (20)

PPTX
Building Web Apps with Express
PPTX
Copper: A high performance workflow engine
PPTX
Intro to node and mongodb 1
PPTX
Node.js Workshop - Sela SDP 2015
PPT
nodejs_at_a_glance.ppt
PPT
nodejs_at_a_glance, understanding java script
KEY
Writing robust Node.js applications
PDF
Writing RESTful web services using Node.js
PPTX
FrameGraph: Extensible Rendering Architecture in Frostbite
ODP
Introduce about Nodejs - duyetdev.com
PPT
Jdbc ppt
ODP
Asynchronous I/O in NodeJS - new standard or challenges?
PDF
Introduction to REST API with Node.js
PDF
KrakenJS
PPT
Node js beginner
PPTX
java database connectivity for java programming
PPTX
Intro to big data analytics using microsoft machine learning server with spark
ODP
Php Site Optimization
PPTX
StrongLoop Overview
Building Web Apps with Express
Copper: A high performance workflow engine
Intro to node and mongodb 1
Node.js Workshop - Sela SDP 2015
nodejs_at_a_glance.ppt
nodejs_at_a_glance, understanding java script
Writing robust Node.js applications
Writing RESTful web services using Node.js
FrameGraph: Extensible Rendering Architecture in Frostbite
Introduce about Nodejs - duyetdev.com
Jdbc ppt
Asynchronous I/O in NodeJS - new standard or challenges?
Introduction to REST API with Node.js
KrakenJS
Node js beginner
java database connectivity for java programming
Intro to big data analytics using microsoft machine learning server with spark
Php Site Optimization
StrongLoop Overview

More from Stratio (20)

PPTX
Mesos Meetup - Building an enterprise-ready analytics and operational ecosyst...
PPTX
Can an intelligent system exist without awareness? BDS18
PPTX
Kafka and KSQL - Apache Kafka Meetup
PPTX
Wild Data - The Data Science Meetup
PPTX
Using Kafka on Event-driven Microservices Architectures - Apache Kafka Meetup
PPTX
Ensemble methods in Machine Learning
PPTX
Stratio Sparta 2.0
PPTX
Big Data Security: Facing the challenge
PPTX
Operationalizing Big Data
PPTX
Artificial Intelligence on Data Centric Platform
PDF
Introduction to Artificial Neural Networks
PDF
“A Distributed Operational and Informational Technological Stack”
PDF
Meetup: Cómo monitorizar y optimizar procesos de Spark usando la Spark Web - ...
PPTX
Lunch&Learn: Combinación de modelos
PDF
Meetup: Spark + Kerberos
PDF
Distributed Logistic Model Trees
PDF
Multiplaform Solution for Graph Datasources
PDF
Stratio's Cassandra Lucene index: Geospatial use cases - Big Data Spain 2016
PPTX
[Strata] Sparkta
PDF
Introduction to Asynchronous scala
Mesos Meetup - Building an enterprise-ready analytics and operational ecosyst...
Can an intelligent system exist without awareness? BDS18
Kafka and KSQL - Apache Kafka Meetup
Wild Data - The Data Science Meetup
Using Kafka on Event-driven Microservices Architectures - Apache Kafka Meetup
Ensemble methods in Machine Learning
Stratio Sparta 2.0
Big Data Security: Facing the challenge
Operationalizing Big Data
Artificial Intelligence on Data Centric Platform
Introduction to Artificial Neural Networks
“A Distributed Operational and Informational Technological Stack”
Meetup: Cómo monitorizar y optimizar procesos de Spark usando la Spark Web - ...
Lunch&Learn: Combinación de modelos
Meetup: Spark + Kerberos
Distributed Logistic Model Trees
Multiplaform Solution for Graph Datasources
Stratio's Cassandra Lucene index: Geospatial use cases - Big Data Spain 2016
[Strata] Sparkta
Introduction to Asynchronous scala

Recently uploaded (20)

PDF
KodekX | Application Modernization Development
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Empathic Computing: Creating Shared Understanding
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Understanding_Digital_Forensics_Presentation.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
KodekX | Application Modernization Development
Spectral efficient network and resource selection model in 5G networks
Review of recent advances in non-invasive hemoglobin estimation
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Dropbox Q2 2025 Financial Results & Investor Presentation
Empathic Computing: Creating Shared Understanding
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
cuic standard and advanced reporting.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
sap open course for s4hana steps from ECC to s4
Chapter 3 Spatial Domain Image Processing.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Spectroscopy.pptx food analysis technology
Network Security Unit 5.pdf for BCA BBA.
Understanding_Digital_Forensics_Presentation.pptx
The AUB Centre for AI in Media Proposal.docx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
“AI and Expert System Decision Support & Business Intelligence Systems”
20250228 LYD VKU AI Blended-Learning.pptx

Node.js and Cassandra

  • 1. Node.js and Cassandra For highly concurrent systems
  • 2. Software as a service Most common scenario • • • I/O Bound o db o other services o file system Low CPU usage Peaks and valleys
  • 4. Why Node.js Event-based • • • • Single threaded Minimum overhead per connection Predictable amount of memory under load Apache / IIS vs Nginx: Process-based vs event-loop Everything runs in parallel except your code
  • 5. Why Node.js Event-based: Apache vs Nginx source webfaction.com
  • 6. Why Node.js Async I/O • • Uses OS network interfaces + fixed thread pool Time spent: db connections / files
  • 7. Why Node.js Javascript: Closures • • • • CPS: Continuation passing style The scope of the outer function -> inner function Javascript: Functional / Dynamic / Object oriented ... packet manager / os community / V8 / ubiquitous...
  • 8. Why Node.js Stream everything • • • • Avoid buffering HTTP: Chunked requests and responses TCP: Chunks readable in a stream Stream Piping (UNIX like)
  • 9. The Driver for Cassandra
  • 10. The Driver for Cassandra Features • • • • • Connection pooling to multiple hosts Load balancing Automatic failover / retry Row and field streaming Queuing: Concurrent connecting / preparing
  • 11. The Driver for Cassandra App Cassandra nodes A G E D C F H B
  • 12. The Driver for Cassandra Sample: Json Web Api 1 app.get('/user/:id', function (req, res, next){ 2 var query = 'SELECT * FROM users WHERE id = ?'; 3 cassandra.executeAsPrepared(query, [req.params.id], function (err, result) { 4 if (err) return next(err); 5 var row = result.rows[0]; 6 //Response: expose some properties of the user 7 res.json({id: req.params.id, name: row.get('name')}); 8 9 }); });
  • 13. The Driver for Cassandra How row streaming works Readable stream Transform stream Transform stream Socket Protocol Parser Chunks Heade r and body chunk s Client Row
  • 14. The Driver for Cassandra Sample: Field streaming 1 app.get('/user/:id/image', function (req, res, next){ 2 var query = 'SELECT id, profile_image FROM users WHERE id = ?'; 3 cassandra.streamField(query, [req.params.id], function (err, row, image) { 4 if (err) return next(err); 5 //pipe the image stream to the response stream 6 image.pipe(res); 7 8 }); });
  • 15. The Driver for Cassandra Sample: Field streaming + image resizing 1 app.get('/user/:id/image', function (req, res, next){ 2 var query = 'SELECT id, profile_image FROM users WHERE id = ?'; 3 cassandra.streamField(query, [req.params.id], function (err, row, image) { 4 if (err) return next(err); 5 //pipe the image stream to a resizer stream 6 image.pipe(resizer).pipe(res); 7 8 }); });
  • 16. Moving forward Next features • • Multiple data centers support. Cassandra query tracing Contribute! :)
  • 18. A Design Framework for Highly Concurrent Systems by Matt Welsh, Steven D. Gribble, Eric A. Brewer, and David Culler @ UC Berkeley Concurrency is not Parallelism (it's better) by Rob Pike @Google Go lang How the single threaded non blocking IO model works in Node.js References and further reading