| Users | Centralized Auth | Distributed Auth |
|---|---|---|
| 100 users | Single auth server handles requests easily; low latency | Each service manages auth locally; simple token validation |
| 10,000 users | Auth server load increases; may need load balancing; DB queries rise | Token issuance centralized; local validation reduces auth server load |
| 1,000,000 users | Auth server becomes bottleneck; DB and network saturated; latency rises | Distributed token validation scales well; token revocation and sync become complex |
| 100,000,000 users | Single auth cluster struggles; needs sharding, caching, and global load balancing | Highly scalable; requires robust token management, sync, and security policies |
Centralized vs distributed auth in Microservices - Scaling Approaches Compared
Start learning this pattern below
Jump into concepts and practice - no test required
In centralized auth, the authentication server and its database become the first bottleneck as user count grows. It handles all login and token issuance, causing CPU, memory, and DB query overload.
In distributed auth, the main bottleneck shifts to token management complexity, especially token revocation and synchronization across services, which can cause inconsistencies and security risks.
- Centralized Auth: Use horizontal scaling with multiple auth servers behind load balancers; implement caching for session data; use read replicas for DB; shard user data by region or user ID.
- Distributed Auth: Use stateless tokens (e.g., JWT) for local validation; implement token revocation lists with fast distributed caches like Redis; synchronize token state with event-driven messaging; enforce strict token expiry policies.
- Use CDNs and edge servers to reduce latency for auth requests globally.
Assuming 1 million users with 10% active per second = 100,000 auth requests/sec peak.
- Centralized auth server: Each server handles ~3000 QPS, so ~34 servers needed.
- Database: Needs to handle 100,000 QPS; use sharding and read replicas.
- Network bandwidth: Assuming 1 KB per auth request, 100 MB/s bandwidth needed.
- Distributed auth: Token validation is local, reducing auth server load to token issuance only (e.g., 10% of requests), lowering server count.
Start by defining the auth model clearly. Discuss trade-offs between centralized and distributed approaches. Identify bottlenecks at each scale. Propose concrete scaling techniques matching bottlenecks. Highlight security and consistency challenges. Use real numbers to justify decisions.
Your database handles 1000 QPS. Traffic grows 10x to 10,000 QPS. What do you do first?
Answer: Add read replicas and implement caching to reduce DB load before scaling application servers. Consider sharding if growth continues.
Practice
Solution
Step 1: Understand centralized authentication
Centralized authentication means one dedicated service manages all login and identity checks for the system.Step 2: Compare with other options
Distributed auth where each service verifies independently, client-only auth, or no auth are not centralized.Final Answer:
A single service handles all user login and identity verification -> Option DQuick Check:
Centralized auth = single service [OK]
- Confusing centralized with distributed auth
- Thinking each service handles login in centralized auth
- Assuming client-only authentication is centralized
Solution
Step 1: Identify token types in distributed auth
Distributed authentication commonly uses tokens like OAuth 2.0 access tokens to verify identity without contacting a central service each time.Step 2: Eliminate incorrect options
SQL queries, unsigned cookies, and plain text passwords are not secure tokens used for distributed auth.Final Answer:
OAuth 2.0 access token -> Option AQuick Check:
Distributed auth token = OAuth 2.0 token [OK]
- Confusing SQL queries with tokens
- Using unsigned cookies as secure tokens
- Thinking plain text passwords are tokens
Solution
Step 1: Understand local JWT validation
When services validate JWT tokens locally, they avoid network calls to a central auth server, reducing latency and dependency.Step 2: Analyze other options
Token revocation is harder locally, centralized control over user sessions is lost, and tokens still need expiration.Final Answer:
Reduced latency and less dependency on a central service -> Option AQuick Check:
Distributed auth local validation = less latency [OK]
- Assuming token revocation is easier locally
- Thinking local validation means centralized control
- Ignoring token expiration needs
Solution
Step 1: Identify problem with centralized auth downtime
Downtime of the central auth service causes failures in login or token validation.Step 2: Choose a solution to reduce dependency
Caching tokens locally in services reduces calls to the central auth, improving availability without removing auth or security.Final Answer:
Implement caching of authentication tokens in services -> Option CQuick Check:
Fix downtime by caching tokens [OK]
- Removing authentication entirely
- Switching to insecure plain text passwords
- Switching to distributed auth without planning
Solution
Step 1: Analyze security and latency needs
High security requires token validation and revocation; low latency requires avoiding frequent central calls.Step 2: Evaluate options
Distributed authentication using signed tokens validated locally with periodic revocation checks uses signed tokens validated locally to reduce latency and periodic revocation checks to maintain security. Centralized authentication with synchronous calls for every request causes latency, no authentication is insecure, and centralized authentication with no token expiration risks stale sessions.Final Answer:
Distributed authentication using signed tokens validated locally with periodic revocation checks -> Option BQuick Check:
Balance security and speed with distributed tokens [OK]
- Choosing no authentication for speed
- Ignoring token expiration and revocation
- Relying on central auth for every request causing latency
