Skip to content
lorebow

Concurrency

Handle more work by running more processes, split by type, instead of making one machine bigger.

KFounder and editor 208 words 1 min read Find it on the map
On this page

Scale out via the process model. When the app needs to handle more, you start more processes. You don't move it to a bigger server.

Each kind of work gets its own process type: web handles HTTP requests, worker handles background jobs from a queue, clock runs scheduled tasks. Each type scales on its own.

Scaling out, one process type at a timeweb=1 worker=1Step 1 of 3
Routerspreads requestsweb.1web.2web.3Queuejobsworker.1worker.2

1.A quiet morning

One web process answers every request, and one worker sends the order emails it queues.

#Why more processes, not a bigger machine

Scale up (one bigger server - Vertical)Scale out (more processes - Horizontal)
Has a ceiling: the largest machine you can buyKeeps going as long as you add machines
One failure takes everything downLosing one process loses a fraction of capacity
Usually needs a restart to resizeAdd or remove processes while running
Scales every kind of work togetherScales web and workers separately

Scaling out only works because the processes are stateless. If they weren't, a new process would start without the data the others hold.

#How you scale

The platform runs the processes; you just say how many.

bash
# Heroku-style platforms
heroku ps:scale web=3 worker=2
 
# Kubernetes
kubectl scale deployment/web --replicas=3

Don't run your app as a background daemon or write its own PID files. Let the platform's process manager start, stop, restart and count the processes.

Referenced by