The interview prompt

“Design a URL-shortening service with fast redirects.”

Assume 1 million new links and 100 million redirects per day. Links may expire or be disabled by their owner. Creation requires authentication; redirects are public. We will design creation, lookup, expiration, and asynchronous analytics. Traffic and retention figures are illustrative.

01. Clarify the API and redirect behavior

Propose POST /links with destination URL, optional expiry, and an idempotency key. Return the short code and full short URL. GET /{code} looks up an active mapping and returns a redirect. Define unknown and expired-link responses separately.

Use HTTP or HTTPS destinations only and validate syntax. Do not fetch arbitrary destinations in the synchronous creation path. If a separate scanner visits links, isolate it from private networks and apply bounded fetch controls.

Choose a temporary redirect when destinations or safety status may change. Permanent redirects can be cached beyond your direct control, which complicates revocation and analytics. RFC 9110 defines the redirect status semantics; cache behavior also depends on cache directives and clients.

02. Allocate codes without silent collisions

A seven-character base62 namespace contains 62⁷ = 3,521,614,606,208 possible strings. That capacity does not mean random allocation is collision-free. Enforce uniqueness in storage and retry a generated code on conflict.

Monotonic IDs encoded in base62 simplify uniqueness but reveal ordering and are easy to enumerate. Random codes reduce obvious sequence exposure, yet short links are still public identifiers rather than an authorization mechanism.

Custom aliases use the same uniqueness boundary. Scope idempotency keys to the authenticated owner and reject reuse with conflicting request parameters.

03. Optimize the read path

Redirect path
Short codeMapping cacheMapping storeRedirect
The durable mapping store is authoritative. Analytics events leave the critical path asynchronously.

Store code, destination, owner, creation time, expiry, status, and version. Cache hot mappings with bounded lifetimes and check expiry before redirecting. Use short negative-cache lifetimes so newly created codes do not remain falsely absent.

The assumed traffic averages about 1,160 redirects per second; a 10× peak is about 11,600. At 500 bytes per mapping, one year of one million daily creations is roughly 182.5 GB of raw mapping data before indexes, replicas, and overhead.

A popular link can be a hot key. Cache it near readers, collapse concurrent cache misses, and make sure a cold-cache event does not overload the store.

04. Make updates and expiration explicit

A new link should work immediately after successful creation. Route an initial miss to an authoritative read or use a read-your-write strategy if replicas can lag.

For a disabled link, update durable state and invalidate caches. Define the maximum stale-redirect window and use short lifetimes or version-aware checks where immediate revocation matters. Deleting a database row alone does not revoke a cached redirect.

Do not rapidly reuse expired codes: old bookmarks or caches could send visitors to a new owner's destination. Treat code reuse as a separate product decision with a strong safety argument.

05. Keep analytics from breaking redirects

Emit click events asynchronously with a unique event ID where deduplication is needed. If analytics is unavailable, a policy may prioritize the redirect and tolerate bounded event loss. Exact billing-grade counting would require a stronger design than best-effort click analytics.

Limit retained visitor data and avoid logging sensitive destination query strings unnecessarily. Monitor redirect latency, cache hit rate, storage errors, missing mappings, and invalidation lag.

06. Defend the choices

“Can the same long URL share one short code?”

Only if ownership, expiration, and analytics semantics permit it. Per-owner links may intentionally differ even when their destinations match.

“One link receives half the traffic.”

Use caching and request coalescing rather than assuming hash partitioning alone spreads a single key. Protect creation with a rate limiter and treat redirect abuse separately.

Common mistakes

Assuming random IDs never collide, reusing expired codes casually, blocking redirects on analytics, or ignoring cached state during revocation.

Sources & further reading

RFC 9110: HTTP semantics for redirects. Architecture and scale estimates are original illustrative choices.

Continue your preparation

Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.