0
0
HLDsystem_design~10 mins

OAuth 2.0 flow in HLD - Scalability & System Analysis

Choose your learning style9 modes available
Scalability Analysis - OAuth 2.0 flow
Growth Table: OAuth 2.0 Flow Scaling
UsersRequests per SecondToken IssuanceDatabase LoadNetwork TrafficLatency
100 users~10-20 RPSLow token requestsSingle DB instance handles wellLow bandwidth usageLow latency
10,000 users~1,000-2,000 RPSModerate token requests, refreshesDB load increases, possible CPU spikesModerate bandwidth usageLatency may increase slightly
1,000,000 users~100,000 RPSHigh token issuance and validationDB bottleneck likely, connection limits hitHigh bandwidth, possible network congestionLatency noticeable without caching
100,000,000 users~10,000,000 RPSVery high token traffic, refresh stormsSingle DB impossible, sharding neededVery high bandwidth, CDN and edge caching neededLatency critical, must optimize globally
First Bottleneck

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.

Scaling Solutions
  • 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.
Back-of-Envelope Cost Analysis
  • 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.
Interview Tip

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.

Self Check Question

Your database handles 1000 QPS for token validation. Traffic grows 10x to 10,000 QPS. What do you do first and why?

Key Result
The database storing tokens and sessions is the first bottleneck as OAuth 2.0 traffic grows; caching tokens and horizontally scaling authorization servers are key to scaling.