← Back to the journal

Design a URL shortener

A design prompt covering identifiers, redirects, persistence, and caching.

The prompt

Design a service that creates a short link for a long URL and redirects visitors to the original destination. Consider a workload with many more redirects than new links.

Solution recording

This is an example prompt. Add a recording to the entry to publish a video walkthrough here.

Establish the scope

Start with link creation and redirects. Clarify whether custom aliases, expiration, destination editing, and analytics are requirements before adding them to the design.

The core data

Store the short identifier, destination, creation time, and optional expiration. Enforce identifier uniqueness in storage.

Tradeoffs to discuss

  • Random identifiers require collision handling; sequential identifiers are predictable.
  • Caching popular links reduces reads but complicates updates and expiration.
  • Redirect status codes affect browser caching and the ability to change destinations.
  • Destination validation and abuse handling belong at the service boundary.

A useful test

Follow one newly created link through a cold cache, then through a warm cache. Explain what changes if the destination expires between those two requests.