System design
Design a URL shortener
Design a service that turns a long URL into a short link, like sho.rt/aZ3k9Q, and sends anyone who opens the short link on to the original URL with a redirect.
It takes about 100 million new links a month and keeps them for five years. Each link is opened about 100 times on average, and redirects peak near 20,000 a second. A long URL averages 500 bytes, and users can choose their own alias instead of a generated code.
Things to cover
- Generating short codes, and how long they need to be
- The data model, and where the links are stored
- Keeping redirects fast: caching, and a 301 versus a 302
- Custom aliases, collisions and abuse