AlgoViz

Design a URL shortener

medium 45 min

Turn a long URL into a short code and redirect anyone who opens it.

Explain your choices

Answer first. Then compare your reasoning.

12 questions 0 got it 0 to review12 not marked

Summary

Trade-offs and cheat sheet

Decisions

DecisionChoiceBecause
301 vs 302302Links can change and clicks can be counted, at the price of load
Base62 vs Base64Base62URL-safe without escaping
Hash vs counted IDsRanges + scrambleNo collisions, fast, resilient
SQL vs NoSQL for linksDynamoDBPure key-value access
Sync vs async analyticsAsync (Kafka)Decoupled from the hot path, absorbs bursts
One vs two CDNsReady for twoFailover, with more complexity

When they push back

They sayAnswer with
"Why not just PostgreSQL?""At 3 TB I would. At 183 TB with only key lookups I prefer a store that partitions for me. I would rethink if you need rich queries on links."
"ZooKeeper for a counter?""It is light use. If the team does not run it, one compare-and-set row in a strongly consistent store does the same job."
"Your edge cache breaks analytics.""Agreed, origin cannot see those clicks, so they come from edge logs. If logs are too late for you, I drop edge caching for tracked links."
"Isn't 302 slower?""Slightly more traffic for us, yes. In return links can be edited and counted."
"Is all this needed?""Not at first. I would ship version 2 and add each part when its number arrives."