Requirements


Functional Requirements:


  • Create a short URL for a given long URL.
  • Return the long URL associated with a given short URL.



Non-Functional Requirements:


  • High Availability: The system must be available 24/7 (e.g., 99.99%).
  • Low Latency: Redirects must occur in less than 100 ms.
  • Read-Heavy: The read-to-write ratio is approximately 100:1.


API Design

POST /api/v1/shorten — Create a link. Accepts long_url, returns short_url.


GET /{short_url_id} — Redirect. Returns a 302 Found status and a Location header.



High-Level Design

Describe the overall system architecture. Identify the main components needed to solve the problem end-to-end. Use the diagramming tool to create a block diagram.





Detailed Component Design

Key Generation: We use Base62 encoding. For a 7-character ID, we get 62^7 (about 3.5 trillion) unique combinations. Caching: Using Redis to cache “hot” links. Since 20% of links typically generate 80% of traffic, the cache will significantly reduce the load on the database.