Short links with click analytics: a system design interview question
A small team's link shortener must support custom aliases, click analytics and 100 times the traffic. It is a junior-level question of about 30 minutes, and it starts from a system that already works, which is how many real design interviews begin.
How do I approach the short links with click analytics question?
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.
Practise this design interview
The situation
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 you are asked to design
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 worth asking first
How long should links live, and can an owner edit or delete one?
What read-to-write ratio should I assume, and how fast must a redirect be?
Must click counts be exact and real time, or can they be a few minutes behind?
Can two people ask for the same custom alias at once, and what happens then?
Where interviewers dig
Generating unique short codes without collisions across many servers.
A cache in front of the database for hot links, and what invalidates it.
Counting clicks without slowing redirects down.
What a strong answer covers
Separates the read path (redirects, very hot) from the write path (creating links) and sizes them: about 1,200 redirects a second on average, several times that at peak.
Chooses a code scheme and justifies it: a counter or a distributed ID turned into base62, or random codes with a uniqueness check, and says what happens on a collision.
Puts a cache in front of reads, and handles the alias race with a unique constraint rather than a read-then-write.
Records clicks asynchronously (a queue or a log), aggregates them in batches, and explains why the dashboard can lag slightly.
Traps that cost points
Hashing the long URL and truncating it without handling collisions.
Counting clicks with a database update on every redirect, which turns the hot read path into a write path.
Using a temporary redirect when the requirement was permanent, or the reverse, without discussing caching of redirects.
How the practice works here
It works on a laptop or desktop, not on a phone: the canvas and the interviewer's view of your drawing need the screen space.
You talk with the interviewer by voice, and the canvas already shows the company's system as it is today. You extend it, and the interviewer sees what you draw. A button pauses your microphone when you want to think or sketch in silence; the interviewer waits.
When the time is up you get a report: a hire or no-hire call for the level, ratings for problem navigation, solution design, technical depth and communication with a quote from your own answer for each, what to fix, and the points a strong answer covered that yours did not. Your first interview on giveinterview, of any kind, is free, and every interview report is free. After that a design interview costs credits at the same per-minute rate as a role interview, and playing duels earns credits you can spend on it.
Frequently asked questions
How long is this design interview?
About 30 minutes, the length of a typical junior-level design round.
Can I do it on my phone?
No. System design practice needs a computer screen for the canvas, so it is for laptops and desktops only.
Do I have to draw?
Yes. The canvas starts with the current system and the interviewer sees what you add, as at a whiteboard. You can pause your microphone to sketch and explain afterwards.
Is it free?
Your first interview on giveinterview, of any kind, is free, and every interview report is free. After that a design interview costs credits at the same per-minute rate as a role interview, and playing duels earns credits you can spend on it.
Keep reading
- A rate limiter for a public API: a system design interview question
- A news feed that stays fast at 10 million users: a system design interview question
- Real-time chat with delivery receipts: a system design interview question
- A reliable notification system: a system design interview question
- Selling tickets without selling a seat twice: a system design interview question
- Matching riders with nearby drivers: a system design interview question
- A payments ledger you can trust: a system design interview question
- Practice interview online, with an interviewer that answers back
- Company interview guidesRounds and questions by company