KatInterview

Design a Compact Link Redirect Service

System DesignModel answer
MediumModel answerSystem Designdistributed-systemsscalabilitycaching

Last updated

Build a distributed system that maps long URLs to short alphanumeric codes and serves fast redirects at scale.

Design a Compact Link Redirect Service

You need to architect a service that converts lengthy URLs into short alphanumeric codes and redirects users back to the original destination when they visit the shortened link.

Functional Requirements

  • Create short link: Accept a long URL and return a compact alias (for example, aB3xK9m).
  • Redirect: When a user visits the short link, send them to the original URL.
  • Custom codes: Allow users to request a specific alias if it's available.
  • Optional: Support link expiration and per-user link management.

Non-Functional Requirements

  • Scale: The service creates roughly 100 million new links each month.
  • Performance: Redirects must be fast—ideally under 50 ms at the 99th percentile.
  • Availability: The redirect path should remain available even during partial outages.
  • Compactness: Aliases should be as short as practical while avoiding collisions over a 10-year horizon.

What to Cover

  1. Capacity estimation: Calculate read/write rates, storage needs, and alias length.
  2. API contracts: Define the endpoints and their request/response format.
  3. Data storage: Choose a database technology and schema that fits the access pattern.
  4. Alias generation: Explain how you produce unique codes and handle collisions or custom requests.
  5. Scaling and caching: Describe how to serve high redirect traffic and distribute data across nodes.

Hints

Hint 1

Calculate the collision space for Base62 encoding with different lengths to justify your alias size.

Hint 2

Consider whether identical long URLs submitted by different users should map to the same short code or separate ones.

Hint 3

Think about the difference between a 301 permanent redirect and a 302 temporary redirect for analytics and caching.