1. How to Approach a Design Question
1.8 How do you sketch the data model?
At the architect's desk: The store room is designed around how you'll look for things. If you always grab rice by name, you label shelves by name. You don't arrange them by the date you bought them.
In the interview: The data model is what you store and how it's organised. Start from the questions your API will ask of the data, then shape the storage to answer them fast.
The URL shortener's API asks one question again and again: "Given this code, what's the long URL?" So:
Table: urls
code (primary key) "aB3x9Q"
long_url "https://example.com/a/very/long/page"
created_at 2026-10-05 10:00
user_id (optional) who created it
Every lookup is "find by exact code". That's a key-value access pattern: one key, one value, no joins. So a key-value store fits well, and so does a relational table with the code as its primary key. Either is a fair choice if you say why (Chapter 8 covers how to pick).
Memory code: "Store it the way you'll ask for it." The access pattern shapes the data model.