Short links with click analytics

A small team's link shortener must support custom aliases, click analytics and 100 times the traffic.

To design a URL shortener, separate redirects, which are read-heavy, from link creation. Generate unique short codes with a counter or random codes plus a uniqueness check, cache hot links in front of the database, and record clicks asynchronously so analytics never slow a redirect.

The system today: A marketing tool shortens links. One web server takes requests to create a link and to follow one. It writes to a single SQL database table (short code, long URL, created time). It handles a few hundred redirects a day, and the server and the database run on one machine.

What has to change: A customer launches a campaign: expect about 100 million redirects a day, links that people can name themselves (custom aliases), and a dashboard showing clicks per link per day. Redirects must stay fast, and a link must never point to the wrong place.

Questions to ask first

Where the interviewer digs in

What a strong answer covers

Common mistakes