Q27: How would you design a URL shortener?
Create a short code for each long URL, store the mapping in a database, and redirect requests through a highly available read path. Generate codes using random IDs with collision checks or an ID-generation strategy plus Base62 encoding. Cache hot mappings, apply abuse and malware checks, and track analytics asynchronously. Define expiration, custom aliases, collision handling, and redirect semantics; avoid making analytics block redirects.
Key Takeaways
- Optimize redirects for low latency and high read volume.
- Separate analytics from the critical redirect path.