Microservices Security · Architecture Patterns
Where Should JWT Validation Happen?
The authentication question every microservices team eventually faces — and why the answer depends on your trust model, not your tech stack.
!DOCTYPE html>
Microservices Security · Architecture Patterns
The authentication question every microservices team eventually faces — and why the answer depends on your trust model, not your tech stack.
We help engineering teams define authentication boundaries, implement zero-trust patterns, and build identity infrastructure that scales without becoming operational debt.
Talk to UsBefore discussing architecture patterns, it is important to separate authentication from authorization — two concerns that are often confused.
"Authentication answers who is making this request. Authorization answers whether they are allowed to perform this action."
Authentication is frequently centralized. Authorization often remains inside domain services.
A user may be authenticated successfully but still not have permission to perform a specific business operation. This distinction becomes increasingly important as platforms scale — and it directly shapes which JWT validation pattern is appropriate.
Often the first approach teams implement. Every service independently validates the token end-to-end.
Each service receives the JWT directly and performs the full validation stack: signature, expiration, issuer, audience, and claim extraction.
A common middle-ground: centralize validation while still forwarding the original token downstream.
Services can choose their level of trust. Some trust the gateway's validation; others still parse the token for claims or perform additional checks.
Increasingly common in modern cloud-native platforms. The gateway validates once and injects trusted identity headers instead of forwarding the raw token.
Instead of forwarding the token itself, the gateway forwards only the required identity context. For example:
X-User-Id: 12345
X-User-Roles: ADMIN
X-Tenant-Id: tenant-001
Services receive identity context rather than raw tokens. They focus entirely on business logic.
When discussing gateway-based authentication, most conversations focus on JWT validation. The more important control is header sanitization.
Consider an incoming request that includes identity headers directly:
GET /courses
X-User-Id: admin
X-User-Role: SUPER_ADMIN
A secure gateway must enforce this flow without exception:
Incoming Request
│
▼
Remove ALL incoming identity headers (X-User-Id, X-Roles, etc.)
│
▼
Validate JWT cryptographically
│
▼
Generate trusted identity headers from validated claims
│
▼
Forward sanitized request to downstream services
"Identity information should originate from cryptographic validation — never from client-supplied input."
This single architectural control eliminates an entire class of impersonation vulnerabilities. It is often treated as an implementation detail, but it is a foundational security requirement for Pattern 3 to be safe.
Large enterprises often introduce an additional trust boundary — the gateway issues short-lived internal tokens rather than forwarding external identity.
Services validate only internal tokens. External identity is fully isolated from the internal service mesh.
There is no single dominant pattern. Different industries optimize for different priorities.
Often prefer simplicity and operational efficiency:
CloudFront / CDN
│
WAF
│
API Gateway
│
JWT Validation
│
Trusted Identity Headers
│
Microservices
Benefits: operational simplicity, faster development cycles, centralized security governance.
Often prefer stronger internal trust isolation:
Gateway
│
Validate JWT
│
Internal Identity Token
│
Microservices
Benefits: stronger trust boundaries, security isolation between external and internal identity domains.
Often prefer independent verification at every layer:
Gateway
│
JWT
│
Services Validate JWT Independently
Benefits: independent auditability, regulatory compliance, strong service autonomy that satisfies external audits.
| Pattern | Best For | Main Tradeoff |
|---|---|---|
| Validation in every service | Regulated industries | High operational overhead |
| Gateway validates, forwards JWT | Migration / transitional | Token propagation risk |
| Gateway validates, forwards context | SaaS, cloud-native | Gateway trust dependency |
| External + internal tokens | Enterprise, financial | Added infrastructure complexity |
JWT validation is often presented as a security problem. In practice, it is usually an architecture problem.
Every approach discussed here is technically valid. Each represents a different balance between security, simplicity, performance, service autonomy, and operational complexity.
"The question is not where JWT validation happens. The better question is: what trust model is our platform trying to achieve?"
The most successful microservices platforms are not the ones that blindly follow a particular pattern. They are the ones that understand their trust boundaries, apply them consistently, and choose an approach that aligns with their business, operational, and regulatory requirements.
Once that answer is clear, the architecture usually follows.
Topics