Quick revision
The short answer
We run both token types side by side: every service gets a resolver that recognises a token's format or issuer and sends it to the right validator, with one shared claims mapping so both tokens produce the same principal and roles. Then we move clients to the new provider in waves, starting with internal callers, measure how much traffic still uses old tokens per service, and remove the old path on a fixed date after testing key rotation and provider outages.
What to remember
In this answer, we planned the migration so that nothing breaks. Every service first accepts both formats through an AuthenticationManagerResolver, with one claims mapping in the shared starter so both tokens become the same principal and roles. Callers then move in waves from internal services to partners, each with a rollback. The share of old tokens per service tells us when to remove the legacy path by a published date, and key rotation and provider outages are tested before the old system is switched off.
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.
We run both token types side by side: every service gets a resolver that recognises a token's format or issuer and sends it to the right validator, with one shared claims mapping so both tokens produce the same principal and roles. Then we move clients to the new provider in waves, starting with internal callers, measure how much traffic still uses old tokens per service, and remove the old path on a fixed date after testing key rotation and provider outages.
Why this question is asked
A token migration touches every request of every service, so a mistake does not break one feature; it locks users out of everything. With 50 services owned by different teams, we also cannot change them all on one night. Interviewers ask this to see whether we can plan a change that is reversible at every step and measurable from start to finish. In this answer, we will set up dual acceptance, standardise the claims mapping in a shared starter, plan the waves, decide when the old path can go, and test the failure cases before the cutover.
1Why a Big-Bang Switch Fails
Every request carries a token issued by somebody, a browser login, a mobile app, a batch job, a partner. If we switch all 50 services to accept only new JWTs on one date, every caller must switch on the same date too, and any caller we forgot fails instantly. There is no rollback that does not also roll back the callers.
So the plan rests on one idea: services learn to accept both formats first, and only after that do callers move. Accepting is cheap and safe; issuing is where the risk is. When every service accepts both, we can move callers one at a time and move them back if something breaks.
2Accept Both Token Formats
Spring Security lets a resource server choose its AuthenticationManager per request through an AuthenticationManagerResolver. We write one that looks at the bearer token: a JWT has three dot-separated parts and an iss from the new provider, while the legacy token has its own shape. Each kind goes to its own validation.
Notice that the choice is only routing. Each branch still validates fully: the JWT branch checks signature, issuer, audience and expiry, and the legacy branch does whatever the old system did. If the token looks like neither, it is rejected. We also count every request by branch, because that number drives the rest of the plan.
3One Claims Mapping in the Platform Starter
The two formats name things differently. The old token might carry user_id and a comma-separated role string, while the new provider uses sub and a roles array. If each team writes its own mapping, 50 services will interpret roles in 50 slightly different ways, and a user will have admin rights in one service and not in another.
So we put the mapping into the shared Spring Boot starter that every service already uses. It turns both formats into the same principal: the same user id, the same tenant id and the same Spring authorities such as ROLE_ADMIN. Services keep their @PreAuthorize rules unchanged and never see which format arrived. Because the mapping lives in one place, we test it once with sample tokens of both kinds, and a fix reaches every service with a version bump.
- Callersbrowsers, apps, batch jobs, partners; move in waves
- Token resolverroutes each token to the new or the legacy validator
- Validatorsnew JWT decoder and the legacy check, both complete
- Shared claims mappingone principal, tenant and authorities for both
- Service codeunchanged
@PreAuthorizerules
5 layers, from the top down. Step through them one at a time.
Only the starter knows two formats exist; service code sees one principal.
4Move Callers in Waves
Once all services run the new starter version, we start moving callers. The first wave is internal service-to-service callers using client credentials, because we own both ends, the traffic is predictable, and a failure is visible only to us. The second wave is our own front ends and mobile apps, which need the new login flow and a release cycle. The last wave is partners and external integrators, who need notice periods and test environments.
Each wave has an owner, a date and a rollback: the caller can switch back to the old token because services still accept it. We watch the error rate and the latency per service during each wave, and we do not start the next wave until the previous one has been stable for an agreed time, for example a week.
5Measure and Set a Removal Date
Dual running is a cost, so it must end. The counter from step 1 gives us, per service, the share of requests still using old tokens. When a service sees zero old tokens for, say, 30 days, its legacy branch can be switched off. We publish a removal date for the whole old system at the start, so teams plan for it, and we use the per-service numbers to chase the last callers by name rather than by guesswork.
6Test Failure Cases Before the Cutover
The new provider becomes critical, so we test what happens when it misbehaves before we rely on it. We rotate its signing key in a staging environment and confirm that every service picks up the new key without errors. We block access to the provider and confirm that services keep validating tokens with cached keys while issuing new tokens fails cleanly. We also run a load test of the token endpoint at peak login traffic. Each of these is cheaper to discover in staging than at the moment the old system is turned off.
7Follow-up questions
Why start with internal callers rather than the browser app?
Because we control both sides, the traffic is steady, and a failure affects only our own systems. That makes the first wave a safe test of the provider, the claims mapping and the monitoring before any customer is involved.
What if the old tokens cannot be told apart from the new JWTs?
Then we route by issuer instead of by shape: we parse the token as a JWT without trusting it, read iss, and choose the validator for that issuer from a fixed list. If the legacy tokens are opaque strings, a simple check for the three-part JWT shape is enough.
How do we stop a team from deploying an old starter version late in the migration?
We make the starter version a release check in the build pipeline, and we use the per-service metrics: a service that still has no new-token branch shows up as rejecting traffic from migrated callers in staging, before production.
8Conclusion
In this answer, we planned the migration so that nothing breaks. Every service first accepts both formats through an AuthenticationManagerResolver, with one claims mapping in the shared starter so both tokens become the same principal and roles. Callers then move in waves from internal services to partners, each with a rollback. The share of old tokens per service tells us when to remove the legacy path by a published date, and key rotation and provider outages are tested before the old system is switched off.
Open with
I would separate accepting tokens from issuing them. First, every service learns to accept both formats: in our shared Spring Boot starter I add an AuthenticationManagerResolver that routes a request to the new JWT decoder or to the legacy validation, based on the token's shape or its issuer, and each branch validates fully.
Then, if they want more
In the same starter I put one claims mapping, so both formats produce the same user id, tenant and authorities, and service code with its @PreAuthorize rules does not change.
Once all 50 services run that version, I move callers in waves: internal service-to-service clients first, because we own both ends, then our own web and mobile apps, and partners last with notice. Each wave can roll back because services still accept old tokens.
The resolver counts requests per branch, so for every service I can see the share of old tokens, and when a service shows zero for about a month I turn off its legacy path. I publish a removal date at the start so the dual running ends.
Before relying on the new provider, I test key rotation, a provider outage and peak login load in staging.
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
- RFC 6749, The OAuth 2.0 Authorization Framework, Spring Security reference, OAuth2
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 "Your company is moving 50 services from a legacy token format to OAuth2 JWT access...": https://scrivio-interview-library.netlify.app/spring-boot/oauth2-and-oidc/d7cdd53eb5/