SlideShare a Scribd company logo
Distributed app
 development
 node.js + zeroMQ = awwyeah
ZeroMQ from a noob’s
     viewpoint
RUBEN TAN

• NodeJS enthusiast
• Author of eazy
  (https://github.com/soggie/eazy)


• Dota 2-er
DISCLAIMER

• I AM NOT A ZEROMQ EXPERT
• (not even remotely close)
• Case study by consulting a successful
  implementer of ZMQ in an adserver
Objective

• 1,000,000,000 ad impressions per month
  (on average)
• 80ms maximum response time for each ad
• Good luck, Apache
Webserver Choices

• Netty - Java can actually be fast
  https://netty.io


• Gevent - For Python lovers
  http://gevent.org/


• Node.js - The reason why you’re here
  http://nodejs.org/
So... which one?
• All 3, but that’s not the point
• Speed isn’t the most important factor
• Reliability under load is more important
    than pure performance
• 1 missed impression = 1 potential disaster
    (imagine BMW ads showing up in ThePirateBay)

•   (but secretly, I prefer node.js)
Welcome to the
distributed app
   ecosystem
Definitions, definitions

• Distributed: distributed across multiple
  geological “clouds”
• Apps: each app handles a small scope of
  responsibility
• Ecosystem: apps talk to apps via a
  standardized protocol
Distributed

• Route 53 -> HAProxy -> Webserver ->
  Apps
• Scale webservers by creating new instances
  behind HAProxy
• Scale apps by creating new instances in
  their own clouds
Distributed
                   Route 53 (DNS)

                  HAProxy “LB layer”

Webserver            Webserver            Webserver




      App cloud                        App cloud
        (EU)                             (NA)
Apps

• Each app should perform ONE single
  domain of function
• Write the app like you’re writing an API
• The simpler the app, the better
• App can be written in any language
User app

• List of exposed API:
  •   create new user

  •   edit user

  •   delete user

  •   merge user accounts

  •   authenticate user
Ecosystem

• Apps communicate using JSON-RPC
• Apps connect to each other using ZMQ
• “Controller” scripts and monit handles
  lifecycle
Quick & dirty ZeroMQ
• ZMQ = socket library
• Types of socket:
 •   inproc

 •   IPC

 •   TCP

 •   pgm

 •   epgm
Socket Types

• Push-pull
• Req-rep
• Pub-sub (not covered)
• Dealer-router (not covered)
• Xreq-xrep (not covered)
Push-pull
• Push socket pushes data to pull socket(s)
• Pull socket pulls data from push socket(s)

       Push                     Pull
      Socket                   Socket
Push-pull

• Use cases:
 •   Sending email: apps pushes email data to email app

 •   Logging: apps pushes messages to a logging app

 •   Data crunching: apps pushes partials to processing app(s) to work on

 •   Analytics: apps pushes tracking data to analytics app to process
Push-pull

• Push socket can connect to multiple pull
  sockets (fan-out)
• Pull sockets can listen on multiple push
  sockets (fan-in)
• Best part: ZeroMQ handles the load
  balancing (usually via a LRU)
Advanced Push-Pull
• Example: Log file processing
• Log file needs to be parsed
• Push app (ventilator) parses the log file
• Push app continuously fires partials to pull
  apps (workers)
• Workers push into another pull app
  (collector)
Advanced Push-pull
                           Worker




                           Worker
             push                   push
Ventilator                                        Collector
                    pull                   pull
                           Worker




                           Worker
How do we scale?
ADD MORE
WORKERS
Req-rep

• Req socket sends data to rep socket
• Rep socket receives data from req socket
• Rep socket replies to req socket
• NOTE: Req socket always expects
  replies
  (remember that girl that you waited 5 years for?)
Req-rep

• Use cases:
 •   Inter-app communications: apps that has dependencies between
     each other uses a REQ-REP pattern

 •   Caching: apps req cached items from cache app, cache app rep with
     cached item

 •   API: 3rd party developers issue req to your API app, which filters the
     request and replies with the results
Req-rep
 REQ                   REP
Socket                Socket
          req

 REQ                   REP
Socket                Socket



                rep
 REQ                   REP
Socket                Socket
How to scale?
ADD MORE REP APPS
All together now...
Sample ZMQ code:
 01   var zmq = require('zmq'),
 02     push = zmq.socket('push'),
 03     pullA = zmq.socket('pull'),
 04     pullB = zmq.socket('pull');
 05
 06   pullA.on('message', function (msg) {
 07     console.log('pullA received ' + msg);
 08   });
 09
 10   pullB.on('message', function (msg) {
 11     console.log('pullB received ' + msg);
 12   });
 13
 14   pullA.bindSync('inproc://nodehack-rocks');
 15   pullB.bindSync('inproc://oh-la-la');
 16
 17   push.connect('inproc://nodehack-rocks');
 18   push.connect('inproc://oh-la-la');
 19
 20   for (var i = 0; i < 10; i++) {
 21     push.send('this is message ' + i);
 22   }
Notes
• Each app can define and use multiple ZMQ
  sockets
• You can organize your app’s internals using
  inproc ZMQ sockets (better MVC)
• Controller scripts are important
• There are advanced patterns for reliability
  (read the ZMQ guide)
Libraries

• NodeJS ZMQ binding
  (https://github.com/JustinTulloss/zeromq.node)


• ZMQ Guide
  (http://zguide.zeromq.org/page:all)


• Eazy
  (https://github.com/soggie/eazy)
- the end -

More Related Content

PPT
Leveraging zeromq for node.js
PDF
ZeroMQ with NodeJS
PPTX
Build reliable, traceable, distributed systems with ZeroMQ
PPTX
ZeroMQ: Super Sockets - by J2 Labs
PPTX
zeromq
PDF
Introduction to ZeroMQ - eSpace TechTalk
PDF
Zmq in context of openstack
PDF
Zeromq anatomy & jeromq
Leveraging zeromq for node.js
ZeroMQ with NodeJS
Build reliable, traceable, distributed systems with ZeroMQ
ZeroMQ: Super Sockets - by J2 Labs
zeromq
Introduction to ZeroMQ - eSpace TechTalk
Zmq in context of openstack
Zeromq anatomy & jeromq

What's hot (20)

ODP
Overview of ZeroMQ
KEY
PDF
Lindsay distributed geventzmq
KEY
Europycon2011: Implementing distributed application using ZeroMQ
ODP
Event Driven with LibUV and ZeroMQ
PDF
ZeroMQ - Sockets on steroids!
PDF
High-Performance Networking Using eBPF, XDP, and io_uring
ODP
CurveZMQ, ZMTP and other Dubious Characters
PDF
Skydive 5/07/2016
KEY
Zero mq logs
PDF
Skydive, real-time network analyzer, container integration
PDF
Skydive, real-time network analyzer
PDF
Skydive 31 janv. 2016
PDF
The art of concurrent programming
PDF
Rust Is Safe. But Is It Fast?
ODP
Rust Primer
PDF
Netty @Apple: Large Scale Deployment/Connectivity
PDF
Practical SystemTAP basics: Perl memory profiling
Overview of ZeroMQ
Lindsay distributed geventzmq
Europycon2011: Implementing distributed application using ZeroMQ
Event Driven with LibUV and ZeroMQ
ZeroMQ - Sockets on steroids!
High-Performance Networking Using eBPF, XDP, and io_uring
CurveZMQ, ZMTP and other Dubious Characters
Skydive 5/07/2016
Zero mq logs
Skydive, real-time network analyzer, container integration
Skydive, real-time network analyzer
Skydive 31 janv. 2016
The art of concurrent programming
Rust Is Safe. But Is It Fast?
Rust Primer
Netty @Apple: Large Scale Deployment/Connectivity
Practical SystemTAP basics: Perl memory profiling
Ad

Viewers also liked (20)

PDF
Introduction to ZeroMQ
PDF
Scala and ZeroMQ: Events beyond the JVM
ODP
Case study: Insegnalo
ODP
Case study: iTunes for K-12
ODP
CouchDB @ PoliMi
ODP
Chansonnier: web application for multimedia search on song videos
PPTX
Queue System and Zend\Queue implementation
PDF
Queue your work
PDF
Faster PHP apps using Queues and Workers
ODP
Blind detection of image manipulation @ PoliMi
PPTX
PHP and node.js Together
PDF
Building Scalable, Highly Concurrent & Fault Tolerant Systems - Lessons Learned
PDF
Comet with node.js and V8
ODP
Sistema de Mensajeria de Colas con ZeroMQ y Python
PDF
Distributed Queue System using Gearman
ODP
Case study: Khan Academy
PDF
Software Architecture over ZeroMQ
PDF
ZeroMQ Is The Answer
PPTX
Navigation system for blind using GPS & GSM
PPTX
Map Projections, Datums, GIS and GPS for Everyone
Introduction to ZeroMQ
Scala and ZeroMQ: Events beyond the JVM
Case study: Insegnalo
Case study: iTunes for K-12
CouchDB @ PoliMi
Chansonnier: web application for multimedia search on song videos
Queue System and Zend\Queue implementation
Queue your work
Faster PHP apps using Queues and Workers
Blind detection of image manipulation @ PoliMi
PHP and node.js Together
Building Scalable, Highly Concurrent & Fault Tolerant Systems - Lessons Learned
Comet with node.js and V8
Sistema de Mensajeria de Colas con ZeroMQ y Python
Distributed Queue System using Gearman
Case study: Khan Academy
Software Architecture over ZeroMQ
ZeroMQ Is The Answer
Navigation system for blind using GPS & GSM
Map Projections, Datums, GIS and GPS for Everyone
Ad

Similar to Distributed app development with nodejs and zeromq (20)

PDF
NullMQ @ PDX
PDF
Real time web apps
PDF
Building Web APIs that Scale
PDF
Network-Connected Development with ZeroMQ
 
KEY
Realtime rocks
PPTX
Real time websites and mobile apps with SignalR
KEY
Network with node
PDF
Real-Time with Flowdock
PDF
Distributed Reactive Services with Reactor & Spring - Stéphane Maldini
PPTX
VisualWeb - Building a NodeJS Server Meshwork and Full-Javascript Stack Frame...
PPTX
øMQ Vortrag
PDF
ØMQ - An Introduction
PDF
Developing realtime apps with Drupal and NodeJS
PDF
Building businesspost.ie using Node.js
PPTX
Building and Scaling Node.js Applications
PPTX
WebSocket protocol
PDF
Building and Scaling a WebSockets Pubsub System
PDF
Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...
PDF
Realtime web apps rails
PDF
Firebase introduction
NullMQ @ PDX
Real time web apps
Building Web APIs that Scale
Network-Connected Development with ZeroMQ
 
Realtime rocks
Real time websites and mobile apps with SignalR
Network with node
Real-Time with Flowdock
Distributed Reactive Services with Reactor & Spring - Stéphane Maldini
VisualWeb - Building a NodeJS Server Meshwork and Full-Javascript Stack Frame...
øMQ Vortrag
ØMQ - An Introduction
Developing realtime apps with Drupal and NodeJS
Building businesspost.ie using Node.js
Building and Scaling Node.js Applications
WebSocket protocol
Building and Scaling a WebSockets Pubsub System
Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...
Realtime web apps rails
Firebase introduction

More from Ruben Tan (10)

PDF
Basic distributed systems principles
PDF
Demystifying blockchains
PDF
Banking on blockchains
PDF
Consensus in distributed computing
PDF
Defensive programming in Javascript and Node.js
PDF
Client-side storage
KEY
How we git - commit policy and code review
KEY
NodeHack #2 - MVP
KEY
40 square's git workflow
KEY
Unit testing for 40 square software
Basic distributed systems principles
Demystifying blockchains
Banking on blockchains
Consensus in distributed computing
Defensive programming in Javascript and Node.js
Client-side storage
How we git - commit policy and code review
NodeHack #2 - MVP
40 square's git workflow
Unit testing for 40 square software

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPT
Teaching material agriculture food technology
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Getting Started with Data Integration: FME Form 101
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
1. Introduction to Computer Programming.pptx
PDF
Machine learning based COVID-19 study performance prediction
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Empathic Computing: Creating Shared Understanding
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Machine Learning_overview_presentation.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
Electronic commerce courselecture one. Pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Teaching material agriculture food technology
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Big Data Technologies - Introduction.pptx
Getting Started with Data Integration: FME Form 101
Encapsulation_ Review paper, used for researhc scholars
A comparative analysis of optical character recognition models for extracting...
1. Introduction to Computer Programming.pptx
Machine learning based COVID-19 study performance prediction
MYSQL Presentation for SQL database connectivity
Empathic Computing: Creating Shared Understanding
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Per capita expenditure prediction using model stacking based on satellite ima...
Group 1 Presentation -Planning and Decision Making .pptx
Network Security Unit 5.pdf for BCA BBA.
Unlocking AI with Model Context Protocol (MCP)
Machine Learning_overview_presentation.pptx
Programs and apps: productivity, graphics, security and other tools

Distributed app development with nodejs and zeromq

  • 1. Distributed app development node.js + zeroMQ = awwyeah
  • 2. ZeroMQ from a noob’s viewpoint
  • 3. RUBEN TAN • NodeJS enthusiast • Author of eazy (https://github.com/soggie/eazy) • Dota 2-er
  • 4. DISCLAIMER • I AM NOT A ZEROMQ EXPERT • (not even remotely close) • Case study by consulting a successful implementer of ZMQ in an adserver
  • 5. Objective • 1,000,000,000 ad impressions per month (on average) • 80ms maximum response time for each ad • Good luck, Apache
  • 6. Webserver Choices • Netty - Java can actually be fast https://netty.io • Gevent - For Python lovers http://gevent.org/ • Node.js - The reason why you’re here http://nodejs.org/
  • 7. So... which one? • All 3, but that’s not the point • Speed isn’t the most important factor • Reliability under load is more important than pure performance • 1 missed impression = 1 potential disaster (imagine BMW ads showing up in ThePirateBay) • (but secretly, I prefer node.js)
  • 9. Definitions, definitions • Distributed: distributed across multiple geological “clouds” • Apps: each app handles a small scope of responsibility • Ecosystem: apps talk to apps via a standardized protocol
  • 10. Distributed • Route 53 -> HAProxy -> Webserver -> Apps • Scale webservers by creating new instances behind HAProxy • Scale apps by creating new instances in their own clouds
  • 11. Distributed Route 53 (DNS) HAProxy “LB layer” Webserver Webserver Webserver App cloud App cloud (EU) (NA)
  • 12. Apps • Each app should perform ONE single domain of function • Write the app like you’re writing an API • The simpler the app, the better • App can be written in any language
  • 13. User app • List of exposed API: • create new user • edit user • delete user • merge user accounts • authenticate user
  • 14. Ecosystem • Apps communicate using JSON-RPC • Apps connect to each other using ZMQ • “Controller” scripts and monit handles lifecycle
  • 15. Quick & dirty ZeroMQ • ZMQ = socket library • Types of socket: • inproc • IPC • TCP • pgm • epgm
  • 16. Socket Types • Push-pull • Req-rep • Pub-sub (not covered) • Dealer-router (not covered) • Xreq-xrep (not covered)
  • 17. Push-pull • Push socket pushes data to pull socket(s) • Pull socket pulls data from push socket(s) Push Pull Socket Socket
  • 18. Push-pull • Use cases: • Sending email: apps pushes email data to email app • Logging: apps pushes messages to a logging app • Data crunching: apps pushes partials to processing app(s) to work on • Analytics: apps pushes tracking data to analytics app to process
  • 19. Push-pull • Push socket can connect to multiple pull sockets (fan-out) • Pull sockets can listen on multiple push sockets (fan-in) • Best part: ZeroMQ handles the load balancing (usually via a LRU)
  • 20. Advanced Push-Pull • Example: Log file processing • Log file needs to be parsed • Push app (ventilator) parses the log file • Push app continuously fires partials to pull apps (workers) • Workers push into another pull app (collector)
  • 21. Advanced Push-pull Worker Worker push push Ventilator Collector pull pull Worker Worker
  • 22. How do we scale?
  • 24. Req-rep • Req socket sends data to rep socket • Rep socket receives data from req socket • Rep socket replies to req socket • NOTE: Req socket always expects replies (remember that girl that you waited 5 years for?)
  • 25. Req-rep • Use cases: • Inter-app communications: apps that has dependencies between each other uses a REQ-REP pattern • Caching: apps req cached items from cache app, cache app rep with cached item • API: 3rd party developers issue req to your API app, which filters the request and replies with the results
  • 26. Req-rep REQ REP Socket Socket req REQ REP Socket Socket rep REQ REP Socket Socket
  • 28. ADD MORE REP APPS
  • 30. Sample ZMQ code: 01 var zmq = require('zmq'), 02 push = zmq.socket('push'), 03 pullA = zmq.socket('pull'), 04 pullB = zmq.socket('pull'); 05 06 pullA.on('message', function (msg) { 07 console.log('pullA received ' + msg); 08 }); 09 10 pullB.on('message', function (msg) { 11 console.log('pullB received ' + msg); 12 }); 13 14 pullA.bindSync('inproc://nodehack-rocks'); 15 pullB.bindSync('inproc://oh-la-la'); 16 17 push.connect('inproc://nodehack-rocks'); 18 push.connect('inproc://oh-la-la'); 19 20 for (var i = 0; i < 10; i++) { 21 push.send('this is message ' + i); 22 }
  • 31. Notes • Each app can define and use multiple ZMQ sockets • You can organize your app’s internals using inproc ZMQ sockets (better MVC) • Controller scripts are important • There are advanced patterns for reliability (read the ZMQ guide)
  • 32. Libraries • NodeJS ZMQ binding (https://github.com/JustinTulloss/zeromq.node) • ZMQ Guide (http://zguide.zeromq.org/page:all) • Eazy (https://github.com/soggie/eazy)

Editor's Notes