System Design Intro
System design is the craft of deciding how the pieces of a software system fit together so that it does its job for the number of people who will use it. Writing a function that shortens a URL takes ten minutes. Running a URL shortener that answers 100,000 requests per second, never loses a link and keeps working when a data centre goes dark takes a design.
This course teaches that craft from the ground up. You will learn the vocabulary (latency, throughput, availability, consistency, sharding, quorum), the standard building blocks (load balancers, caches, queues, databases, CDNs) and the algorithms inside them (consistent hashing, LRU, token buckets, Raft). Then you will combine them in case studies such as a chat system, a news feed and a key-value store.
Why a design, and not just code?
A program that works on your laptop can fail in production for reasons that have nothing to do with bugs in its logic:
| Problem | Example | Design answer |
|---|---|---|
| Too much traffic | One server handles 2,000 requests/s, you get 30,000 | Horizontal scaling behind a load balancer |
| Too much data | 40 TB of photos does not fit on one disk | Object storage, partitioning |
| Slow responses | Every page reads the same rows from the database | Caching |
| Failures | A disk dies, a network link drops | Replication, retries, timeouts |
| Spiky work | Video uploads arrive in bursts | Message queues and workers |
| Many teams | 200 engineers deploy one codebase | Service boundaries |
Every answer has a price: more machines, more moving parts, harder debugging, weaker consistency. System design is mostly the art of choosing which price to pay.
How we model systems in this course
You can't spin up 50 servers in a browser tab, but you can model them. A model is a small program that keeps the essential behaviour of a system and drops everything else. Here is the smallest possible "system": clients sending requests to one server that can process a fixed number per second.
CAPACITY = 500 # requests the server can finish per second
def serve(arrivals_per_second):
served = min(arrivals_per_second, CAPACITY)
dropped = arrivals_per_second - served
return served, dropped
for load in [200, 500, 800, 1500]:
served, dropped = serve(load)
print(f"load {load:5}/s -> served {served:4}, dropped {dropped:4} ({dropped / load:.0%})")load 200/s -> served 200, dropped 0 (0%)
load 500/s -> served 500, dropped 0 (0%)
load 800/s -> served 500, dropped 300 (38%)
load 1500/s -> served 500, dropped 1000 (67%)
The model is crude, but it already shows the first rule of capacity: once load passes capacity, the extra work does not just slow down, it is lost (or it queues up, which we model later). Adding a second identical server behind a load balancer doubles capacity:
CAPACITY = 500
def serve_cluster(load, servers):
capacity = CAPACITY * servers
served = min(load, capacity)
return served, load - served
for servers in [1, 2, 3, 4]:
served, dropped = serve_cluster(1500, servers)
print(f"{servers} server(s): capacity {servers * CAPACITY:4}/s, served {served:4}, dropped {dropped:4}")1 server(s): capacity 500/s, served 500, dropped 1000
2 server(s): capacity 1000/s, served 1000, dropped 500
3 server(s): capacity 1500/s, served 1500, dropped 0
4 server(s): capacity 2000/s, served 1500, dropped 0
All the Python examples in this course are deterministic: when a model needs randomness it uses a seeded generator such as random.Random(42), so you get exactly the output shown under each playground. Change the numbers and run them again: that is the fastest way to build intuition.
The shape of a typical web system
Most designs you will meet are variations of this picture:
+--------+
users ---> | DNS |
+--------+
|
v
+--------+ +-------------+
| CDN |----->| object store| (images, video, JS)
+--------+ +-------------+
|
v
+--------------+
| load balancer|
+--------------+
/ | \
+-----+ +-----+ +-----+
| app | | app | | app | stateless application servers
+-----+ +-----+ +-----+
| \ | / \
| +-------+ +-------+
| | cache | | queue |---> workers
| +-------+ +-------+
v
+-----------+ replication +-----------+
| primary DB|---------------->| replica DB|
+-----------+ +-----------+Each box is a lesson in this course. Reading the diagram top to bottom is also how a request flows.
How to approach a design problem
Whether you are designing a real feature or answering an interview question, the same steps work:
- Clarify requirements. What must the system do (functional) and how well (non-functional: latency, availability, scale)?
- Estimate. Requests per second, storage per year, bandwidth. Numbers decide whether one database is enough.
- Sketch a high-level design. Boxes and arrows, the API and the data model.
- Deep dive. Pick the hardest parts (the hot path, the biggest table, the failure modes) and design them carefully.
- Review trade-offs. What breaks first? What would you change at 10x scale?
Tip: Resist drawing boxes before you know the numbers. A system for 1,000 users and one for 100 million users look completely different, and both are good designs for their own scale.
Common beginner mistakes
- Over-engineering: microservices, Kafka and five databases for an app with 50 users. Start simple and grow.
- Ignoring failure: every network call can time out, every machine can die. Ask "what if this box disappears?" for each box.
- Vague requirements: "it should be fast" is not a requirement. "95% of reads under 100 ms" is.
- Single points of failure: one load balancer or one database with no replica means one outage takes everything down.
Test yourself
In the first model, what happens to requests beyond the server's capacity?
- They are served more slowly
- They are dropped
- They are sent to a cache
- Capacity grows automatically
Which step should normally come before drawing a high-level design?
- Choosing a database brand
- Clarifying requirements and estimating scale
- Writing the code
- Adding caches everywhere
What is a single point of failure?
- A bug that only appears once
- A component whose failure takes the whole system down
- The slowest server in a cluster
- A failed unit test