Skip to content
lorebow

Concurrency

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

KFounder and editor 188 words 1 min read Find it on the map

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.

#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