The 5-step execution flow
easy 45 minA fixed order for the 45 minutes of a low-level design round: ask, name, sketch, build, prove.
Video lesson · Chapter 1 of 6
Make a prediction
The 5-step execution flow
1:04Reel
Theory
Read or listen first. About 2 min.
What it is
The flow has five steps. Ask: agree on requirements. Name: find the things and their owners. Sketch: give each class state and methods, choose patterns, data structures and locks. Build: write the core code. Prove: trace it, then extend it.
Each step produces something that the next one uses. Requirements give the nouns. Nouns give the classes. Classes give the code. Code gives something to trace.
The minutes here are for a round of 45: 5, 5, 8, 13 and 14. They are a plan, not a rule of nature. For another length keep the shares: about 10, 10, 20, 30 and 30 percent.
Why it exists
Without a plan, people spend the time where they feel safe: long questions, beautiful boxes. The code starts at minute 35 and nothing is proved.
A fixed order also frees your head. You do not think about what comes next, you think about the problem. And the interviewer can follow, because you say where you are.
The order is cheap to leave and cheap to return to. A question about locks at minute 8 gets a short answer, and then you are back at your step.
A short history
1945
George Polya publishes How to Solve It with four phases: understand the problem, devise a plan, carry it out, look back.
1989
Kent Beck and Ward Cunningham present CRC cards: walk through a scenario and let each card say what it does. The Name step still works like this.
1991
James Martin publishes Rapid Application Development, after work on the approach at IBM. Fixed time boxes later count among its best practices.
Words to know
- Time box
- A fixed length for a step. At its end you move on with what you have.
- Exit line
- The sentence that closes a step and asks for agreement.
- Functional requirement
- What the program does: a student starts a machine.
- Non-functional requirement
- How well it does it: never two washes in one machine.
- Core path
- The one action in which most rules meet. Code this first.
- Seam
- A place where a later change can enter without a rewrite.
- Injected clock
- Time is passed in as a function, so a test can move it.
- Parking list
- Good ideas that are out of scope, written down and left.
How it works
Step through the idea, or press Play.
Ask. 0 to 5: requirements
Understand it
Start here
One dish, five cooks, one clock
Five cooks finish one dish. Each does one thing and hands it on. You are all five of them.
The plate never goes back. A cook who finds a mistake says so and fixes it at their own place.
The clock
Five steps, five results
| Step | Minutes | You do | You leave with | Exit line |
|---|---|---|---|---|
| 1 Ask | 0 to 5 | Questions, then a list | 5 to 7 requirements, a list of what is out | Does this match what you want? |
| 2 Name | 5 to 10 | Nouns, owners, rejected nouns | 3 to 5 classes, one sentence each | These keep the rules. I continue with state and methods. |
| 3 Sketch | 10 to 18 | Fields, methods, patterns, structures, locks | A class diagram with signatures | I would code start and empty now. |
| 4 Build | 18 to 31 | The core path, refusals first | Two methods that are complete | Let me trace this. |
| 5 Prove | 31 to 45 | Trace 5 minutes, extend 9 minutes | A checked core and one extension | This class is new, these stay. |
What each step hands on
Behind the clock? Cut scope
We run the whole flow on one prompt: Design the laundry room of a student house. Students see which machines are free, start a program and empty the machine.
Step 1, minutes 0 to 5
Ask
Say the main path first: a student looks, starts a wash, comes back and empties the machine. Then ask about scale, actors and constraints.
Three kinds of scope question
Scale
One room in memory, or many houses on a network? One room changes the answer to a class design.
Actors
Who acts? Students, the caretaker, and time itself: a wash ends although nobody presses a button.
Constraints
Several screens at once? Can a machine or the network fail? Must data survive a restart?
F and N: what it does, and how well
| F, functional | N, non-functional |
|---|---|
| List free machines | Atomic: never two washes in one machine |
| Start quick (30 min) or cotton (60 min) | Size: one room, about 10 machines, in memory |
| At most two machines per student | Extensible: the house will add rules for starting |
| Owner empties a finished machine | Testable: time can be moved in a test |
| Others may empty it 15 minutes after the end | Several screens at once |
| Out: payment, reservations, faults |
Minute 1 to 4
You
A student looks, starts a program, and empties the machine later. Is that the main path?
Interviewer
Yes.
You
What if the owner does not come back? Then one person blocks a machine.
Interviewer
Others may take the clothes out after 15 minutes.
You
Good, that is a rule about time. May one student use all machines?
Interviewer
Two at most.
You
I assume one process, several screens, nothing stored on disk, no payment. Does this match what you want?
Step 2, minutes 5 to 10
Name
Underline the nouns and ask three questions: what holds (container), what is held (item), who takes the request (manager). The full lens is on what an LLD interview tests.
Container, item, manager
| Problem | Container | Item | Manager |
|---|---|---|---|
| Laundry room | Room | Machine, wash | LaundryRoom |
| Parking lot | Floor, spot | Vehicle, ticket | ParkingSystem |
| Chess | Board, square | Piece | GameController |
| Library | Shelf, section | Book copy | Lending desk |
Nouns, judged
| Noun | Verdict | Because |
|---|---|---|
| Machine | Class | Has identity and a rule: one wash at a time |
| Wash | Small record | Owner and end belong together, and never change |
| Room | Class | The limit per student spans machines |
| Program | Enum | Only a number of minutes differs |
| Student | Just an id | We store no fact about them |
| Timer | Not a class | The state can be computed from the clock |
| Screen | Out | It calls us |
Reject nouns aloud. It is a decision, and it earns as much as a class. How to find owners: entities.
Step 3, minutes 10 to 18
Sketch
Now each class gets state, methods and a rule to keep. Here you also choose patterns, data structures and locks, each with a reason.
The sketch at minute 18
1/5Machine first
The rule one wash at a time lives in Machine. It may hold a Wash or nothing.
owns (dies together)usesdepends on
Words that point to a pattern
| You hear | Think of | Use it only if |
|---|---|---|
| Several ways to do X, policy, algorithm | Strategy | Behaviour differs, not just a value |
| Status changes, idle and active | State | Behaviour differs per state. Else an enum |
| Notify, subscribe, update others | Observer | The sender must not know the receivers |
| Undo, redo, history, queue of actions | Command | An action must be kept or reversed |
| Create by type | Factory | The choice is made in more than one place |
| Only one, shared by all | Create one and pass it in | Singleton needs a much stronger reason |
Data structure and lock, with a reason
| Need | Choose | Laundry room |
|---|---|---|
| Find by key often | Hash map | Yes: machine by id |
| Always the smallest or most urgent | Priority queue | No: a list of 10 is scanned |
| Many yes or no flags, very many items | Bit set | No |
| Several writers, check then change | One lock around both | Yes: limit and start |
| At most n at a time may enter | Semaphore | No: we refuse, nobody waits |
| Many readers, few writers, slow reads | Read and write lock | No: reads take microseconds |
How does a machine become DONE?
BreaksA thread per machine that sleeps
- How
startstarts a thread, and after 30 minutes it writes DONE.- Limit
- Threads to manage, races with
empty, and a test that takes 30 minutes. - Choose when
- Never here.
WorksA tick that updates all machines
- How
- Once per second somebody calls
tick(now). - Limit
- The state is wrong between ticks, and somebody must call it.
- Choose when
- If something must happen at that moment, such as a message.
StrongCompute it when asked
- How
state(now)compares now with the end of the wash.- Limit
- Nobody is told when it ends. A message needs a scheduler beside it.
- Choose when
- Whenever the state follows from time and stored facts.
Deriving fields and methods from requirements step by step: class design.
Step 4, minutes 18 to 31
Build
Write from the inside out: enums and records, then the class with the tightest rule, then the manager. Inside a method: refusals first, then the change. Say why while you type.
The laundry room in the order you would write it
Small types give the rest a vocabulary. Do not stay here.
from dataclasses import dataclassfrom enum import Enumfrom threading import Lockfrom typing import Callable, Protocolclass Refused(Exception): """A rule said no."""class Program(Enum): QUICK = 30 # minutes COTTON = 60class State(Enum): FREE = "free" RUNNING = "running" DONE = "done"@dataclass(frozen=True)class Wash: owner: str ends_at: int # minutes since midnight of day 0Lines 7 to 8
One exception for every rule that says no. The screen shows its text, and a real bug still looks different.
A start, from tap to answer
States of a machine
Step 5a, minutes 31 to 36
Prove
Choose one good case, one refusal, one race. Use numbers. Write the values beside the code. If you find a bug, say it and fix it.
Trace: two machines, limit 2, grace 15
| Time | Call | m1 before | Result | m1 after |
|---|---|---|---|---|
| 600 | start(asha, m1, quick) | free | ends at 630 | running |
| 600 | start(lee, m1, quick) | running | refused: m1 is running | running |
| 630 | empty(lee, m1) | done | refused: wait for the owner | done |
| 645 | empty(lee, m1) | done | ok, 645 is not before 645 | free |
The trace as a test, then the extension
The same table as code. If the format allows running, run it.
now = 600 # 10:00, and we can move itroom = LaundryRoom([Machine("m1"), Machine("m2")], clock=lambda: now)def refused(action): try: action() except Refused as e: return str(e) raise AssertionError("should have been refused")room.start("asha", "m1", Program.QUICK) # ends at 630assert room.free() == ["m2"]assert refused(lambda: room.start("lee", "m1", Program.QUICK)) == "m1 is running"now = 630assert refused(lambda: room.empty("lee", "m1")) == "m1: wait for the owner"now = 645room.empty("lee", "m1") # 15 minutes later: allowedassert room.free() == ["m1", "m2"]Lines 1 to 2
A clock we can move. Three quarters of an hour pass in no time.
Which cases to choose, and how to trace a race: verifying and extending a design.
Step 5b, minutes 36 to 45
Extend
What the extension touches
1/4Before
The room and its machines. The limit was two lines in start.
owns (dies together)has (lives on)implements
Other follow-ups, and where they land
| Follow-up | Changes | Stays |
|---|---|---|
| Dryers with other programs | Minutes become data per machine kind | State rule, lock |
| Tell me when it is done | A scheduler beside the room, listeners | Machine: the state is still computed |
| A broken machine | A fourth state with an owner: the caretaker | Limit, rules |
| Pay per wash | Charge before start, refund if start refuses | Machine |
| Ten houses, one server | The room per house, storage behind an interface, lock becomes a transaction | Rules and their tests |
The last 60 seconds
- 1
What works
Start and empty keep three rules: one wash, limit, grace.
- 2
What I left out
Payment, faults, data on disk.
- 3
What I would do next
A message at the end of a wash, then storage.
Other lengths
35, 60 and 90 minutes
| Round | Ask | Name | Sketch | Build | Prove |
|---|---|---|---|---|---|
| 35 minutes | 4 | 4 | 6 | 10 | 11 |
| 45 minutes | 5 | 5 | 8 | 13 | 14 |
| 60 minutes | 6 | 6 | 12 | 18 | 18 |
| 90 minutes, must run | 8 | 7 | 12 | 45 | 18 |
Two habits
What keeps you on time
On time
- Start and end of each step said aloud
- The clock is visible
- Ideas go to a parking list
- The core path is coded first
Late
- Questions until minute 12
- Every class gets all its getters
- A debate about a pattern name
- The easy method first, the hard one never
Summary
The whole topic in one minute.
Ask 5, name 5, sketch 8, build 13, prove 14. End each step with one sentence and a result that can be seen.
Being late means cutting scope, never cutting proof. A small core that was traced beats a large one that was not.
- Ask 5, name 5, sketch 8, build 13, prove 14.
- Scale, actors, constraints. Then F and N.
- Container, item, manager. Reject nouns aloud.
- Patterns, structures and locks are chosen in the sketch, with a reason.
- Build inside out, refusals first, time passed in.
- One good case, one refusal, one race. Then one extension, and what stays.
- Late? Cut scope, keep the proof.
Sources
- How to Solve It, the four phases
- Beck and Cunningham: A Laboratory for Teaching Object-Oriented Thinking (1989)
- Rapid application development, history
- Shape Up: Set Boundaries
- Kubernetes enhancement proposal template
- Rust RFC template
- PEP 1: purpose and guidelines
- Go proposal process
- Google engineering practices: small CLs
- How SQLite is tested
- Java: Clock