KatInterview

Design a URL Shortener with Fast Redirect Lookups

System DesignModel answer
EasyModel answerSystem Designsystem designstorageindexing

Last updated

Design a system that converts long URLs into short codes and resolves them to the original URL with low latency at modest scale.

Background

A URL shortener takes an arbitrary long URL (e.g., https://example.com/very/long/path?query=123) and returns a short code (e.g., short.ly/aB3xZ). When a user visits the short link, they are redirected to the original URL within milliseconds.

This is a classic entry-level system design problem that tests your understanding of storage choices, indexing, and read-heavy workload optimisation.

Functional Requirements

  • Shorten: given a long URL, return a unique short code (6–8 alphanumeric characters).
  • Redirect: given a short code, return the original URL (HTTP 301/302 redirect).
  • Optional: basic click analytics (count redirects per short code).

Non-Functional Requirements / Scale

  • Write rate: ~500 new short URLs per second (peak).
  • Read rate: ~50,000 redirects per second (100:1 read-to-write ratio).
  • Data retention: URLs live for at least 2 years.
  • p99 redirect latency: under 20 ms.
  • Availability: 99.9% uptime is sufficient; strong consistency is not required.

What Is Expected

Walk through:

  1. API design (endpoints and response codes)
  2. Short code generation strategy
  3. Data model and storage choice
  4. How you index and cache for fast lookups
  5. At least two trade-offs you consciously made

Hints

Hint 1

How many total short codes will you need to store over 2 years at 500 writes/sec? Does a relational DB with a single primary-key index handle that, or do you need something else?

Hint 2

The read-to-write ratio is 100:1. What layer can absorb most reads before they ever hit your database?

Hint 3

Think about what HTTP status code to return on redirect and why the choice affects browser and CDN caching behaviour.