Scaling Basics
Scaling Starts with Statelessness
To scale horizontally, your app instances should be stateless. That means: no local file uploads for shared data, no local sessions only, no single-server assumptions.
Sessions and Horizontal Scaling
If you store sessions on one server, requests must stick to that server. Better options: shared session storage (Redis) or database-backed sessions (with care).
Database Is Often the Bottleneck
As traffic grows, the DB becomes the limiting factor: slow queries, missing indexes, connection saturation. Fixes include indexing, query optimization, caching, read replicas, and connection pooling strategies.
Cache First, Then Scale
Before adding servers, add caching and OPcache. Optimize hot paths. Measure latency and error rates. Then scale horizontally with a load balancer.
Queue Heavy Work
Move slow tasks (emails, image processing, external API calls) to background jobs/queues. This keeps web requests fast and predictable.
Production Tip
Use metrics: p95 latency, error rate, DB query time. Add caching, ensure statelessness, then scale. Scaling without observability is guessing.