A Framework for System Design
A repeatable way to attack open-ended design problems: requirements, back-of-envelope estimates, API, data model, high-level design, deep dives, and trade-offs.
intermediate40 min#system-design#estimation#requirements#trade-offs
Prerequisites: Big-O and Complexity Analysis
Why it matters
Real systems are never specified completely. Someone says "build a photo-sharing app" and it is your job to decide what that means, how big it will get, and what you are willing to give up. System design interviews test exactly this skill, and so does every design review at work. The danger is not a wrong box on a diagram; it is jumping to boxes before you know what the system must do.
A fixed framework keeps you calm and keeps the conversation structured. You always know what to do next, and the other person can see your reasoning.
Intuition
Think of an architect designing a building. They do not start with the plumbing. They ask how many people will use it, what it is for, and what the budget is. Only then do they sketch floors, and only after that do they zoom into the tricky parts such as the foundation or the elevator.
System design works the same way: go from wide to narrow. Each step narrows the space of valid designs, so the next decision becomes easier and easier to justify.
How it works
Use these steps, in order, and spend roughly equal time on the first four before the deep dives.
- Clarify requirements. Split them into functional (what the system does: "users can post a photo and follow others") and non-functional (how well: latency, availability, durability, consistency, cost). Also write down what is out of scope. Ask about scale: how many users, how read-heavy is it?
- Estimate. A back-of-envelope calculation tells you whether one machine is enough or whether you need partitioning. You only need the right order of magnitude.
- Define the API. List the few operations clients call, with inputs and outputs. This pins down the behavior without drawing anything.
- Sketch the data model. Which entities exist, what are the keys, and how will they be queried? The access pattern, not the entity list, drives the choice of storage.
- Draw the high-level design. Clients, a load balancer, stateless application servers, a data store, a cache, maybe a queue. Keep it to a handful of boxes and trace one request through them.
- Deep dive. Pick the one or two hardest parts (the hot path, the bottleneck, the part you were asked about) and go deep.
- Name trade-offs and failure modes. What breaks first? What did you give up (consistency for latency, cost for durability)? What would you change at 10x scale?
requirements -> estimates -> API -> data model
|
v
trade-offs <- deep dives <- high-level design
Estimation rules of thumb
Memorize a few anchors rather than exact figures:
- A day has about 86,400 seconds, which is close to 100,000. So "1 million actions per day" is about 12 per second on average.
- Peak traffic is a multiple of the average. Pick a factor (2x to 5x is common) and state it.
- Storage is
items per day * bytes per item * days kept. Multiply by a replication factor (often 3) for the real disk footprint. - Powers of ten are fine: a kilobyte is about a thousand bytes, a megabyte a million, a gigabyte a billion.
Always state your assumptions out loud. The point is not a precise number but a number you can defend and adjust.
| Operation | Time | Notes |
|---|---|---|
| Average QPS | requests per day / 86,400 | Convert daily volume to per-second |
| Peak QPS | average QPS * peak factor | Size for peak, not average |
| Storage per year | writes/day * bytes * 365 | Then multiply by replication |
| Bandwidth | QPS * bytes per request | Check against network limits |
Code: a back-of-envelope calculator
Writing estimates as a function forces you to name every assumption, and lets you change one number and see what moves.
SECONDS_PER_DAY = 86400
def estimate(dau, actions_per_user, write_ratio, bytes_per_write,
peak_factor=3, replication=3):
requests_per_day = dau * actions_per_user
avg_qps = requests_per_day / SECONDS_PER_DAY
peak_qps = avg_qps * peak_factor
write_qps = avg_qps * write_ratio
writes_per_year = requests_per_day * write_ratio * 365
raw_tb = writes_per_year * bytes_per_write / 1e12
return {
"avg_qps": avg_qps,
"peak_qps": peak_qps,
"write_qps": write_qps,
"storage_tb_per_year": raw_tb,
"disk_tb_with_replicas": raw_tb * replication,
}
result = estimate(dau=10_000_000, actions_per_user=10,
write_ratio=0.1, bytes_per_write=500)
for name, value in result.items():
print(f"{name}: {value:.1f}")const SECONDS_PER_DAY = 86400;
function estimate({ dau, actionsPerUser, writeRatio, bytesPerWrite,
peakFactor = 3, replication = 3 }) {
const requestsPerDay = dau * actionsPerUser;
const avgQps = requestsPerDay / SECONDS_PER_DAY;
const peakQps = avgQps * peakFactor;
const writeQps = avgQps * writeRatio;
const writesPerYear = requestsPerDay * writeRatio * 365;
const rawTb = (writesPerYear * bytesPerWrite) / 1e12;
return {
avg_qps: avgQps,
peak_qps: peakQps,
write_qps: writeQps,
storage_tb_per_year: rawTb,
disk_tb_with_replicas: rawTb * replication,
};
}
const result = estimate({ dau: 10_000_000, actionsPerUser: 10,
writeRatio: 0.1, bytesPerWrite: 500 });
for (const [name, value] of Object.entries(result)) {
console.log(`${name}: ${value.toFixed(1)}`);
}Both versions print:
avg_qps: 1157.4
peak_qps: 3472.2
write_qps: 115.7
storage_tb_per_year: 1.8
disk_tb_with_replicas: 5.5
Read it like a designer: about a thousand requests per second on average is easily handled by a few ordinary application servers, and a couple of terabytes per year fits on a single database server disk but not comfortably once you add replicas, indexes, and growth. That points toward replication early and a plan for partitioning later.
A typical request passes through the same few tiers, which is what the high-level design step draws.
Common pitfalls
- Skipping requirements. The most common failure. Two minutes of questions saves ten minutes of designing the wrong thing.
- Designing for Google scale on day one. If the estimate says one database handles the load, say so, then explain how you would grow.
- Boxes without flow. A diagram with ten components and no traced request proves nothing. Walk one read and one write through it.
- Buzzword stuffing. Adding a queue, a cache, and a search cluster "because they are standard" without a requirement that needs them.
- Ignoring failure. Every component can die. Say what happens when it does.
- Hiding trade-offs. Every choice costs something. State the cost before someone asks.
Practice
Estimate a chat service easy
Hint
Start from daily messages, convert to per-second, then apply a peak factor.
Show solution
Assume 5 million daily users sending 40 messages each, 100 bytes per message. That is 200 million messages per day, about 2,300 per second on average, and with a 3x peak roughly 7,000 per second. Storage is 200 million times 100 bytes, about 20 GB per day, or around 7 TB per year before replication. The numbers say a single writer node is tight at peak, so partition by conversation.
Functional vs non-functional easy
Hint
Functional is what, non-functional is how well.
Show solution
For a ride-hailing app, "a rider can request a trip" is functional. "Matching a rider to a driver completes within a few seconds" and "the service stays available during a regional outage" are non-functional. Non-functional requirements are usually what force the interesting architecture.
Pick the access pattern first medium
Hint
Write the two or three most frequent queries before choosing a database.
Show solution
For a news feed, the hot query is "latest posts from the accounts I follow". That favors either computing the feed when a post is written (fan-out on write, fast reads, expensive writes for popular accounts) or when it is read (cheap writes, slower reads). The data store follows from that choice, not the other way round.
Find the bottleneck medium
Hint
Compare each estimate against what one machine can plausibly do.
Show solution
Suppose peak read traffic is 50,000 requests per second and one application server comfortably serves about 2,000. You need on the order of 25 servers behind a load balancer. If every request hits the database, the database becomes the bottleneck long before the app tier, which is the argument for a cache in front of it.
Interview questions
- How do you start a design question? Clarify functional and non-functional requirements and expected scale before drawing anything.
- Why do back-of-envelope estimates matter? They decide whether you need partitioning, caching, or just a bigger machine, and they expose the bottleneck early.
- How do you choose a database? From the access patterns, consistency needs, and scale, not from familiarity or fashion.
- How do you handle a requirement that conflicts with another? Name the conflict (for example strong consistency versus low latency), propose a choice, and say what you give up.
Interviewers look for: structured thinking, stated assumptions, a bottleneck identified from numbers, and explicit trade-offs rather than a memorized architecture.
Quick check
A system gets 86 million requests per day. About how many requests per second is that on average?
Finished this lesson?
Further resources
- Systems design (Wikipedia) (article)
- Fermi problem (Wikipedia) (article)
- The System Design Primer (article)