What it does
A URL shortener takes a long link and returns a short one. When someone visits the short link, the service looks up the original and redirects the browser there.
It is a small problem on the surface but exercises ideas that show up everywhere, id generation, key value lookup, caching, and read heavy scaling.
The two paths
- Write path. A user submits a long url. The service creates a unique short code, stores the mapping code to long url, and returns the short link.
- Read path. A browser hits the short link. The service looks up the code and returns an HTTP redirect to the long url.
Reads dominate. A link is created once but may be clicked millions of times.
What to get right
- Codes must be short and unique.
- Lookups must be fast, so a key value store plus cache fits well.
- Redirects should return quickly with a proper status code.
Key idea
A URL shortener maps a unique short code to a long url, with a write path that creates the code and a read heavy lookup path that redirects, backed by a fast key value store.