1. URL shortener
Hash a long URL to a short key and store the mapping in a key-value store.
url_shortener: hash-and-kv-storeTyporithm · medium
Step 1 of 8 · intro card
Design Interview
The classic problems repeat: a URL shortener (hashing plus a key-value store), a news feed (fan-out on write vs on read), chat (WebSockets plus message queues), a rate limiter (token bucket), and typeahead/search (inverted index or trie). The real skill is recognizing reusable building blocks.
A URL shortener maps a long URL to a short key — generate the key by hashing or a counter, then store the mapping in a fast key-value store and redirect on lookup.
A news feed is the fan-out tradeoff: fan-out on write precomputes each follower's timeline when someone posts (fast reads, expensive writes for popular accounts), while fan-out on read assembles the feed at request time (cheap writes, slower reads). Chat layers a live WebSocket connection over a message queue that handles delivery and offline users.
A rate limiter typically uses a token bucket to smooth bursts, and typeahead/search relies on an inverted index or a trie. Recognizing these reusable building blocks — and naming the right one quickly — is what the interview is really testing.
URL shortener: hash plus key-value store.
News feed: fan-out on write vs on read.
Chat: WebSockets plus a message queue.
problems:
url_shortener: hash-and-kv-store
news_feed: fanout-on-write
chat: websockets-and-queue
rate_limiter: token-bucket
search: inverted-indexConnect each part of the code to the concept before you type.
Hash a long URL to a short key and store the mapping in a key-value store.
url_shortener: hash-and-kv-storeFan-out on write precomputes each follower's feed at post time; fan-out on read assembles it at read time.
news_feed: fanout-on-writeWebSockets keep a live connection; a message queue handles delivery and offline buffering.
chat: websockets-and-queueA token bucket grants requests as tokens refill, smoothing bursts.
rate_limiter: token-bucketAn inverted index (or a trie for typeahead) maps terms to the documents that contain them.
search: inverted-indexRead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.