Requirements


Functional Requirements:


  • Create a short URL for a given long URL(accessible by anyone).
  • Return the long URL associated with a given short URL(acting as a proxy).
  • Map each distinct long URL to a single short URL by default, but provide the option for multiple short URLs to be created for the same long URL if needed.



Non-Functional Requirements:


  • List the key non-functional requirements (eg low latency, scalability, reliability, etc.)...
  • High availability to handle user requests.
  • Low redirect latency (ideally under 100 ms).
  • Horizontal scalability to accommodate high traffic volumes.
  • the generated short URL should follow the format of http://servicehost.com/shortened_alias, allowing browsers to correctly route requests to your service.


Capacity Estimation

Estimate the scale of the system. Consider daily active users, read/write ratio, storage requirements, bandwidth, and any relevant QPS calculations...




API Design

at least 2 apis. one get request to read the long url and generate new persist into database and send new short as response. second get request to get short url to look up into database to get long url then redirect to it.



High-Level Design

api server run on k8s to make horizontally scale automatically. redis for data quick fetch. new record comes directly into redis and sync into database later. db uses postgresql for large volumn and quick reaction and low cost.



Database Design

Define the data model. Identify the main entities, their attributes, and relationships. Consider the choice of database type (SQL vs NoSQL) and justify your decision based on access patterns...




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.