Lesson 1 of 38Building blocks
What Is System Design
Learn what system design means, the requirements that drive it, and the framework interviewers expect you to follow.
Writing a function that works is one skill. Deciding how a product with ten million users stores its data, survives a server dying at 3 a.m., and answers in under a fifth of a second is a different one. That second skill is system design, and it is what separates mid-level from senior engineers in both real jobs and interviews. If you took the Design & Architecture course, you have been shaping the code inside one service. This course zooms out to the machines, networks, and data stores that service runs on.
Boxes, arrows, and trade-offs
System design is choosing the parts of a system (servers, databases, caches, queues, CDNs) and how they talk to each other, so the whole thing meets its goals. You draw it as boxes and arrows. The interesting part is never the boxes themselves: it is why each box is there and what it costs you.
Almost every real system starts as one box and grows. Step through how a typical web app evolves as traffic rises.
Day one: one server runs your code and the database. This is fine for thousands of users, and you should not build more until you need it.
Each step fixed a specific problem and added a new one: more servers mean you cannot keep login sessions in one server's memory, a cache can serve stale data, and a replica can lag behind the primary. That pattern (fix a bottleneck, pay with complexity) is the heart of the subject. The rest of this unit teaches each box in detail.
Functional and non-functional requirements
Before drawing anything, you pin down what the system must do. Requirements come in two kinds.
- Functional requirements are features: what the system does. "Users can post a photo." "Users see a feed of people they follow."
- Non-functional requirements are qualities: how well it does it. "The feed loads in under 200 ms at the 99th percentile." "We never lose a payment." "It stays up during a data center outage."
Functional requirements decide your API and data model. Non-functional requirements decide your architecture. Two apps with identical features (a chat app for a 10-person team and one for 500 million people) end up with completely different designs because the non-functional requirements differ.
Match each requirement to its kind.
Scalability and availability
Scalability is the ability to handle more load by adding resources. You scale vertically by buying a bigger machine (more CPU, more RAM) or horizontally by adding more machines. Vertical is simpler but has a ceiling and a single point of failure. Horizontal has no real ceiling but forces you to deal with many machines agreeing on things.
Availability is the fraction of time the system works. It is quoted in "nines".
| Availability | Downtime per year | Downtime per month | Typical for |
|---|---|---|---|
| 99% (two nines) | 3.65 days | 7.3 hours | Internal tools |
| 99.9% (three nines) | 8.8 hours | 43.8 minutes | Most SaaS products |
| 99.99% (four nines) | 52.6 minutes | 4.4 minutes | Payments, core APIs |
| 99.999% (five nines) | 5.3 minutes | 26 seconds | Telecoms, cloud control planes |
Each extra nine is ten times less downtime and usually much more than ten times the cost. You get there with redundancy: no single machine, rack, or data center whose failure takes everything down. A component like that is a single point of failure (SPOF).
There is a catch when components depend on each other in a chain. If a request must pass through two services and each is up 99.9% of the time, the request succeeds only when both are up.
Two services in a chain, each 99.9% available. What is the combined availability (as a percent)?
a = 0.999 b = 0.999 print(round(a * b * 100, 2))
Latency and throughput
Latency is how long one request takes, usually in milliseconds. Throughput is how many requests the system completes per unit of time, usually in QPS (queries per second) or RPS (requests per second).
They are related but not the same. A highway has a speed limit (latency for one car) and a number of lanes (throughput). Adding lanes does not make any single car faster. Likewise, adding servers raises throughput but does nothing for a request that is slow because it waits 80 ms on a database query.
Latency is reported in percentiles, not averages. p50 is the median request. p99 is the request slower than 99% of all others. If your p50 is 40 ms and your p99 is 2 seconds, one user in a hundred is having a terrible time, and a page that makes 20 backend calls will hit that slow tail often.
Durability is not availability
Scale, latency and uptime get most of the attention, but they are not the only qualities that shape a design. The next one people blur is durability.
Availability asks: can I use the system right now? Durability asks: does my data still exist? They fail independently. A database that is down for an hour but loses nothing had bad availability and perfect durability. A database that fails over in ten seconds but quietly drops the last few seconds of writes had great availability and broken durability. For a photo app the second outage is a shrug. For a bank it is a regulator's letter.
Two numbers make durability concrete, and senior engineers use them in every conversation about data:
- RPO (recovery point objective): how much data you can afford to lose, measured in time. "RPO of 5 minutes" means after a disaster you may lose up to the last 5 minutes of writes.
- RTO (recovery time objective): how long until the service works again.
Your RPO decides one specific moment in the design: when you tell the client "saved". If you acknowledge a write as soon as the primary has it, and the primary dies before the replica copied it, that write is gone even though the user saw a success. Getting RPO to zero means waiting for a second machine (ideally in another availability zone) to confirm the write before you reply. That costs latency on every write, because each write now waits for a network round trip.
| How data is protected | Typical RPO | Cost you pay |
|---|---|---|
| Nightly backup only | Up to 24 hours | Cheap; a bad day loses a day |
| Point-in-time recovery (archived write-ahead log) | Minutes or less | Storage for the log archive |
| Async replica | Seconds (the replication lag) | Recent writes lost on failover |
| Sync replica in another zone | Zero for single failures | Slower writes; a slow replica slows everyone |
There is one more trap. Replication protects you from hardware failure, not from mistakes. A buggy migration or a DELETE without a WHERE clause is copied to every replica within milliseconds. Only backups and point-in-time recovery let you go back to before the mistake. And a backup you have never restored is a hope, not a backup: teams that take durability seriously run restore drills on a schedule and time them, because that measured time is their real RTO.
Security, cost, and operability are requirements too
Three more qualities rarely appear in the prompt, but strong candidates bring them up and real design reviews always ask about them.
Security. Who can call this, and who can see what? Name where authentication happens (usually at the gateway), how authorization is checked (every request checks that this user may touch this resource, not just that they are logged in), and which data is sensitive. A classic hole: object ids that are guessable integers plus a missing ownership check, so GET /invoices/1002 returns someone else's invoice. Also say what you encrypt in transit (everything, with TLS) and at rest, and what you do not store at all. Data you never collect cannot leak.
Cost. A design that meets every target but costs ten times the budget has failed. You do not need prices in an interview, but you should know what drives the bill: bytes stored and for how long, bytes sent out to the internet (egress), compute running around the clock for a peak that happens one hour a day, and per-request charges on managed services. Good cost moves sound like: "We keep raw events for 30 days and aggregates forever", "Images are served from a CDN so the origin egress is small", "Batch jobs run on cheaper interruptible capacity".
Operability. Can a tired engineer at 3 a.m. tell what is broken and fix it? That means metrics, logs and traces that answer real questions, alerts tied to user impact rather than CPU graphs, a deploy that can be rolled back in minutes, and feature flags to turn off a bad path without a deploy. Every new component (a second database, a stream processor, a service mesh) is another thing someone must upgrade, monitor and understand. That is why experienced engineers pick boring, well-understood tools unless a requirement forces something else. The observability and SLOs and reliability patterns lessons go deep on this.
Two more come up in specific domains: compliance (data residency rules such as keeping EU users' data in the EU, and the right to have personal data deleted) and consistency (whether a user may ever see stale data), which has its own lesson in this course.
Match each design decision to the non-functional requirement it mainly serves.
Write requirements as numbers
"Fast", "reliable" and "scalable" are not requirements. Nobody can design against them or check them later. A senior engineer turns each one into a number with a unit, a percentile, and a place it is measured.
| Vague | Precise |
|---|---|
| The feed should be fast | p99 latency of GET /feed under 300 ms, measured at the load balancer |
| It should be reliable | 99.9% of requests succeed over a rolling 30 days |
| It should scale | 20,000 reads per second at peak, 5x headroom for launches |
| Do not lose data | RPO 0 for orders, RPO 1 hour for analytics events |
Once availability is a number, it becomes a budget. A 99.9% target over a month allows about 43 minutes of full downtime, or the equivalent in failed requests. That budget is what you spend on risky deploys and planned maintenance. Run the numbers for a service that handles 50 million requests a month.
Press Run (⌘ Enter) to see what happens.Notice the shape: each extra nine divides the budget by ten. At 99.99% you get about 4 minutes a month, which is less time than it takes a human to be paged, wake up and log in. That is why four nines needs automated failover, not people.
A service gets 50,000,000 requests a month with a 99.9% success target. How many requests may fail before the budget is gone?
print(round(50_000_000 * (1 - 0.999)))
The interview framework
System design interviews are open-ended on purpose ("Design Instagram"). Strong candidates follow a structure so they never freeze and never skip what matters. In a 45-minute round it looks like this.
Never start drawing before you know what you are building. Ask: who uses it, which features are in scope, how many users, what matters most (speed, consistency, cost)?
Put the interview steps in order.
- Tap the steps below in the right order.
Which deep dive will the interviewer pick
The deep-dive slot is where senior candidates separate themselves, and it is more predictable than it looks. Each classic prompt hides one or two hard problems, and the interviewer usually chose the prompt because of those problems. If you spot them in the first five minutes, you can steer your time there instead of polishing the parts that are easy.
| Signal in the prompt | The hard part they will probe | Where this course covers it |
|---|---|---|
| Money, bookings, "never double charge" | Idempotency, transactions across services, retries | Payments, Distributed transactions |
| Limited stock, seats, flash sales | Contention on a few hot rows, holds that expire | Ticketing |
| Celebrities, followers, a feed | Fan-out on write vs read, hot keys | News feed, Replication and sharding |
| Short codes, ids, "unique" | Generating ids without a single counter | Unique ID generation, URL shortener |
| Counting clicks, views, metrics | Streaming aggregation, late events, deduplication | Stream processing, Ad click aggregation |
| Search, autocomplete, "find" | Inverted indexes, ranking, index freshness | Search and inverted indexes, Search autocomplete |
| Large files, video, sync | Chunked uploads, deduplication, CDN delivery | Storage and blobs, File sync, Video streaming |
| Real time, live location, chat | Long-lived connections, presence, geo lookup | Chat app, Ride sharing |
| "Survive a region outage", leaders | Failover, consensus, split brain | Multi-region and DR, Consensus and leader election |
| Public API, abuse, quotas | Distributed counters, fail open vs closed | Rate limiting |
You can also name the deep dives yourself once the high-level design is up: "The two parts I think are hardest here are holding seats during checkout and absorbing the on-sale spike. Which would you like me to go into?" That shows you know where the risk is, and it lets the interviewer steer without having to drag you there.
How this course is laid out
- Building blocks: estimation, DNS and CDNs, load balancers, caches, databases, replication, consistency, queues, APIs, rate limits, and blob storage.
- Data internals: how databases lay data out on disk, and how to generate unique IDs without a central counter.
- Distributed systems: consensus, transactions that span services, and Kafka-style streams.
- Running in production: SLOs, timeouts and retries, multi-region recovery, and search.
- Case studies: sixteen full designs, from a URL shortener up to a Ticketmaster on-sale, each using the blocks above.
By the end you can take a vague prompt, turn it into numbers, draw a design that meets them, and defend its trade-offs. The course closes with a wrap-up that walks one design end to end.
- functional requirement
- A feature the system must provide, like 'users can post a photo'.
- non-functional requirement
- A quality target such as latency, availability, scalability, durability or cost.
- availability (nines)
- Fraction of time the system works. 99.9% allows about 8.8 hours of downtime a year.
- single point of failure
- A component whose failure takes the whole system down. Removed with redundancy.
- latency vs throughput
- Latency is how long one request takes; throughput is how many requests finish per second (QPS).
- p99
- The latency that 99% of requests beat. It shows the slow tail that averages hide.
- durability
- The guarantee that acknowledged data survives failures. Separate from availability, which is about being usable right now.
- RPO and RTO
- Recovery point objective (how much data you may lose, in time) and recovery time objective (how long until service is back).
- error budget
- The failure allowed by an availability target, such as about 43 minutes a month at 99.9%, spent on risky changes.