List functional requirements for the system (Ask the chat bot for hints if stuck.)...
List non-functional requirements for the system...
Estimate the scale of the system you are going to design...4
Compute:
Assume QPS is 10000(READ), then write QPS is 100
24 * 3600 Second -> 100 * 1000 -> 10^5 second per day
QPS 10000 READ, let's say my API latency is 100 ms, then i may need 1000 core
without caching -> 50 ~100 instances (16 core cpu)
Storage:
1 record is 100 bytes of data (100byte)
10^2 write request/s * 10^5 second -> 10^9 byte -> 1GB perday
one year is 400GB
Define what APIs are expected from the system...
3 API
POST /api/shorten
This POST request accepts the original URL, the service will generate a shortened URL and
returned to user
{
"long_url": "longurl.com"
"custom_url":"abc" (optional)
}
GET /api/short_url
{
"long_url": "longurl.com"
}
GET /short_url This is the API that will accept the short URL and redirect to the original URL
status [302]
Defining the system data model early on will clarify how data will flow among different components of the system. Also you could draw an ER diagram using the diagramming tool to enhance your design...
NoSQL. DynamoDB
Partition Key: ShortURL
Sort Key: LongURL
Attribute: creation_time, expiration_time
You should identify enough components that are needed to solve the actual problem from end to end. Also remember to draw a block diagram using the diagramming tool to augment your design. If you are unfamiliar with the tool, you can simply describe your design to the chat bot and ask it to generate a starter diagram for you to modify...
🔹 API Layer: Load-balanced microservices handling URL shortens and expansions.
🔹 Database Layer: NoSQL (DynamoDB or Cassandra)
🔹 Caching Layer: Redis for ultra-fast URL lookups.
🔹 Message Queue: Kafka to asynchronously log analytics.
🔹 CDN: Cloudflare/Akamai for redirection caching.
✅ Use UUID + Base62 Encoding (ensures global uniqueness without a central ID generator).
✅ Use Redis as a global cache (reduces DB queries, handles 90% of requests).
✅ Use a distributed database (DynamoDB, CockroachDB, or Aurora Global DB) for consistency.
✅ Use a CDN + Edge Caching (Cloudflare, Fastly) to offload static requests.
✅ Use eventual consistency (Kafka, CDC) to sync global instances.
✅ For strict consistency, use a leader-follower DB (CockroachDB, Aurora).
Explain how the request flows from end to end in your high level design. Also you could draw a sequence diagram using the diagramming tool to enhance your explanation...
The backend logic of encoding long url into a unique short url, we need a collision-free and scalable method.
Steps to Generate a short url from long url
Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...
Explain any trade offs you have made and why you made certain tech choices...
Try to discuss as many failure scenarios/bottlenecks as possible.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?