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 /api/v1/shorten
GET /{short_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.
Create short URL
Get short URL
Short URL generation
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...
We'll use a SQL database for sequential primary key generation, and strong consistency. Use a distributed form of SQL so we can easily shard as needed. Distribute rows by hash(id). We'll use the following schema:
short_urls
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
Short URL generation
We use sequential primary key generation from the SQL database to provide unique IDs for each short URL. To keep the underlying ID private, we obfuscate it via Squids with a salted alphabet. This will allow us to convert between the primary key ID and the short URL with a deterministic 1:1 mapping that is also only convertible by us.
Cache
We'll scale the cache layer based on read demand. We'll use a 2 day TTL and a LRU eviction policy. We will lazily load data into the cache; on cache miss, generate the response, then store it in the cache.