Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

SD
System Design
0/13 completed
Beginner
What is system design?How the internet worksBack-of-the-envelope estimation
Intermediate
Scaling basicsLoad balancersCachingDatabases at scale
Advanced
Sharding and consistent hashingMessage queues and event streamingConsistency, CAP and distributed transactionsReliability and observability
Pro
Designing a URL shortenerDesigning a chat app
Tracks / System Design / Intermediate

Scaling basics

When traffic grows, a system can scale up (a bigger machine) or scale out (more machines). Knowing when each works, and what has to change in your application before you can scale out, is the foundation of every large design.

Vertical scaling: a bigger machine

Add CPU, memory and faster disks to one server.

  • ✔ Simple: no code changes, no distributed-systems problems.
  • ✔ Surprisingly far-reaching: a single large server can have hundreds of cores and terabytes of RAM.
  • ✖ Limits: there's a biggest machine, and prices rise steeply near the top.
  • ✖ Single point of failure: when it goes down (or is upgraded), everything is down.

Scaling up is the right first move for many systems, especially databases. Don't distribute what you don't have to.

Horizontal scaling: more machines

Run many copies of the application behind a load balancer:

                ┌──▶ app server 1 ──┐
users ──▶ LB ───┼──▶ app server 2 ──┼──▶ database / cache
                └──▶ app server 3 ──┘
  • ✔ Nearly unlimited capacity, on cheap commodity machines.
  • ✔ Redundancy: if one server dies, the others carry on.
  • ✔ Elasticity: add servers at peak, remove them at night (autoscaling).
  • ✖ Needs the application to be stateless, and moves the bottleneck elsewhere (usually the database).

Statelessness

If a server keeps user data in its own memory (sessions, uploaded files, a shopping cart), the next request, sent to another server, won't find it:

Python · editable

To make servers stateless, move state out:

State Where it goes
Sessions A shared store (Redis, a database), or a signed token/cookie the client carries
Uploaded files Object storage (S3)
Caches A shared cache (Redis, Memcached), or accept per-server caches that may differ
Scheduled jobs A job queue or scheduler, so they don't run once per server

Sticky sessions (the load balancer always sends a user to the same server) avoid the problem without fixing it: that server's failure still logs the user out, and load becomes uneven.

Where's the bottleneck?

Scaling is a cycle: find the bottleneck, remove it, find the next one. A request's time splits between components, and the slowest shared resource limits the whole system:

Python · editable

The usual order of fixes for a growing web product:

  1. Optimise first: add database indexes, fix N+1 queries, paginate. Often a 10× win for free.
  2. Scale the app tier horizontally behind a load balancer (stateless servers).
  3. Cache hot reads (Redis) and put static files on a CDN.
  4. Read replicas for read-heavy databases.
  5. Queues to move slow work (emails, image processing) out of requests.
  6. Shard the database when writes or data size outgrow one primary.
  7. Split services when teams and domains, not just traffic, require it.

Availability: no single points of failure

A single point of failure (SPOF) is any component whose failure takes the whole system down. Remove them with redundancy:

  • At least two of everything stateless (app servers, load balancers).
  • Databases with replicas and automatic failover.
  • Spread across availability zones (separate data centres in one region); critical systems also across regions.

Availability is measured in "nines":

Python · editable

Every component in the request path multiplies in its chance of failure, which is why redundancy matters at every layer.

Autoscaling

Cloud platforms add and remove servers automatically based on metrics (CPU above 60%, requests per instance, queue length). Remember: new instances take time to start (keep a baseline), databases usually don't autoscale this way, and scale-in must drain connections gracefully.

Practice

  1. Change the capacity model so the database handles 8,000 queries/s. How many app servers are useful before the database becomes the bottleneck again?
  2. List everything in a typical web app that's stateful, and where you'd move each piece.
  3. A checkout flow calls five services in series, each 99.95% available. What's the availability of checkout?
✎ Check your understanding

1.What does "stateless" mean for an application server?

2.Adding app servers stopped increasing throughput. What's the likely reason?

3.Roughly how much downtime per year does 99.9% availability allow?

← Back-of-the-envelope estimation