Walk me through how you'd design a URL shortener like Bitly that handles a few thousand redirects per second.
system-design · Mid level · software-engineering
What the interviewer is really asking
Assesses whether the candidate can take a deceptively simple prompt and reason through key generation, the read-heavy access pattern, and storage choices — not whether they memorized a canonical answer.
What to say
- Clarify scope and traffic shape first: how many short URLs created per day vs. redirects served, whether links expire, and that this is heavily read-skewed (often 100:1 reads to writes), which justifies caching and read replicas.
- Explain short-key generation concretely: base62 encode an auto-increment or distributed counter for collision-free keys, or pre-generate keys with a Key Generation Service; contrast with hashing the long URL plus collision handling, and say why you'd pick one.
- Cover the redirect path: a 301/302 lookup of key to long URL backed by a cache (cache-aside on Redis) in front of a KV store, returning the right status code and recording analytics asynchronously so the hot path stays fast.
What to avoid
- Jumping straight to a database schema or a specific tech ("I'd use Postgres") before clarifying read/write ratio and scale.
- Hand-waving key generation with "just hash the URL" and never addressing collisions or key length.
- Ignoring the read-heavy nature entirely — no caching, no CDN, no replicas — and treating it as a write-balanced workload.
Example answers
Strong: I'd confirm scale first — say 10M new links/day and ~1B redirects/day, so it's read-dominated. I'd generate 7-char base62 keys from a distributed counter (range-allocated per app server) to guarantee uniqueness without a per-write collision check. Redirects hit a Redis cache-aside layer in front of DynamoDB; on miss I read the KV store and backfill. I'd use 302 so I can change destinations and capture click analytics, and push the analytics event onto a queue so it never blocks the redirect.
Weak: I'd hash the long URL with MD5 and take the first few characters as the short code, store it in a SQL table, and redirect.