KatInterview

Build a Link Compression Service

System DesignModel answer
MediumModel answerSystem Designdistributed-systemsscalabilitycaching

Last updated

Design a scalable service that converts long URLs into compact aliases and redirects users back to the original destinations.

Problem

Design a service that compresses URLs into shorter versions and handles redirection. Users submit lengthy URLs and receive compact aliases that redirect to the original destination when visited.

Core Functions

Your service must support:

  1. Compression: Accept a long URL and return a short, unique identifier
  2. Resolution: When someone visits the short link, redirect them to the original URL
  3. Custom identifiers: Let users choose their own alias (if available)
  4. Optional analytics: Track how many times each link is accessed

Scale Constraints

Your design should handle:

  • Write volume: 100 million new URLs created daily
  • Read volume: 1 billion redirections per day
  • Latency target: Redirections complete in under 100ms
  • Reliability: No data loss; links remain accessible indefinitely (or until expiration)
  • Availability: Service stays operational under heavy traffic

What to Cover

Provide a complete design including:

  • REST API specification with endpoints and payloads
  • Data storage strategy (technology choice and schema)
  • System architecture showing all major components
  • Short code generation approach with collision handling
  • Performance optimizations for read-heavy workload
  • Discussion of key trade-offs and design decisions

Hints

Hint 1

Calculate the minimum identifier length needed to avoid exhausting the namespace within 5 years

Hint 2

The read-to-write ratio is roughly 10:1 - design for the common case

Hint 3

Consider how to guarantee uniqueness without checking the database on every write

Hint 4

Think about what happens when a link goes viral and gets millions of hits in minutes