Concurrency
Handle more work by running more processes, split by type, instead of making one machine bigger.
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.
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 buy | Keeps going as long as you add machines |
| One failure takes everything down | Losing one process loses a fraction of capacity |
| Usually needs a restart to resize | Add or remove processes while running |
| Scales every kind of work together | Scales 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.
# Heroku-style platforms
heroku ps:scale web=3 worker=2
# Kubernetes
kubectl scale deployment/web --replicas=3Don'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