Preparing your design workspace

Loading the problem and your latest saved attempt…

Design an Idempotent URL Shortening Service

Design a short-link service that keeps at most one live alias for each normalized destination, with expiring links, even under retries, concurrency, sharding, and regional failures.

Problem statement

For this exercise, design the simplest URL-shortening topology that satisfies the stated workload before adding coordination.

Clients may create and resolve links from multiple regions, but a first-pass design may route creates through one logical write service or primary database; active-active writers are a follow-up, not a default requirement.

Every link expires. For this exercise, a create may ask for a lifetime; if it asks for none, the link lives one year, and no create can set an expiration more than five years after that request. A normalized long URL has at most one live short code at a time.

Repeated create requests for the same normalized long URL while its link is live, including concurrent requests and ambiguous retries, must converge on that same code; as a practice rule, each such create moves the link's expiration to the later of the stored expiration and the newly requested one, so a live link's expiration never moves earlier.

A create that arrives after the link has expired gets a new code. Expiration is decided by the write authority's clock when the change commits. A short code never resolves to two destinations, an expired code stops resolving, and no code is ever reissued.

Design the public API, durable mappings, cache, ID-allocation strategy, data placement, routing, and failure behavior. Explain why the later-of rule beats keeping the original expiration or letting the latest request win, and how it behaves under retries and concurrent creates.

Explain how read replicas and edge caching absorb redirect volume without serving expired links, how a database uniqueness or conditional-write boundary prevents two live aliases for one destination, when range sharding becomes necessary, and how capacity can grow while live links remain valid.

Custom aliases, link deletion, owner-edited expiration, click analytics, and malware scanning are outside the core unless you explicitly add them after protecting the stated contract.

What to build

  1. Return the one live generated short code for a normalized long URL, creating it if none is live; a create for a live link moves its expiration to the later of the stored and requested times, and same-input retries and concurrent creates return the same code.
  2. Redirect a known code to exactly one destination only while it is live, with distinct bounded outcomes for unknown and expired codes.
  3. Keep every acknowledged mapping durable until it expires, never shorten a live link's expiration, and never reissue or reinterpret a code, including an expired one.
  4. Add storage capacity without changing live aliases or taking the redirect path offline.

At scale

  • For this exercise, accept 50,000 create requests and 500,000 redirects per second globally, with an 80/20 regional traffic split.
  • For this exercise, target p99 redirects below 100 ms and p99 creates below 500 ms in the healthy case.
  • For this exercise, nearly all create requests are repeats or retries for destinations that already have a live link: plan for about 2 billion new links a year and up to 10 billion codes issued over the service's planned five-year life. Every live link holds a distinct issued code, so at most those 10 billion links can ever be live at once, however often repeated creates extend them. Keep idempotency request records for 24 hours at about 100 bytes each. Budget 500 bytes for each live normalized destination plus 300 bytes for mapping metadata and primary, reverse, and request-identity index entries before replication and operational headroom; once a link expires it may shrink to a compact record of about 40 bytes that keeps its code from being reissued, or to nothing if codes come from an allocator that never repeats, in which case a code with no record below the issued high-water mark is answered as expired, so unknown and expired codes stay distinct. Allow one popular alias to receive 100,000 redirects per second.
  • For this exercise, survive loss of one availability zone without losing an acknowledged mapping; a cross-region partition may reject new creates rather than violate the one-live-alias rule.