Stage 1 — One box does everything
Perfect for the first thousand users. Deployments are easy, debugging is easy, and it costs very little.
Symptom that ends it: a traffic spike makes the DB and app fight for CPU and RAM; a disk failure would lose everything.
Stage 2 — Split the database out
Move the database to its own machine (or a managed service such as RDS or Cloud SQL). Now the app and the DB scale independently, and the managed DB gives you automated backups.
New problem: there is still one app server. When it dies or deploys, the site is down.
Stage 3 — Many app servers behind a load balancer
For this to work, the app servers must be stateless: no user sessions or uploaded files on local disk. Sessions move to a shared store (Redis) or into signed tokens; files move to an object store such as S3.
A stateless server is like a bank teller who looks up your account in the central system. Any teller can serve you. A stateful server is a teller who keeps your records in their own drawer — you must always queue for that one person.
New problem: every request still hits one database. Reads pile up.
Stage 4 — Cache and read replicas
Most apps read far more than they write. Two tools take load off the primary:
- A cache (Redis) for hot objects: product pages, user profiles, session data.
- Read replicas that copy the primary and serve read queries.
New problem: replicas lag behind the primary by milliseconds to seconds, so a user may update their address and then see the old one. Caches can serve stale data. Welcome to consistency (Chapters Database Replication Explained and Caching and Redis for System Design Interviews).