Capacity planning is estimating the resources (servers, storage, bandwidth) needed to support a system at scale. In interviews, this is often the first step after requirements clarification.
QPS = Total Requests per Day / Seconds per Day
Example:
- 100 million users
- 10% are DAU (Daily Active Users) = 10 million DAU
- Each user makes 10 requests/day
- Total requests = 10M × 10 = 100M requests/day
- QPS = 100M / 86,400 ≈ 1,157 QPS
- Peak QPS = 2 × avg QPS ≈ 2,314 QPS
Average QPS: Total requests / Total seconds
Peak QPS: Usually 2-3x average (depends on traffic pattern)
Traffic pattern examples:
- Social media: Peak in evening (3-5x average)
- E-commerce: Peak during sales (10x+ average)
- Enterprise SaaS: Peak during work hours (2x average)
Storage = Data per item × Items per day × Retention days
Example (Twitter):
- 500 million tweets/day
- Average tweet: 300 bytes (text) + 1 KB (metadata) = 1.3 KB
- Media: 20% of tweets have images (500 KB avg)
- Media per day: 100M × 500 KB = 50 TB/day
- Text per day: 500M × 1.3 KB = 650 GB/day
- Total per day: ~50.65 TB/day
- 5-year storage: 50.65 TB × 365 × 5 ≈ 92 PB
Problem: Design Instagram
- 500 million DAU
- Each user uploads 2 photos per day
- Average photo: 2 MB
Storage per day:
500M × 2 × 2 MB = 2,000 TB = 2 PB per day
Storage per year:
2 PB × 365 = 730 PB per year
With replication (3x):
730 PB × 3 = 2.19 EB per year
Cache = Daily Active Users × Data per user × Cache hit ratio
Example:
- 10 million DAU
- User profile: 1 KB
- 80% of users accessed daily
- Cache 20% of active users (hot data)
Cache size = 10M × 1 KB × 20% = 2 GB
- Is QPS reasonable for a single server? (1K-10K typical)
- Is storage in the right order of magnitude?
- Does bandwidth make physical sense?
- Are numbers consistent with each other?