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...
Daily Active Users: 100 million users
Read/Write: 100:1 -> 1 million of URLs are shortned daily and 100 million short requests are redirected.
Storage requirements: the biggest entity is the Short URL table or structure that will hold:
Having 1 million of newly created URLs daily we would need to allocate 192 MB daily or roughly 50 GB per year.
Bandwitdth: on read request the user will send the short url payload mainly 16 bytes + the short url site domain. Having uniformly distributed users across the world, the 100 mln requests daily => 4 mln request per hour or 60k requests per minute or 1k QPS.
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.
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...
SQL database horizontally sharded by hash of hte short url.
Tables:
NoSQL table:
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
Bloom filters: having 365 mln newly created URLs per year and 1 billion URLS approximately in 25 years, we would need the Bloom filter to handle False negative level of 10*-7, so on each 1bln of requests we will get 100 false positives for 1 billion of URLS which is acceptable.
General KV Redis Cache with LFU, will store the most frequently used urls. As some urls will generally be accessed more oftend then others.
Kafka+ NoSQL DB will ensure eventuall consistency and durability for serving statistics API.
Cache TTL / expiry flow: Each mapping is cached in Redis with a TTL (e.g., 24h, refreshed on every hit). On a cache miss or expiry, the redirect service fetches the mapping directly from the shard (hash of short code → one shard), serves the 302, and writes the result back to Redis with a fresh TTL. To protect the DB from a thundering herd on a newly-viral link, concurrent misses on the same key are coalesced (single-flight) so the shard is hit once, and the first response populates the cache for the rest.