Sub topic 10
Make trade-offs explicit
This chapter assumes you have read the earlier chapters on requirements, capacity estimation, storage choices, and scaling. You should know what replication, partitioning, and caching do. Here you learn to say what each choice costs and why you accepted that cost.
Why trade-offs matter
Every design choice gains something and gives something up. A cache lowers read latency but can serve stale data. Replication improves availability but makes consistency harder. A design with no stated costs looks finished, but it hides the decisions a reviewer most wants to check.
A named trade-off shows that you considered alternatives. It also lets others challenge the decision against the requirements, not against their own preferences.
A repeatable pattern
Use the same four steps for each significant decision:
- State the decision as a question, such as "Should reads go through a cache?"
- List two or three real options.
- Compare them on the dimensions that matter for this problem, such as latency, consistency, cost, and operational effort.
- Choose one, name what you gave up, and tie the choice to a requirement or a number from your estimates.
Common trade-off axes
The same few tensions appear in most designs.
| Axis | One side | Other side |
|---|---|---|
| Consistency vs. availability | Every read sees the latest write | The system keeps answering during failures |
| Latency vs. durability | Acknowledge a write immediately | Wait until it is safely stored on several nodes |
| Read speed vs. write cost | Precompute results for fast reads | Compute on demand and keep writes cheap |
| Simplicity vs. scale | One database, easy to operate | Sharded stores, harder to operate |
| Cost vs. headroom | Provision for average load | Provision for peak load |
A worked example
Suppose your estimate shows about 11,574 average read QPS (queries per second) and about 579 write QPS. Reads outnumber writes by roughly 20 to 1. The decision is whether to put a cache in front of the database.
- No cache: This is simple and always fresh. The database must handle every read, so it becomes the first bottleneck.
- Cache with a short expiry (TTL): This removes most database reads. Users may see data that is a few seconds old, and you now have a second system to run and monitor.
- Cache updated on every write: This keeps data fresher. It adds write latency and creates more places where the cache and database can disagree.
You might write down: "I choose a cache with a 30-second TTL. The read-heavy ratio justifies it, and the requirements allow slightly stale item lists. If a later requirement demands read-your-own-writes, I would bypass the cache for the owner's own reads."
That statement names the choice, the cost, the reason, and the condition that would change it.
Common errors
- Hiding the cost. Presenting a choice as having no downside makes reviewers distrust the rest of the design.
- Listing options without choosing. A comparison with no decision leaves the work unfinished.
- Optimizing the wrong dimension. Spending effort on global scale when the requirements describe a single-region product wastes complexity.
- Treating a choice as permanent. Record what would make you revisit it, so you can revise calmly when requirements change.
Exercise
Your service has a 50:1 read-to-write ratio, and the requirements say users must always see their own latest post immediately. You are considering a read cache with a 60-second TTL. State one benefit, one cost, and how you would resolve the conflict with the requirement.
Show answer
The benefit is that most reads are served from the cache, which lowers database load and read latency. The cost is stale data for up to 60 seconds. This conflicts with the requirement that users see their own latest post. One resolution is to route a user's reads of their own posts directly to the database, or to invalidate or update the cached entry on write. This keeps the cache for everyone else's reads, and the cost is extra complexity in the read path.