Choosing and defending
easy 30 minEvery box on the board is a choice.
Video lesson · Chapter 1 of 5
A green seat at nine o'clock
Choice, reason, cost, trigger
1:20Reel coming soon
Theory
Read or listen first. About 1 min.
What it is
Design is a chain of decisions. Choosing is picking one option for a stated reason. Defending is explaining it, with its cost, to someone who asks hard questions.
A complete decision has four parts: the choice, the reason, the cost and what would change it.
Why it exists
There is rarely one right answer, so interviewers look at how you decide. A list of options without a choice leaves them guessing.
At work the same habit saves later engineers from asking why something was done.
A short history
1772
Benjamin Franklin describes weighing pros and cons on a sheet of paper in a letter to Joseph Priestley.
2000
Eric Brewer presents the CAP conjecture, a famous trade-off between consistency and availability when the network splits.
2011
Michael Nygard proposes short architecture decision records.
Words to know
- Option
- One way to solve the problem.
- Cost
- What the choice makes worse.
- Trigger
- The fact that would change your mind.
- Reversible
- Easy to undo later.
- Constraint
- Something you cannot change.
How it works
Step through the idea, or press Play.
Choose. Two or three options, one pick, one reason with a number
Understand it
Start here
How should Sam travel?
Nobody asks "which is better, a bike or a bus?" without saying where they are going. Technology is the same. An option is only good for a trip.
The four parts
What a full decision sounds like
- 1
Choice
One option, named. "I will cache the seat map."
- 2
Reason
A requirement or a number. "We expect 5,000 map reads a second, mostly the same maps."
- 3
Cost
What gets worse. "The map can be two seconds old."
- 4
Trigger
What would change your mind. "If readers must see every seat change at once, I would push updates instead."
From need to decision
A decision
- "I choose a unique rule in the database."
- "Because two readers must never hold one seat."
- "It costs a refused write when two people race."
- "If one database cannot take the writes, I would split by building."
Not a decision
- "We could use SQL or NoSQL."
- "Kafka, because it scales."
- "It is the industry standard."
- "This has no downsides."
Compare
Three options in one minute
Draw a tiny table in your head. Columns are the two needs that matter most here, never ten. If one option fails a need, drop it and say why. If two pass, take the one that is simpler to run.
School bus tracker: how do parents see the bus?
| Option | Position at most 10 s old? | Cheap at 20,000 parents? | Verdict |
|---|---|---|---|
| Reload the page by hand | No | Yes | breaks |
| App asks every 10 seconds | Yes | Yes, 2,000 requests/s | strong here |
| Server pushes on an open connection | Yes, about a second | Yes, but 20,000 connections to look after | works; more than we need |
The number that decides
Grade
Breaks, works, strong
Three grades for any option
Breaks
It fails something we agreed on. You can name the request, the number or the failure.
Works
It meets the need today, with a limit you can name. Often right for a smaller system.
Strong
It meets the need with room to grow and a cost we accept. It is strong for this problem only.
Grading an option
Recipe sharing: resizing photos
| Option | Grade | Why |
|---|---|---|
| Resize while the cook waits | works | 2 s of waiting is tolerable at first; a burst of uploads blocks web requests |
| Put a job on a queue, workers resize | strong | Upload returns at once; bursts wait in the queue; needs a retry rule and a "processing" state |
| Resize on the phone only | breaks | Old phones and other clients send any size, so the server still has to check |
How many workers?
Decision 1
SQL or key-value
| Choose | When | Cost | Trigger to move |
|---|---|---|---|
| Relational (SQL) | Rules across rows, several ways to query, data fits one large machine with a standby | Splitting it later is work | Storage or write rate beyond one machine after replicas, caching and batching |
| Key-value | One known key answers almost every request, and size or write rate needs splitting | Few joins; each new question may need a new index or copy | A new feature needs rules across many records |
Decision 2
Sync or async
Ask one question: does the user need the result to continue? Yes means do it now. No means accept it, store it safely, and finish it later.
| Choose | When | Cost | Example |
|---|---|---|---|
| Sync (now) | The answer depends on it, and it is quick | The user waits; its failure is your failure | Claiming a seat |
| Async (later) | It is slow, bursty or can be retried | Status to show, duplicate work to handle | Confirmation email, photo sizes |
Decision 3
Push or pull
Who starts the message?
The same choice appears in feeds. Fan-out on write pushes a post to every follower's list. Fan-out on read pulls from the people you follow. Many readers per post favours push; an author with millions of followers favours pull for that author.
Decision 4
Cache or not
- 1
Is the read too much for the source?
Give the number. If the database is fine, do not add a second copy to keep right.
- 2
Do reads repeat?
A cache helps when the same thing is asked for again soon.
- 3
May it be old?
Agree how old. If the answer is never, do not cache the decision, only the page around it.
- 4
What happens on a miss?
Many requests at once must not all reach the database.
Decision 5
Strong or eventual consistency
Strong means every read after a write sees it. Eventual means copies catch up soon. Choose per operation, not once for the whole system: ask what a person loses if they see old data.
| Operation | Old data causes | Choose |
|---|---|---|
| Book a seat | Two readers, one seat | Strong: decided by the database |
| Show the seat map | A polite refusal | Eventual: up to 2 s old |
| Match a driver to a trip | One driver, two riders | Strong: conditional update |
| Show drivers on the map | A car drawn slightly behind | Eventual: next update in 3 s |
| Count saves on a recipe | A number off by a few | Eventual |
Push-back
When they say "are you sure?"
Answering a challenge
Seat booking: holding your ground
Interviewer
Why not Redis for the bookings? It is faster.
You
You are worried about speed at 9:00. We expect about 300 booking attempts a second, which is well within one relational database.
Interviewer
But Redis could do it.
You
It could. What I need most is that a confirmed booking is never lost or doubled. The database gives me a unique rule and durable commits that I would otherwise build around Redis myself. If attempts grew past what the database can take, I would put the waiting room in front first, then split by building.
Bus tracker: changing your mind well
Interviewer
Parents now want to see the bus move smoothly, within a second.
You
That is the trigger I gave. Polling would go from 2,000 to 20,000 requests a second, and most answers would be empty. I would change to server-sent events.
Interviewer
What does that cost us?
You
20,000 open connections, a way to route each bus to its watchers, and reconnects after a restart. The buses would also have to report every second, not every ten, so that write path grows ten times too. I keep polling as a fallback.
Summary
The whole topic in one minute.
State the choice, the reason, the cost and the trigger.
Push-back is information. Ask what they see, weigh it, then keep or change the choice for a reason.
- Choice, reason, cost, trigger: every box gets all four.
- Compare on the two needs that matter here, then take the simpler option that passes.
- Breaks, works, strong are grades for this problem, not for the technology.
- Choose consistency for each operation by asking what old data would cost.
- Push-back with a new fact can change the choice. Without one, explain the choice better.