1. How to Approach a Design Question
1.9 What does a good high-level design look like?
Draw, Dive, Defend: solve it
At the architect's desk: A floor plan shows every room and how you walk between them. It doesn't show the wiring or the paint. And a good architect checks it by imagining walking through: front door, hall, kitchen. If you can't reach the kitchen, the plan is wrong.
In the interview: The high-level design is a diagram of the main components (boxes) and how requests flow between them (arrows). Two rules make it good:
- Start with the simplest design that meets every requirement. Add complexity only when the requirements or numbers demand it.
- Walk a request through it. Trace one real request, step by step. If some requirement has no path through your boxes, something's missing.
Figure: the URL shortener's first floor plan, with one redirect traced step by step. Clicks take the green path. The database is touched only on a miss.
Walking a redirect through it:
- The user clicks
sho.rt/aB3x9Q. - The load balancer sends the request to one of many identical app servers (Chapter 7).
- The app server checks the cache for
aB3x9Q(Chapter 12). - On a miss, it reads the database and puts a copy in the cache.
- It replies with a redirect to the long URL.
Creating a link takes a different path: the app server gets a new unique code from the ID maker (Chapter 10), saves it in the database, and returns the short URL.
Memory code: "Draw it simple, walk it through." The simplest plan that works, then trace a real request across it.