What happens during a rotation
- A token arrives signed under a key the middleware hasn’t seen (a new key id).
- The middleware looks it up in its cached set of MudraID keys — not found.
- It fetches the latest keys from MudraID. Under load, it does this once, not once per request.
- It finds the new key, verifies the token, and serves the request.
The cache, briefly
The middleware caches MudraID’s public keys and reuses them so verification stays local and fast. The reactive refresh on an unknown key is what makes rotation seamless — you don’t wait for a cache timer to notice the new key.If MudraID’s keys are briefly unreachable
If the middleware needs to fetch keys and can’t reach MudraID, the affected requests return500 JWKS_UNAVAILABLE and a warning is logged. The existing cache is not thrown away on a failed fetch, so a brief network blip doesn’t invalidate keys you already hold — only requests that genuinely need a not-yet-cached key are affected.
What to watch (optional)
- A spike in
JWKS_UNAVAILABLEmeans your network path to MudraID is having trouble — not that anything is misconfigured. - A brief blip of
INVALID_TOKENright at a rotation is normal and self-corrects as the refresh lands. A sustained one is worth a look.

