The first system design interview question: key generation, heavy reads, a cache in front, and click analytics off the request path.
What is on this board
Parts
- Visitor User
- Edge cache CDN · Cloudflare
- Short links Service · Go
- Key generator Service
- Hot links Cache · Redis
- Links Key-value store · DynamoDB
- Clicks Message queue · Kafka
- Click counter Stream processor
- Analytics Data warehouse · ClickHouse
- Back of the envelope Data table
- Random-looking keys from a counter Decision record
- 301 or 302? Decision
- 301 Option
- 302 Option
How they connect
- Visitor → Edge cache: opens the short link
- Edge cache → Short links: on a miss
- Short links → Hot links: key?
- Short links → Links: key?
- Short links → Key generator: new key
- Short links → Clicks: clicked
- Clicks → Click counter: consume
- Click counter → Analytics: write
- 301 or 302? → 302: chosen
Notes and decisions
- Short links: Create and redirect
- Key generator: Hands out ranges of IDs, encoded in base62
- Hot links: Most links are never read twice; a few are read a lot
- Links: short key -> long URL
- Random-looking keys from a counter: A hash can collide. A counter handed out in ranges can't, and any server can use its range with no coordination.
- 301: Fewer requests, but the browser caches it and clicks go uncounted
- 302: Every click reaches us. Chosen: analytics matter
More like this
News feed, like TwitterFan-out on write or on read? Timelines in a cache, the celebrity problem, and how a post reaches millions of followers.
News feed, like TwitterFan-out on write or on read? Timelines in a cache, the celebrity problem, and how a post reaches millions of followers.
Ride hailing app, like UberMatching riders and drivers: live locations in a geo index, dispatch, surge, trips and payments. A classic system design interview.