Make the right trade-off / CHAPTER 25
Discussing tradeoffs clearly
Turn competing requirements into a justified decision that can change when evidence changes.
Builds on Functional and non-functional requirements, Back-of-the-envelope estimation.
- Compare alternatives against explicit requirements.
- Explain benefits, costs, and failure behavior.
- Define a measurable trigger for revisiting a decision.
01A tradeoff is a consequence, not a slogan
A shop receives 10,000 product-page reads and 20 description edits each second. Tests show that its database meets the response-time and error targets at up to 2,000 description reads per second. Reading the database for every page would exceed that limit.
Keeping descriptions in a cache means saving an extra copy that many page requests can reuse. The copy saves database reads, but it may not include the latest edit. This is a tradeoff: we accept a specific cost to obtain a useful benefit.
First separate the shop's promises:
- Browsing: a product description may be up to 30 seconds old.
- Buying: the purchase service must verify the agreed price and the buyer's current permission before accepting an order.
- Capacity: database traffic must remain within its tested safe rate, including during failures.
The first promise permits some older display data. It does not permit checkout to charge an old price. A requirement that must always hold is a hard constraint; a preference such as lower cost helps choose among designs that already satisfy those constraints.
02Use a small decision record
Compare complete request paths, rather than giving technologies scores in isolation.
| Option | What handles a page request? | What extra work or limitation follows? |
|---|---|---|
| Direct database read | The application reads the saved description for every page. | The assumed 10,000 reads/s exceed the database's 2,000/s safe rate. |
| Cache repeated descriptions | The application returns a sufficiently recent copy; a missing copy requires a database read. | The application must update or remove old copies and protect the database when many copies are missing. |
| Generate static catalog pages | A publication job builds pages that a file-serving system returns. | Edits appear only after publication; this delay must fit the 30-second promise. |
Write a short decision record:
- State the problem: description reads exceed database capacity.
- State the assumption: enough visitors read the same products for caching to help. A proposed 90% hit rate is a hypothesis, not a property of installing a cache.
- Choose a candidate and calculate its effect: estimate how many page requests still need the database.
- Explain the cost: describe how edits reach copies and what happens when the cache fails.
- Name a reason to revisit: measured database reads above 2,000/s or descriptions older than 30 seconds invalidate the choice.
Exclude a design that breaks purchase correctness before comparing its price or average response time.
03Worked decision: product descriptions
Follow one product page and one edit:
- A browser requests product
42. The application looks for that product's cached description. It uses the copy only if fewer than 30 seconds have passed since the database verified that description. A delayed cache fill must keep that original verification time; storing it later must not restart the 30 seconds. - If no usable copy exists, the application reads the database. It saves a replaceable copy for later visitors. At 90% hits, 10% of 10,000 requests reach the database: 1,000 reads/s, plus refresh work. That fits the assumed 2,000/s capacity.
- An editor saves a new description. Save it in the database first. Then update the cached copy or remove it so the next reader reloads it. Removing a cached value is called invalidation.
- Account for a slow reader. A reader might load an old description before the edit and put it in the cache afterward. Version checks or another coordinated update rule must handle this race. An expiry timer alone does not make every edit immediately visible.
- The customer buys the item. The purchase service checks the price and permission using the records that decide the purchase. A description-cache hit is not permission to buy.
- The cache fails. Up to 10,000 reads/s could now reach the database. Keep description reads, including refreshes, within the tested 2,000/s limit, and reserve capacity for purchase checks. Reuse descriptions only within their 30-second limit; reject browsing requests that would exceed the remaining capacity.
Now lower the hit-rate assumption to 75%. The database receives 10,000 × 25% = 2,500 reads/s, already above its safe rate. The calculation changes the decision even though the architecture drawing still contains the same boxes.
Discussing tradeoffs clearly — decision flow
Follow the numbered arrows
- Shop requirements → Read the databasecheck the direct-read load
- Shop requirements → Cache descriptionscheck whether copies may be reused
- Read the database → Keep purchase checkscompare required work and errors
- Cache descriptions → Keep purchase checkscompare saved work and stale copies
- Keep purchase checks → Measure database readsmeasure whether the choice still fits
Trace the diagram in words
- State which descriptions may be old and which purchase details must be checked now.
- Compare how direct reads and cache reads reach the product database.
- Count database misses during normal traffic and cache failure before accepting the choice.
04Explain uncertainty and change
Explain the decision with the same concrete promises used to make it:
- Why cache? Repeated description reads can share a copy, reducing database work while the product permits a 30-second delay.
- What stays separate? The purchase service still verifies current purchase details. A faster page cannot justify an incorrect order.
- Who maintains copies? Name the application or worker that updates them, records failures and retries missing updates.
- What is measured? Track database reads, description age, response time and errors separately. A high hit rate with old data is not success.
- When should the design change? Immediate edit visibility requires a different read/update rule. A fall to 100 reads/s may make direct database reads simpler.
A concise interview explanation is: “Descriptions may be 30 seconds old, so repeated reads can use a cache. Checkout verifies the purchase independently. I will test hit rate and cache failure, and revisit the choice if database reads or description age exceed their limits.”
DRAW. CALCULATE. EXPLAIN.
Choose a dashboard policy
20 minutes · guided practice
A dashboard receives 5,000 reads/s. Counts may lag 10 seconds; permission revocation must apply immediately. Its source safely serves 500 count reads/s. Assume 95% cache hits, then consider a drop to 85%. Choose policies and a failure response.
Compare the worked solution
- At 95% hits, 5% of 5,000 count reads reach storage: 250/s. This fits the 500/s limit before refresh work.
- At 85% hits, 750/s reach storage, which exceeds that limit. The original caching assumption no longer supports the load.
- Cache dashboard counts only within the allowed 10-second age. Check private access against a permission system that sees revocations before returning the dashboard.
- If the cache fails, keep count reads and refreshes below 500/s, and return older counts only if their verified age is at most 10 seconds, or report that counts are unavailable. Do not skip permission checks to preserve availability.
- Measure count age and storage reads; change the design when either exceeds its target.
The checkboxes record your own assessment. The worked solution gives you a way to check the reasoning.
RETRIEVE BEFORE YOU REVEAL
Keep the important ideas.
Say the answer aloud, then turn the card over.
CARD 01How do you explain a tradeoff?
- Name the user promise.
- Show how the mechanism helps.
- Calculate its benefit and explain its failure cost.
- Name evidence that would change the choice.
CARD 02How should alternatives be compared?
- Use the same workload and correctness rules.
- Exclude options that break essential promises.
- Compare response time, total cost and operating work among the remaining options.
CARD 03Why test a cache outage?
- Normal hits may keep database reads low.
- An outage can send every read to it.
- Limit fallback traffic and serve older display data only within the allowed age.
CHECK THE REASONING
Can you explain the choice?
Answer every question, then finish for an immediate score and an explanation for each answer. Aim for 80%, then revisit any gaps.
CLOSE THE LOOP
Explain it without the page.
Summarise the mechanism, one trade-off, and one failure mode. Then mark this chapter complete.