| Users | Requests per Second (RPS) | Token Size & Overhead | Network Impact | Service Load |
|---|---|---|---|---|
| 100 users | ~50 RPS | Small (1-2 KB) | Minimal | Low CPU and memory usage |
| 10,000 users | ~5,000 RPS | Small (1-2 KB) | Noticeable increase in bandwidth | Moderate CPU for token verification |
| 1,000,000 users | ~500,000 RPS | Small (1-2 KB) | High bandwidth usage, network latency may increase | High CPU usage for token verification; potential bottleneck |
| 100,000,000 users | ~50,000,000 RPS | Small (1-2 KB) | Extremely high bandwidth; network saturation risk | Token verification becomes major CPU bottleneck; scaling challenges |
JWT token propagation in Microservices - Scalability & System Analysis
Start learning this pattern below
Jump into concepts and practice - no test required
The first bottleneck in JWT token propagation is the CPU load on microservices caused by verifying tokens on every request. Each service must decode and validate the JWT signature, which is CPU-intensive. As requests grow, this verification step consumes significant CPU resources, slowing down response times.
Network bandwidth can also become a bottleneck at very large scales due to token size added to every request header, but CPU is the primary bottleneck initially.
- Token Verification Caching: Cache verification results for tokens during their validity period to avoid repeated cryptographic checks.
- Offload Verification: Use an API gateway or dedicated authentication service to verify tokens once and pass trusted context downstream.
- Horizontal Scaling: Add more instances of microservices behind load balancers to distribute CPU load.
- Use Lightweight Tokens: Minimize JWT size by including only essential claims to reduce network overhead.
- Asynchronous Processing: For non-critical paths, defer token verification or batch requests.
- Network Optimization: Use HTTP/2 or gRPC to reduce header overhead and improve network efficiency.
- At 10,000 users (~5,000 RPS), CPU usage for token verification can reach 30-50% on a single server.
- Each JWT token adds ~1-2 KB per request header, so at 5,000 RPS, bandwidth overhead is ~5-10 MB/s.
- At 1 million users (~500,000 RPS), bandwidth overhead approaches 500-1000 MB/s (4-8 Gbps), requiring high network capacity.
- Storage for tokens is minimal since JWTs are stateless, but caching verification results requires memory proportional to active tokens.
When discussing JWT token propagation scalability, start by explaining the token verification process and its CPU cost. Then identify the bottleneck (CPU on microservices). Next, propose solutions like caching verification results or offloading verification to a gateway. Discuss network overhead and how to reduce token size. Finally, mention horizontal scaling and network optimizations. Structure your answer by identifying bottlenecks, explaining impact, and proposing targeted fixes.
Your database handles 1000 QPS. Traffic grows 10x. What do you do first?
Answer: Since the database is the bottleneck at 1000 QPS, and traffic grows to 10,000 QPS, the first step is to add read replicas and implement connection pooling to distribute load and reduce contention. For JWT token propagation, similarly, if token verification CPU load grows 10x, first add horizontal scaling and caching of verification results before optimizing further.
Practice
Solution
Step 1: Understand JWT token role
JWT tokens carry user identity and claims securely in a compact form.Step 2: Identify propagation purpose
Propagating JWT tokens allows each microservice to verify and trust the user's identity without storing it locally.Final Answer:
To securely share user identity information across multiple services -> Option CQuick Check:
JWT propagation = share identity securely [OK]
- Confusing JWT propagation with data storage
- Thinking JWT encrypts all communication
- Assuming JWT replaces all authentication methods
Solution
Step 1: Identify standard header for tokens
The Authorization header is the standard way to send bearer tokens like JWT in HTTP requests.Step 2: Confirm other headers' roles
X-Auth-Token is less standard, Cookie is for browser sessions, Content-Type defines data format.Final Answer:
Authorization -> Option AQuick Check:
JWT token sent in Authorization header [OK]
- Using Cookie header for token forwarding
- Confusing Content-Type with authentication headers
- Assuming custom headers like X-Auth-Token are standard
fetch('http://serviceB/api', {
headers: { 'Authorization': req.headers['authorization'] }
})
What will happen if the original request has no Authorization header?Solution
Step 1: Check header forwarding code
The code forwards req.headers['authorization'] directly as the Authorization header value.Step 2: Understand missing header behavior
If req.headers['authorization'] is undefined, the header is omitted in fetch, so Service B gets no Authorization header.Final Answer:
Service B receives the request without any Authorization header -> Option DQuick Check:
Missing header means no Authorization sent [OK]
- Assuming 'undefined' string is sent as header value
- Expecting fetch to throw error on missing header
- Thinking header is set to empty string automatically
Solution
Step 1: Analyze verification failure causes
Verification fails if the microservice uses a wrong secret or public key to check the JWT signature.Step 2: Evaluate other options
Not forwarding headers causes downstream issues, sending tokens in body is non-standard but not verification failure, caching affects freshness but not signature verification.Final Answer:
The microservice uses a different secret or public key to verify tokens -> Option BQuick Check:
Wrong key = verification fails [OK]
- Confusing forwarding issues with verification errors
- Assuming token location affects signature verification
- Ignoring key mismatch as cause of failure
Solution
Step 1: Understand token propagation best practice
JWT tokens should be forwarded unchanged so each service can verify the original user identity and claims.Step 2: Evaluate alternatives
Generating new tokens breaks trust chain; skipping tokens breaks authentication; fetching tokens from another service adds complexity and risk.Final Answer:
Service A sends the JWT to Service B, which forwards the same JWT to Service C; each service verifies the token locally -> Option AQuick Check:
Forward original JWT for trust and verification [OK]
- Creating new tokens at intermediate services
- Not forwarding tokens to all downstream services
- Relying on token fetching instead of forwarding
