Jump to a problem, path or page
Jump to a problem, path or page
01 · Develop the design
Use a stateless API, durable link mappings, cache-aside redirects, and asynchronous click processing. The diagram shows logical dependencies; production services may have multiple instances behind a load balancer.
Stage 1
Separate the two hot paths
Creation needs a durable write; redirect needs a fast lookup by code. Start by specifying POST /links and GET /:code, including unknown and expired links.
Stage 2
Make uniqueness a storage guarantee
Generate a random Base62 code, then insert it under a unique constraint. Retry a collision a bounded number of times. An existence check before insertion is not safe under concurrency.
Stage 3
Keep optional work off redirects
Read with cache-aside and bound the TTL by link expiry. Send analytics to a bounded queue consumed by a worker. Decide whether analytics loss is acceptable when the queue is unavailable.
02 · Work through the method
03 · Justify the choices
How do you allocate short codes?
Random Base62 with a unique constraint and collision retry
Random codes need a database uniqueness guarantee and bounded retries. Time alone and URL truncation can collide.
How should the cache behave?
Cache-aside with TTL bounded by link expiry
A hot mapping avoids database reads, but its cache TTL must not outlive the link. Enforce expiry on redirect too.
What happens if analytics is unavailable?
Redirect and use a bounded event queue with a documented loss policy
Keep analytics off the redirect critical path. Bound retries and queue growth, and state when events may be dropped.
04 · Plan the evidence