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
- Horizontal vs. Vertical Scaling
- The Master/Worker Model
- Queue Concepts
- Demo
- 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:
- Update arrow graphic
- POST /api/vote
- Cache is updated (Vote persists visually)
- Vote is added to RabbitMQ
- 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
- Horizontal vs. Vertical Scaling
- The Master/Worker Model
- Queue Concepts
- Demo
- 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