| Users | Requests per Second | Token Issuance | Database Load | Network Traffic | Latency |
|---|---|---|---|---|---|
| 100 users | ~10-20 RPS | Low token requests | Single DB instance handles well | Low bandwidth usage | Low latency |
| 10,000 users | ~1,000-2,000 RPS | Moderate token requests, refreshes | DB load increases, possible CPU spikes | Moderate bandwidth usage | Latency may increase slightly |
| 1,000,000 users | ~100,000 RPS | High token issuance and validation | DB bottleneck likely, connection limits hit | High bandwidth, possible network congestion | Latency noticeable without caching |
| 100,000,000 users | ~10,000,000 RPS | Very high token traffic, refresh storms | Single DB impossible, sharding needed | Very high bandwidth, CDN and edge caching needed | Latency critical, must optimize globally |
OAuth 2.0 flow in HLD - Scalability & System Analysis
The first bottleneck in OAuth 2.0 flow scaling is the database that stores tokens, authorization codes, and user sessions. As user count and requests grow, the DB faces high read/write load, connection limits, and latency issues. Token validation and refresh operations increase DB pressure quickly.
- Database Scaling: Use read replicas to offload read queries, connection pooling to manage DB connections, and sharding to distribute data across multiple DB instances.
- Caching: Cache access tokens and user session data in fast in-memory stores like Redis to reduce DB hits.
- Horizontal Scaling: Add more authorization servers behind load balancers to handle increased request volume.
- Token Design: Use JWT tokens to reduce DB lookups by embedding claims in tokens, validated cryptographically.
- CDN and Edge: For public OAuth endpoints, use CDN to reduce latency and bandwidth usage globally.
- Rate Limiting: Implement rate limiting to prevent abuse and reduce load spikes.
- At 1M users with 100K RPS, DB must handle ~100K token validations/refreshes per second.
- Assuming 1 token validation = 1 DB read, 1 refresh = 1 write + 1 read, DB QPS can exceed 200K.
- Single PostgreSQL instance handles ~5K QPS, so need ~40+ replicas or sharding.
- Network bandwidth: 100K RPS * 1KB token size = ~100MB/s (~800Mbps), requires 1Gbps+ network.
- Memory for caching tokens: 1M active tokens * 1KB = ~1GB RAM minimum.
When discussing OAuth 2.0 scalability, start by explaining the flow and components. Identify the database as the first bottleneck due to token storage and validation. Then discuss caching and horizontal scaling of authorization servers. Mention token design improvements like JWT to reduce DB load. Finally, cover network and rate limiting strategies. Structure your answer from small scale to large scale with clear bottlenecks and solutions.
Your database handles 1000 QPS for token validation. Traffic grows 10x to 10,000 QPS. What do you do first and why?