Requirements


Functional Requirements:


  • Create a short URL for a given long URL.
  • Return the long URL associated with a given short URL.
  • Track user engagement by providing analytics such as:
    • User click tracking
    • User click tracking by country



Non-Functional Requirements:


  • Performance (The system has to have low latency, the users can't wait for longer than 1 second for a redirect)
  • Reliability (The system needs to be highly available and data should be consistent)
  • Scalability (The number of the system users could increase quickly specially on the return end)


API Design

  • create a short URL - POST /url parameters: long_url returns shortened_url
  • redirect to original URL - GET /url returns 301-302 redirect with location of long URL


High-Level Design

  • CDN with cache to speed up the request redirects to the users
  • Load balancer to manage traffic to the application servers
  • Application servers
  • Database with read replicas since the heavier traffic would be reading data from the DB



Detailed Component Design

When users request a url using the shortened version, the request would go to the nearest CDN to the user, check the cache if the information is available in the cache and is valid, the CDN would directly return the redirect request to the browser with the relevant information like the actual URL, one thing to think of here is analytics, yet even if a request does go to the server, we don't want to cause any delays in the response therefor recording the event to the database would also cause latency. the solution is to in both cases resolve the request and respond to the client, while in parallel at the CDN level or the server level record the event in an event pipeline, then asynchronosly resolve the analytics events.