Design a URL Shortener
Create short links, resolve them quickly and handle expiry without sending users to the wrong destination.
Backend and product engineers designing software behavior.
Your approach: Use diagrams, tables or prose for customer contracts, state transitions and data ownership; include APIs only to the depth the question requests.
The problem
Design a URL shortener that creates links and redirects visitors to their original destination. Define the create and redirect contracts, how short codes remain unique, and how expiry and deletion affect cached redirects. Explain one failure from the visitor’s perspective.
- Create 1 million links/day; each link receives 100 redirects on average.
- Redirect traffic peaks at ten times the daily average. Store the destination and owner for one year.
- Owners may expire or delete a link. Custom aliases and detailed analytics are optional follow-ups.
Work within these constraints
State a p95 server response target, excluding the destination website and internet transit.
Required target: ≤ 100 milliseconds
Concurrent creates and retries must not assign one short code to two different destinations.
State a bounded delay for invalidating redirects and how clients see expired or deleted links.
What to deliver
API and data model
Define link creation, redirect and deletion responses, identifiers and ownership.
Read and write paths
Show durable link storage, code allocation and the redirect cache.
Capacity estimate
Estimate average and peak redirect QPS and one year of storage with stated record size.
Failure and tradeoff
Trace a duplicate create and a cache outage; compare two ways to allocate codes.