Quick revision
The short answer
Each of the 60 services becomes an OAuth2 resource server that validates every token itself, including an audience check so a token issued for one service is refused by the others. Service-to-service calls use client credentials or a workload identity such as mesh mTLS certificates, and when the user's identity must travel, services forward the user token or exchange it rather than trusting headers the gateway set. All of this ships in one shared starter, and it is rolled out in monitoring mode first, logging failures, before it is enforced.
What to remember
In this answer, we saw that trusting the gateway leaves every internal API open to anyone inside the network. The design makes each of the 60 services an OAuth2 resource server that validates signature, issuer, expiry and audience locally, uses client credentials or mesh workload identity for service calls, forwards or exchanges user tokens instead of trusting gateway headers, packages everything in a shared starter, and rolls out in monitoring mode first, then enforces service by service.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Each of the 60 services becomes an OAuth2 resource server that validates every token itself, including an audience check so a token issued for one service is refused by the others. Service-to-service calls use client credentials or a workload identity such as mesh mTLS certificates, and when the user's identity must travel, services forward the user token or exchange it rather than trusting headers the gateway set. All of this ships in one shared starter, and it is rolled out in monitoring mode first, logging failures, before it is enforced.
Why this question is asked
Trusting everything behind the gateway is a design many companies start with, because it is simple and the gateway already checks tokens. The problem appears on the day something inside the network is compromised, or a service is accidentally exposed: every internal endpoint is open to anyone who can reach it, and identity headers can be forged. Interviewers ask this at the senior level because the technical change is well known, but doing it across 60 services without breaking production is a design and rollout problem. In this answer, we will see what is wrong with gateway-only checks, design the per-service validation, handle service and user identity, package it in a starter, and plan a safe rollout.
1What Is Wrong With Trusting the Gateway
Today the gateway validates the user's token and forwards the request, often with headers like X-User-Id added. The internal services check nothing. That means the only thing standing between an attacker and every internal API is network placement.
Three ordinary events break that assumption: a vulnerable service inside the cluster that an attacker controls, a misconfigured ingress or port-forward that exposes a service directly, and a developer tool or batch job with broad network access. In each case the caller can send any request, set X-User-Id to any user, and the service believes it. The design goal, often called zero trust, is that each service checks who is calling, on every request, regardless of where the request came from.
2Every Service Validates Tokens Itself
Each service becomes an OAuth2 resource server: a service that accepts access tokens and validates them locally. For JWTs, validation means checking the signature against the identity provider's published keys (its JWKS endpoint, cached in memory), and checking the issuer, the expiry with a small clock skew, and the audience.
The audience check is the one people forget. The aud claim says which service a token is meant for. Without the check, a token issued to the low-risk reporting service is also accepted by the payments service, so one leaked token works everywhere. With it, each service accepts only tokens minted for it.
Notice the cost. Local validation needs no call to the identity provider per request; after the keys are cached, a signature check takes well under a millisecond. So doing it in 60 services adds almost nothing to latency.
3Service Identity and User Identity
Two kinds of callers need different answers. When service A calls service B on its own behalf, for example a nightly job, A needs its own identity. Either it uses the OAuth2 client credentials flow, getting a token for audience B from the identity provider with its own client id, or it relies on workload identity, where a service mesh issues each pod a certificate and calls use mutual TLS, so B knows cryptographically which workload is calling.
When a user's action passes through several services, B often needs to know the user too. Here we never trust a header set upstream. A forwards the user's token if it is valid for B's audience, or, better, performs token exchange (RFC 8693): it sends the user's token to the identity provider and receives a new token for audience B that still names the user and records that A acted for them. B then validates that token like any other.
| Call | Mechanism | What B learns |
|---|---|---|
| User -> gateway -> A | User token, validated by A | The user |
| A -> B, no user involved | Client credentials or mTLS workload identity | The calling service |
| A -> B for a user | Token exchange (or forward a token valid for B) | The user and that A acted for them |
| Anything with X-User-Id only | Not accepted any more | Nothing trustworthy |
4One Shared Starter Instead of 60 Configurations
If 60 teams each write their own SecurityFilterChain, we get 60 slightly different answers. So the platform team publishes a Spring Boot starter, a dependency with auto-configuration, that provides the resource server chain with the standard issuer, audience, clock skew and error format, health endpoints left open, a RestClient and WebClient interceptor that attaches client credentials or exchanged tokens to outgoing calls, and metrics for every rejection.
A service team then adds one dependency and, at most, a few lines describing which scopes each endpoint needs. Upgrading every service to a new rule becomes a version bump, and a security review covers one code base instead of sixty.
5Rolling Out Without Breaking Production
Switching 60 services to enforcement on one day would break every caller nobody knew about. So the starter has a mode switch. In monitoring mode the service validates every token, records the result as a metric and a log line with the caller's identity, but lets the request through. In enforcing mode it rejects invalid calls.
- Add starter in monitoring modeValidate and log, never reject
- Read failures by caller for 2 to 4 weeksOpen tickets for unknown callers
- Any unexpected failures left?YesFix callers, keep monitoringNoSwitch to enforcing
- Watch 401 and 403 rates after the switchRoll back with one property if needed
4 steps in order. Play them, or step through them one at a time.
We run monitoring mode for a few weeks and read the data: which callers send no token, which send tokens with the wrong audience, which use old headers. Each finding becomes a ticket for the calling team. When a service has had no unexpected failures for, say, two weeks, it switches to enforcing, in waves of about ten services, lowest risk first, with a single property that can be flipped back if something unexpected appears.
6Follow-up questions
If every service validates tokens, do we still need the gateway check?
Yes, as a first line. The gateway rejects obviously invalid traffic early, applies rate limits and routing, and keeps the public surface small. The change is that the gateway is no longer the only check; each service also checks, so a bypass of the gateway no longer means full access.
Is mTLS from a service mesh enough on its own?
It proves which workload is calling, which is great for service-to-service authorization, but it says nothing about the user. For user-facing actions we still need a token that names the user, so most designs combine mesh identity for the channel with tokens for the user.
What happens to latency and availability if the identity provider is down?
Validation uses cached signing keys, so existing tokens keep working during a short outage. New tokens cannot be issued, and token exchange calls fail, so we cache exchanged tokens until shortly before they expire and make the identity provider a highly available tier-zero service.
7Conclusion
In this answer, we saw that trusting the gateway leaves every internal API open to anyone inside the network. The design makes each of the 60 services an OAuth2 resource server that validates signature, issuer, expiry and audience locally, uses client credentials or mesh workload identity for service calls, forwards or exchanges user tokens instead of trusting gateway headers, packages everything in a shared starter, and rolls out in monitoring mode first, then enforces service by service.
Open with
The goal is that no service trusts a request just because it reached it. I'd make each of the 60 services an OAuth2 resource server that validates the JWT itself: signature against the cached JWKS keys, issuer, expiry with a small skew, and audience, so a token minted for one service is useless at another.
Then, if they want more
Local validation costs well under a millisecond, so latency isn't an argument against it. For calls between services, a service acting for itself uses client credentials to get a token for the target's audience, or we use workload identity from the mesh with mTLS certificates.
When a user's identity must flow, I'd forward the user's token only if it's valid for the next audience, and otherwise use token exchange, so the downstream token names both the user and the acting service. Headers like X-User-Id set by the gateway are no longer trusted, because anyone inside the network can set them.
To avoid sixty different configurations, the platform team ships a starter with the security chain, the outgoing-call interceptors, the standard error format and metrics, so teams add one dependency. Rollout is the risky part, so the starter has a monitoring mode that validates and logs failures by caller but lets traffic through.
After a few weeks of fixing unknown callers, each service switches to enforcing in waves, with a property to roll back and dashboards on 401 and 403 rates.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Security reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Today only the API gateway checks tokens, and internal services trust any request that...": https://scrivio-interview-library.netlify.app/spring-boot/security-architecture/69132cdd94/