1. How to Approach a Design Question
1.7 What's an API, and why define it before drawing boxes?
At the architect's desk: Before planning rooms, the architect decides the doors: where people come in, where deliveries arrive, where the car goes. The doors decide how everything inside is laid out.
In the interview: An API (application programming interface) is the list of operations your system offers to the outside world: what goes in, what comes out. Write it before drawing any boxes, because every box you draw later exists to serve these operations.
For the URL shortener, two operations cover both functional requirements:
POST /urls
body: { "long_url": "https://example.com/a/very/long/page" }
returns: { "short_url": "https://sho.rt/aB3x9Q" }
GET /{code}
example: GET /aB3x9Q
returns: a redirect to https://example.com/a/very/long/page
(404 Not Found if the code doesn't exist)
Keep it short: the main operations, their inputs and outputs, and the error case. You don't need every header or field.
Memory code: "Doors before rooms." Decide what goes in and out before you design the inside.