Back to Notes

Problem Statement: Design a URL shortener like bit.ly

Functional Requirements

  1. URL Shortening - Get Unique URL (combination of English letters and digits)
  2. URL Redirection
  3. Link Analytics - Click count

Non-Functional Requirements

  1. Minimize redirect latency
  2. 100M Daily active users
  3. 1 B reads per day
  4. 1-5B total lifetime URLs
  5. Highly Available
  6. High Durability - URL should be stored in reliable database even across failures it should ensure long term access

API Design

  1. POST /api/urls/shorten
    1. Request: Long URL
    2. Response: Shortened URL
    3. { "shortURL": "http://urlshortner.ly/bar4R5"}
  2. GET /api/urls/{shortURL}
    1. Request: short Url
    2. Redirect Long URL - 302 (Non catch) (301 - For catch - bit.ly uses this but using this won't give accurate analytics)

High Level Design

  1. URL Shortening
    • Client: The Front End will send the POST request to shorten URL to shorten URL service.
    • URL Shorten Service:
      • It will generate unique shortend URL by encoding the original URL or using hashing
      • Store the mapping of short to long URL into database.
      • Manages errors and ensure each short URL is unique across all users.
    • Database:
      • We will use highly available NoSQL database liek DynamoDB or Cassandra to store the mappings of short and long URL. NoSQL is preferred for its high write throughput, key value storage.

        ![[Pasted image 20250516234206.png]]

  2. URL Redirection
    • API Gateway: We have introduced two different micro services one to shorten the URL and another to read and redirect the URL. so to handle different request and redirect it to appropriate micro-service we need API Gateway. This will act as the entry point for all incoming requests, routing POST request to the URL shortening service and GET requests to the URL redirection handler.

    • URL Redirection Request handler: It accepts GET request with shortened URL, retrives the original URL from the database and responds with 302 Found status and the original URL in the Location header to facilitate redirection.

      ![[Pasted image 20250516234943.png]]