Sub topic 10
Make trade-offs explicit
This chapter assumes you can read short Python snippets and know how HTTP APIs and databases work. It also assumes you have followed the earlier chapters: you have requirements, a capacity estimate, a high-level design, and a first pass at storage and scaling. Now you need to defend the choices behind that design.
A trade-off is a choice where gaining one property costs you another. Every design decision in a system has one. If you can't name what you gave up, you probably haven't understood the decision yet.
Why explicit trade-offs matter
A design with no stated trade-offs looks finished but can't be checked. A reviewer can't tell whether you chose a technology because it fits or because it is familiar. When requirements change, you can't tell which decisions are now wrong.
Stating a trade-off gives you three things:
- A reason tied to requirements. "We use asynchronous replication because the write latency target is 100 ms and we accept a few seconds of read staleness" can be checked. "Replication is good for availability" can't.
- A trigger for revisiting. If you know a decision depends on read staleness being acceptable, you know to reopen it when a new feature needs fresh reads.
- A shared vocabulary. The people reviewing your design can disagree with one specific cost instead of with the whole design.
The anatomy of a decision
Use the same four parts each time you record a decision.
- The decision. What you chose, in one sentence.
- The alternatives. At least one realistic option you rejected.
- The deciding requirement. The functional or non-functional requirement, or the number from your capacity estimate, that tipped the choice.
- The cost you accepted. What gets worse, and by roughly how much.
Here is a worked example. Suppose your estimate gave about 11,574 average read queries per second (QPS) and 579 average write QPS. Reads outnumber writes about 20 to 1.
- Decision: put a cache in front of the database for item lookups.
- Alternative: scale the database with more read replicas and no cache.
- Deciding requirement: reads dominate, and a lookup should return in under 50 ms.
- Cost accepted: cached data can be stale, and you now have a cache invalidation problem to solve.
Notice that the cost is specific. "Complexity" is not a cost you can act on. "Stale reads for up to the cache time-to-live (TTL)" is.
Trade-off axes you will meet repeatedly
Most decisions fall along a small number of axes. Learning them lets you spot the trade-off quickly.
| Axis | One side | Other side | Typical question |
|---|---|---|---|
| Consistency vs availability | Every read sees the latest write | The system keeps answering during failures | What happens during a network partition? |
| Latency vs throughput | Fast individual responses | More total work per second | Do we batch requests? |
| Read cost vs write cost | Precompute results at write time | Compute results at read time | Which path is hotter? |
| Storage vs compute | Store derived data | Recompute it | Is disk cheaper than CPU here? |
| Simplicity vs flexibility | One general-purpose component | Specialized components | Can the team operate more pieces? |
| Durability vs speed | Wait for disk or replicas | Acknowledge from memory | What data loss is acceptable? |
Consistency and availability
A network partition is a failure that splits nodes into groups that can't talk to each other. During one, a replicated system must choose. It can refuse some requests to keep data consistent, or it can answer from whatever copy it has and risk stale or conflicting data. This choice is often summarized by the CAP theorem. A more useful framing for everyday design is to ask which operations need the latest data and which can tolerate staleness.
A bank balance transfer needs strong consistency. A "like" counter on a post does not. Treat the decision per operation, not per system.
Read cost and write cost
Consider a feed of recent items from accounts a user follows. You can build it in two ways:
- Fan-out on write: when someone posts, copy the item into every follower's feed. Reads are cheap. Writes are expensive, and a user with millions of followers causes a burst.
- Fan-out on read: when someone opens their feed, fetch recent items from each account they follow and merge them. Writes are cheap. Reads are expensive.
Your capacity numbers pick the default. With reads outnumbering writes 20 to 1, precomputing at write time usually wins. The exception is accounts with huge follower counts, where a hybrid approach is common: fan out on write for ordinary accounts and merge the large accounts' items at read time.
Using numbers to break ties
Opinions about trade-offs are cheap. Numbers settle them. Your capacity estimate is the main tool, and you can reuse it to compare options quickly.
The following script compares the write amplification of fan-out on write against fan-out on read, under assumptions you state at the top.
POSTS_PER_DAY = 50_000_000
FEED_OPENS_PER_DAY = 1_000_000_000
AVG_FOLLOWERS = 200
AVG_FOLLOWING = 200
SECONDS_PER_DAY = 86_400
# Fan-out on write: each post is copied to every follower's feed.
write_ops_fanout_write = POSTS_PER_DAY * AVG_FOLLOWERS
read_ops_fanout_write = FEED_OPENS_PER_DAY # one feed lookup per open
# Fan-out on read: each feed open queries every followed account.
write_ops_fanout_read = POSTS_PER_DAY # one write per post
read_ops_fanout_read = FEED_OPENS_PER_DAY * AVG_FOLLOWING
def per_second(count: int) -> float:
return count / SECONDS_PER_DAY
print("fan-out on write")
print(f" writes/s: {per_second(write_ops_fanout_write):,.0f}")
print(f" reads/s: {per_second(read_ops_fanout_write):,.0f}")
print("fan-out on read")
print(f" writes/s: {per_second(write_ops_fanout_read):,.0f}")
print(f" reads/s: {per_second(read_ops_fanout_read):,.0f}")With these assumptions, fan-out on write needs about 115,741 writes per second and 11,574 reads per second. Fan-out on read needs about 579 writes per second and 2,314,815 reads per second. Neither is free. The question is which load your storage layer handles more cheaply. Writes to a log-structured store are often cheap to batch, while 2.3 million random reads per second would need a large cache or many replicas. That argument, backed by numbers, is what makes the trade-off explicit.
Change one assumption and rerun it. If the average follower count drops to 20, fan-out on write falls to about 11,574 writes per second, and the case for it gets stronger.
Showing trade-offs in the design
You can show the same trade-off on a diagram. This one traces the two feed strategies and where each pays its cost.
Recording and revisiting decisions
Keep a short decision log as you design. A table is enough.
| Decision | Alternative | Deciding factor | Accepted cost | Revisit if |
|---|---|---|---|---|
| Cache item lookups | More read replicas | Reads are 20x writes | Stale reads up to TTL | Feature needs read-your-writes |
| Fan-out on write | Fan-out on read | 20x read-heavy load | Burst for large accounts | Follower counts grow 10x |
| Asynchronous replication | Synchronous | 100 ms write target | Small data-loss window on failover | Data becomes financial |
The last column is the one people skip. It turns a decision into a testable claim: the choice holds under these conditions, and here is what would change it.
Common mistakes
- Naming only benefits. "Microservices scale independently" omits the cost: network calls, harder debugging, and distributed failures.
- Treating a trade-off as a binary. Many axes have a middle ground, such as per-request consistency levels, tiered caching, or hybrid fan-out.
- Optimizing an axis nobody asked about. If the requirements never mention sub-10 ms latency, don't pay for it with extra complexity.
- Hiding the cost in vague words. Replace "more complex" with who operates it, what can fail, and how much extra work it adds.
- Deciding once and never again. A trade-off is valid for a set of assumptions. When the assumptions move, the decision may flip.
- Choosing by habit. If you can't state one realistic alternative, you haven't made a decision. You've repeated a default.
Handling pushback
Reviewers will challenge your choices. A trade-off record makes this productive.
- Restate the cost they are pointing at, so they know you saw it.
- Say which requirement the choice serves.
- If they bring a new requirement, accept it and rerun the decision with it.
- If they only prefer another option, ask which cost they would rather pay.
Changing your mind after new information is a sign the process works. Changing it because someone sounds confident, with no new information, usually isn't.
Exercise
Your design must serve 20,000 read QPS and 500 write QPS. Users must see their own posts immediately after publishing, but may see other people's posts a few seconds late. You are choosing between a read-through cache with a 30-second TTL and a read replica with asynchronous replication. State your decision using the four-part format, and name one condition that would make you revisit it.
Show answer
Decision: serve other users' posts from the cache or replica, and serve a user's own recent posts directly from the primary database (or write them through to the cache). Alternative: send all reads through the replica. Deciding requirement: reads are 40x writes, so the primary can't take all reads, but read-your-writes is required for the author. Cost accepted: other users may see posts up to 30 seconds late (cache) or a few seconds late (replica lag), and the application needs routing logic to send authors to the primary. Revisit if: the product requires every user to see new posts within one second, or if author traffic to the primary grows large enough to overload it.
Exercise
A teammate says, "We should use fan-out on write because it is faster." What is missing from this statement, and what would you ask?
Show answer
It names a benefit (fast reads) but not the cost (heavy writes, bursts for accounts with many followers) or the requirement behind it. Ask: what is the read-to-write ratio, what is the largest follower count we must support, and what write rate can storage sustain? Then state the accepted cost and a revisit condition.