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/long-urls
body {
"longUrl": string
}
GET /api/long-url/[shortUrl]
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.
Load balancer sits in front of the server, after the CDN. It routes traffic between multiple servers. Use a Level 7 load balancer here to route traffic intelligently.
The server itself handles API routes for GET and POST.
45GB/day means that database sharding will be required.
Consistent hashing on the URL's database ID to partition shards?
CDN can actually cache the response to /api/[shortUrl] since it never changes!
Given the high read/write ratio, we are optimizing for high-read count here. This means: Caching! So, a redis cache sits in front of our database and caches responses to requests for any given URL, with the short url as the hash key, and the long url as the hash value in each KV string. Since the URL mappings never change, and extremely long TTL can be used. Maybe lazy-caching since some URLs may never be used and we don't want to overfill the cache.
Due to the nature of this system, some URLs will be read far, far more than others, with some extremely hot paths. This means that we need to optimize for hot-read-paths.
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.