Requirements


Functional Requirements:


  • Create a short URL for a given long URL.
  • Return the long URL associated with a given short URL.
  • High Availability
  • Eventual Consistency
  • Horizontal scalability - adding multiple application servers and load balancers.
  • Data duplication to avoid single point of failures
  • We need multiple read servers(DB) and master to write. This will keep the latency low but the tradeoff is eventual consistency.
  • Sharding the data for performance
  • Caching the recently used urls. This can bring down the latency
  • Low redirect latency - Adding CDN and caching the frequently used urls can bring down the redirect latency significantly. The requests are addressed at the client level itself removing application layer latency.
  • Introduce caching at the application server level and at database level can also bring down the latency. Adding indexing at DB level can help faster queries which will also improve the latency.



Non-Functional Requirements:


  • List the key non-functional requirements (eg low latency, scalability, reliability, etc.)...


API Design

Define the APIs expected from the system. This is your chance to analyze and define the read and write paths so that you can come up with the high-level design...


Key API's :

POST : /createURL

Once the shortURL is created , the server responds with a 204 response.

GET: /getURL

getURL response will also go through the similar caching strategy as redirect URL.

DELETE: /deleteURL

Once deleted, the cache needs to be invalidated so that we dont serve stale data to users. Either we can do it in the delete session or can drop an event to clean up the cache. This will result in eventual consistency.

POST: /redirectURL

redirect URL will take the shortUrl as endpoint. This will be the high volume API. We are introducing caching at CDN, application server and DB level. When a request comes from client, the CDN is checked first and if the redirect url is already cached the request is serverd from the web server layer. If not the request comes to the application layer and if the redirect url is present in the application layer or DB layer cache it is served from there. If not the redirect URL is served from DB. While addressing the client request, the redirect URL is wrote back into the different cache layers so that the subsequent requests are served faster.



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

Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.