Quick revision
The short answer
Server sessions in a shared store can be deleted in seconds, which logs those users out at once. JWTs are self-contained and stay valid until they expire, so within five minutes we either rotate the signing key, which invalidates every token, or push a not-before time that the gateway and services enforce, and we revoke refresh tokens at the identity provider. Afterwards we shorten access token lifetimes, add a revocation check at the gateway, and turn the procedure into a practised runbook.
What to remember
In this answer, we saw that server sessions in a shared store can be deleted at once, while self-contained JWTs stay valid until expiry unless something checks them. For the five-minute target we revoke refresh tokens and either rotate the signing key or enforce a not-before time at the gateway. Afterwards we shorten access token lifetimes, add a gateway revocation check, and turn the response into a practised runbook.
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.
Server sessions in a shared store can be deleted in seconds, which logs those users out at once. JWTs are self-contained and stay valid until they expire, so within five minutes we either rotate the signing key, which invalidates every token, or push a not-before time that the gateway and services enforce, and we revoke refresh tokens at the identity provider. Afterwards we shorten access token lifetimes, add a revocation check at the gateway, and turn the procedure into a practised runbook.
Why this question is asked
Mass logout is one of those capabilities nobody builds until the day it is needed, and then it is needed within minutes. A platform with 40 services and two kinds of session state makes it hard, because each kind dies in a different way. Interviewers ask this scenario to see whether we understand what actually keeps a user logged in, and whether we can act under pressure and then fix the design. In this answer, we will recap the two models, kill the server sessions, deal with the JWTs in the short term, look at the trade-offs, and then change the platform so the next incident is routine.
1A Quick Recap: What Keeps Each User Logged In
With server sessions, the browser holds only a random id, and the real login state lives on the server. If the sessions are in a shared store such as Redis, removing the data ends the login everywhere on the next request.
A JWT (JSON Web Token) is different. The token itself says who the user is and when it expires, and it is signed by the identity provider. A service checks the signature with the provider's public key and the expiry time, and it does not ask anyone whether the token is still wanted. That is the point of JWTs: no lookup on every request. It is also why they are hard to revoke. A token issued at 10:00 with a one-hour lifetime is valid until 11:00, whatever we do on the server, unless the services check something extra.
Most platforms also issue refresh tokens: long-lived tokens that a client exchanges at the identity provider for new access tokens. These are stored by the provider and can be revoked there.
2Delete the Server Sessions
For services that use Spring Session with Redis or JDBC, we delete the sessions directly. Every user of those services is logged out on their next request. If services keep sessions in memory instead, a restart of all their instances has the same effect, at the cost of a brief disruption.
Notice that we scan with a pattern rather than flush the whole database, because the same Redis may hold caches or other data that we should not destroy in the middle of an incident.
3Make the JWTs Stop Working
We have two realistic options within five minutes. The first is to rotate the signing key at the identity provider and remove the old public key from its published key set (the JWKS endpoint). Every existing token was signed with the old key, so services reject them all as soon as they fetch the new key set. This is the bluntest tool: it also logs out machine clients and anything else signed with that key, and it only works within five minutes if services refresh their cached key set quickly. Spring Security's JWT decoder caches the key set for a few minutes by default (check your version), so we must know that number before the incident, not during it.
The second option is a not-before time. We publish a timestamp, say 10:42, and the gateway rejects every token whose iat (issued-at) claim is earlier. Users log in again, receive new tokens issued after 10:42, and carry on. This is gentler, because we can apply it to user tokens only and leave service accounts alone, but it requires that the gateway, or every service, already has a hook to check it.
- Delete sessions in the shared storeRedis or JDBC
- Revoke refresh tokens at the identity providerno silent renewal
- Gateway supports a not-before time?YesPublish the cut-off, reject older tokensNoRotate the signing key, drop the old public key
- Force resets for leaked credentialsbefore users log in again
- Verify with test accountsold session and old token both get 401
5 steps in order. Play them, or step through them one at a time.
In both cases we also revoke all refresh tokens at the identity provider, otherwise clients would quietly obtain fresh access tokens and the logout would undo itself. And if the leak means some passwords are known to the attacker, we force password resets for the affected accounts before the new logins happen, or we simply let the attacker log in again.
4Weighing the Short-Term Options
Key rotation needs no code, but it is all or nothing, it depends on every service's key cache, and if any service has the public key hard-coded it will either keep accepting old tokens or reject the new ones. Waiting for expiry is not an option here: an hour is twelve times the five minutes we were given. The not-before check is the best tool, but only if it exists before the incident. That is the main lesson: this kind of response must be prepared in advance.
| Option | Time to effect | Side effects |
|---|---|---|
| Wait for expiry | up to 60 minutes | misses the five-minute target |
| Rotate signing key | key cache refresh time | logs out every client, including machines |
| Not-before cut-off at gateway | seconds | needs the hook to exist already |
| Revoke refresh tokens | immediate at the provider | always needed alongside the others |
5What We Change Afterwards
First, shorter access tokens. With five-minute access tokens and revocable refresh tokens, revoking refresh tokens at the provider logs everyone out within five minutes with no other tool. The cost is more refresh traffic, which providers handle easily.
Second, a revocation check at the gateway: a not-before time per user and a global one, held in a fast store and checked on every request. Services behind the gateway can then trust it, and services reachable directly use the same validator through a shared Spring Boot starter.
Third, a runbook. We write down the commands, who may run them, and how to verify the result, and we practise it in a test environment every few months. The goal is that the next mass logout takes one engineer five minutes, not a war room for an hour.
6Follow-up questions
Why not check every JWT against a revocation list in each service?
It works, but it gives up the main benefit of JWTs, no lookup per request, and 40 services each implementing it is 40 chances to get it wrong. Checking at the gateway, with a small per-user and global cut-off rather than a list of every token, keeps the cost low and the logic in one place.
Does rotating the key break anything else?
It can. Any token signed with the old key, including tokens for internal service-to-service calls, stops working, and clients that cache keys for a long time may reject new tokens until they refresh. That is why the procedure must be tested before it is needed.
How do you prove the logout worked?
Keep a few test accounts logged in on each type of service before the procedure, then confirm that each old session and each old token gets a 401 after it. Login failure and new-login metrics should also show a sharp spike of fresh logins.
7Conclusion
In this answer, we saw that server sessions in a shared store can be deleted at once, while self-contained JWTs stay valid until expiry unless something checks them. For the five-minute target we revoke refresh tokens and either rotate the signing key or enforce a not-before time at the gateway. Afterwards we shorten access token lifetimes, add a gateway revocation check, and turn the response into a practised runbook.
Open with
I would split it by how each service keeps login state. For server sessions in a shared store, such as Spring Session on Redis or JDBC, I can delete the sessions immediately and every user is out on their next request; in-memory sessions need a restart.
Then, if they want more
JWTs are the hard part, because they are self-contained: the service only checks the signature and expiry, so a token issued an hour ago stays valid unless something extra is checked. In the short term I have two options.
If the gateway or services already support a not-before time, I publish a cut-off and reject tokens with an issued-at before it, which is fast and lets me spare service accounts.
Otherwise I rotate the signing key at the identity provider and remove the old public key, which invalidates every token once services refresh their key cache, so I need to know that cache time.
In both cases I revoke all refresh tokens at the provider, and force password resets for leaked accounts before people log in again, then verify with test accounts.
Afterwards I would shorten access tokens to around five minutes so refresh token revocation alone is enough, add a per-user and global revocation check at the gateway through a shared starter, and write the procedure as a runbook that we practise regularly.
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 "After a credential leak, the security team asks you to log out every user of a...": https://scrivio-interview-library.netlify.app/spring-boot/authentication/43e4fe71e9/