Design a Highly Available URL Shortener
Company: Uber
Role: Software Engineer
Category: System Design
Difficulty: medium
Interview Round: Onsite
# Design a Highly Available URL Shortener
Design a distributed service that creates short URLs and redirects them at large scale. Cover APIs, code generation, persistence, caching, partitioning, collision handling, expiration, failure recovery, availability, and horizontal growth.
### Constraints & Assumptions
- Redirect traffic is much heavier than creation traffic.
- A short code must resolve to at most one active destination.
- Expired links must stop redirecting according to a stated consistency policy.
### Clarifying Questions to Ask
- May users request custom aliases?
- Are destination changes allowed after creation?
- What latency, retention, and regional availability are required?
```hint Protect the mapping invariant
Choose a generation strategy only after explaining how the system prevents one code from mapping to two destinations.
```
### What a Strong Answer Covers
- Create and redirect API contracts.
- Unique-code generation and collision behavior.
- Storage keys, partitions, caches, expiration, and invalidation.
- Read scaling, replication, regional failure, observability, and abuse controls.
### Follow-up Questions
1. How would custom aliases alter the hot partition and reservation design?
2. How would you migrate the code-generation scheme without breaking old links?
Overview: Design a production URL shortener with exact mapping guarantees, scalable redirects, caching, expiration, partitioning, and recovery.