3. Stateless services and sessions
One-liner. If any instance can serve any request, scaling is a number, not a project.
Memorize
- Keep session state out of the process: JWT (self-contained, hard to revoke) or session store (Redis, revocable).
- Sticky sessions are a crutch; they break on scale-in and deploy.
- Shared state lives in: cache (Redis), DB (durable), object store (large blobs).
- Idempotent startup: instances must join the pool without coordination.
- Deploys should be rolling; draining connections requires graceful shutdown + LB deregistration delay.
Trap. Storing uploads on the instance's local disk — the next request lands elsewhere and 404s. Do this. Ask "what breaks if this instance dies right now?" for every piece of state.
Check
Users are logged out randomly after a deploy. The app stores sessions in local memory and runs 4 instances. What is the correct fix?
Why
Local memory dies with the instance and isn't shared; sticky sessions only hide it and break on scale-in.