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...
GET /url/{urlID} -> redirect to link
PUT /url -> ID
URL:
{
id: string,
url: string,
expiration: int
}
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.
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...
Using DynamoDB or similar NoSQL
Tables:
URL
{
id: string (UUID or similar), partition key
url: string,
expiration: int, ttl
}
Having the partition key on the URL object be the url string prevents duplicates. Expiration acts as a TTL so URLs get rotated out when they are temporary.
We can do DynamoDB PutItem to handle when the URL already exists in the DB
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
Everything is serverless so scaling will be handled for us.
IDs are a version of UUIDs that are short enough and unique enough for our use case. Collisions would be possible (although incredibly unlikely) but can be handled by returning a 500 if the DB insert does not work and having the client retry.