List the key functional requirements for the system (Ask the AI for hints if stuck)...
List the key non-functional requirements (performance, scalability, reliability, etc.)...
Estimate the scale of the system. Consider daily active users, read/write ratio, storage requirements, bandwidth, and any relevant QPS calculations...
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...
POST /urls
{
"long_url": "http://abd.com/some/long/url",
"alias":"some_optional_alias",
"expiration_time":"optional_expiration_time"
}
->
{
"short_url":"http:/tiny_url/pqj"
}
GET /pqj -> 302 redirect to original long url
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.
The high level design is as follows:
There are 3 components
the client
the server
the database
The client sends POST request to the server to create a short url from the original long url. The server creates a short url and saves it into the db.
The client sends the GET request to the server with the short url and the server returns a 302 redirect response to the original url.
The db used is a postgres db.
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...
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
Unique URL generation
To ensure that the url generated is unique we can use a hash function that minimizes collisions.
DB
To ensure that the reads are quick we can use a lazy loading cache with LRU eviction policy along with the DB.