URL shortener system design diagram
The classic interview question: write path, cached read path and asynchronous analytics.
About this template
Designing a URL shortener is a standard system design exercise because it is small enough to finish and still forces the important decisions: how short codes are generated, how a read-heavy workload is served, and how click analytics are collected without slowing redirects.
This template draws one reasonable answer. Redirects read from a cache first and fall back to a key-value store. Creating a link asks an ID generator for a unique code. Click events go onto a queue so the redirect returns immediately.
What is in the diagram
- API servers
- Stateless. They handle both creating short links and redirecting.
- ID generator
- Produces unique IDs that are base62-encoded into short codes, avoiding collisions without a lookup.
- Cache and key-value store
- Redirects far outnumber new links in this workload, so the most requested codes are kept in memory.
- Click queue and worker
- Analytics are eventually consistent by design; losing a redirect is worse than a late count.
More software architecture templates
Three-tier web app
Browser, load-balanced web servers, an application API, a cache and a replicated database.
Microservices
Clients, an API gateway, four services with their own data, and an event bus between them.
Event-driven architecture
Producers, a broker topic, independent consumers and a dead-letter queue.