Detailed Component Design
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
3. CAPACITY ESTIMATION & TRAFFIC ANALYSIS
------------------------------------------------------------------------
[Core Variables]
* Daily Active Users (DAU): 1,000,000 (1M)
* Total Registered Base: 10,000,000 (10M)
* Average Writes per User/Day: 10 URLs
* Read-to-Write Ratio: 10:1 (100 Reads per 10 Writes per DAU)
[Traffic & QPS Volumes]
* Total Writes per Day: 1M DAU * 10 = 10,000,000 (10M) writes/day
* Total Reads per Day: 10M * 10 = 100,000,000 (100M) reads/day
* Average Write QPS: 10,000,000 / 86,400 seconds = ~116 RPS
* Peak Write QPS (3x Avg): ~350 RPS
* Average Read QPS: 100,000,000 / 86,400 seconds = ~1,157 QPS
* Peak Read QPS (4x Avg): ~4,628 QPS
[Data Size & Storage Footprint]
* User Record Size: 1 KB (ID, Billing Tier, Metadata)
- Registered Base Storage: 10M * 1 KB = 10 GB (Static growth)
* URL Mapping Record Size: 2 KB (Long URL up to 2,048 chars, Short Code, Metadata)
- Daily URL Storage: 10M writes * 2 KB = 20,000,000 KB = 20 GB / day
- Annual URL Storage: 20 GB/day * 365 days = 7,300 GB = ~7.3 TB / year
- 5-Year Storage Target (Retention): 7.3 TB * 5 = 36.5 TB
[Network Bandwidth Calculations]
* Ingress (Write Path):
- Average: 116 RPS * 2 KB = 232 KB/s (~1.85 Mbps)
- Peak: 350 RPS * 2 KB = 700 KB/s (~5.6 Mbps)
* Egress (Read Path - Sending Redirect Headers):
- Expected HTTP Response size (301 Header + Location string) = ~500 Bytes
- Average: 1,157 QPS * 0.5 KB = 578.5 KB/s (~4.63 Mbps)
- Peak: 4,628 QPS * 0.5 KB = 2,314 KB/s (~18.5 Mbps)
[Cache Sizing (Redis RAM)]
* Goal: Cache 20% of daily read traffic volume.
* Daily unique reads needing caching: 100M reads * 20% = 20,000,000 keys.
* Cache Record Size (Only Key -> Long URL Mapping): ~1 KB
* Memory Required: 20,000,000 * 1 KB = 20,000,000 KB = ~20 GB RAM.
* Total Cluster Size (Including master-replica overhead & cushion): ~32 GB RAM.
- ========================================================================