Answer guide
Read the answer guide
Clarify the requirements first: expected traffic, link lifetime, custom aliases and analytics. The core is a write path that creates a short key and a much heavier read path that redirects. Generate keys with a counter encoded in base 62, or with random keys checked for collisions, and store the key-to-URL mapping in a key-value or relational store. Put a cache in front of reads, choose a permanent or temporary redirect depending on whether you need click analytics, and add rate limiting and expiry. Then discuss scaling: partitioning the store and making key generation work across many servers.
What the interviewer is assessing
Structured system design: requirements, data model, trade-offs and scaling.
A strong answer covers
- Start by asking about expected traffic, link lifetime, custom aliases and analytics before designing.
- Generate keys with a base-62 encoded counter, or random keys checked for collisions.
- Store key-to-URL in a key-value or relational store, note reads far outnumber writes, and cache reads.
- Choose a permanent or temporary redirect depending on whether you need click analytics.
- Add rate limiting and expiry, partition the store, and make key generation work across many servers.
Common mistakes
- Jumping to technology before clarifying requirements
- Ignoring that reads far outnumber writes
- Not discussing key collisions
Practise a follow-up
- How would you handle a link that suddenly goes viral?
- How would you prevent abuse?