scaling Node.js apps
with message queues

Kyle Anderson

  • Full-Stack JavaScript Developer (Back-End emphasis)
  • JS Dev since 2014, professionally since 2016
  • Video Nerd for PDXNode
  • Studied Media & Journalism @ Northern Arizona University

Agenda

  1. Horizontal vs. Vertical Scaling
  2. The Master/Worker Model
  3. Queue Concepts
  4. Demo
  5. Queue Implementations

First: Why?

  • Improved Speed for Batch Jobs
  • Added Resiliency
  • Avoids Resource Limitations

Horizontal vs. Vertical Scaling

CPU/RAM

CPU/RAM

CPU/RAM

CPU/RAM

Vertical Scaling

One Machine, Add More Resources

Horizontal Scaling

Multiple Machines, Add More Machines

CPU/RAM

CPU/RAM

CPU/RAM

CPU/RAM

How does Node.js scale?

The Master/Worker Model

Master

Worker

Message Queue

Worker

Worker

The Master/Worker Model

Master 1

Worker

Message Queue

Worker

Worker

Master 2

Queue Concepts

🔃First/Last In/Out 🔃

🔓Locks 🔒

💦Back Pressure🌊

📨Ordered Messages📩

💀Dead-Letter Queue ☠

Demo

Production Example

Production Example

Reddit uses queues to process votes. Simplified explanation:

  1. Update arrow graphic
  2. POST /api/vote
  3. Cache is updated (Vote persists visually)
  4. Vote is added to RabbitMQ
  5. Queue workers update databases (Vote is counted)

 

Queue Implementations

Bull

Cons

  • Proprietary protocol
  • Relatively Young Product
  • Node.js Only

Pros

  • User-Friendly
  • Low Maintenance Overhead
  • Full-featured

Queue Implementations

RabbitMQ

* Disclaimer: I have only researched this product and have not yet worked with it.

Cons

  • Higher Maintenance Overhead
  • Less User-Friendly

Pros

  • Uses standard protocols (AMQP)
  • Multiple Languages
  • Well-Established (since late 2000s)

Queue Implementations

AWS Simple Queue Service (SQS)

Cons

  • Vendor Lock-In
  • Proprietary API
  • Pay-as-you-go

Pros

  • Excellent for Serverless
  • No Maintenance Overhead
  • Pay-as-you-go

* Disclaimer: I have only researched this product and have not yet worked with it.

Summary

  1. Horizontal vs. Vertical Scaling
  2. The Master/Worker Model
  3. Queue Concepts
  4. Demo
  5. Queue Implementations

@ Me

https://kyleanderson.us

@KAndersonUS

Everything Else âž¡
(keybase.io/kandersonus)

Horizontal Scaling with Message Queues

By Kyle Anderson

Horizontal Scaling with Message Queues

  • 58