Reference path
The URL Shortener solution is read-only study material. Use it to compare your own design against a compact reference path before starting practice or after you finish a pass.
- Keep link creation separate from the redirect hot path.
- Protect the redirect path with cache-first reads and durable mapping fallback.
- Move click analytics and reporting out of the synchronous redirect flow.
- Treat abuse checks as part of creation, not every redirect.
Review the problem detail before you compare trade-offs.
High-level design
At MVP scale, the creation API validates destinations, reserves a short code, and writes the mapping. The redirect service resolves short codes quickly, reads from cache first, falls back to the mapping store, and emits click events asynchronously.
POST /links
GET /{code}
GET /links/{code}
The cache is an optimization, not the source of truth. The mapping store remains authoritative for destination URLs, aliases, expiry rules, and ownership metadata when later account stories add durable history.
Trade-offs to study
Counter-based IDs are compact and easy to reason about, but the allocator needs sharding or preallocation before it becomes a bottleneck. Random IDs reduce coordination but require collision handling. Custom aliases should stay on an explicit validation path so the default allocator stays fast and predictable.
Do not model learner practice diagrams as Mermaid in this reader. Authored Mermaid explains reference content; learner high-level-design work remains a future canvas submission flow.