Hacker News new | ask | show | jobs
by jaimehrubiks 1357 days ago
Yes but if each microservice needs to check a cache on each request, then why use jwt at all, you could just save a classic session (with random token) in that cache as well
2 comments

The redis cache with invalidated tokens will be much smaller than storing all sessions.

And you can expire the invalidated keys faster (set the invalidated key expiration to the expiration of the JWT)

Not many people revoke sessions, but a lot of people create sessions. Much more efficient to only store and check revocations. The rest can be stateless.

I don't think that biggest issue with central auth database is its size.
It depends on your scale, but even at small scale, your central auth database is something that needs to be highly available because your whole system is down otherwise.

Obviously the situation is the same when managing a token blacklist if you truly have a hard requirement that sessions be instantly invalidated at a specific point, but there's a good chance you don't. Maybe it's OK to presume signed tokens are still good for some amount of time if your blacklist server is unreachable, or maybe waiting until the JWT expires after 60 minutes is too long, but a one or two minute delay is acceptable. Or maybe you only check the blacklist for high-risk API requests.

It's not ideal. Invalidation is definitely a weakness of JWTs, but there's still a lot of value in baseline statelessness.

Why not let the API Gateway check it?
"Yes but then ... why use jwt at all, you could just save a classic session (with random token) in that cache as well".

JWTs add complexity and have zero benefit. The author never said it can't be made to work, obviously it can. It's just completely pointless in most applications.