If latency budgets leave no room for synchronous retries, never make synchronous cross-region database calls on every API request; keep the hot read path in edge memory and bound the revocation window with short JWT TTLs + fast push invalidation.
TL;DR30-second simplified summary▾
Edge gateways validate JWT signatures locally and check (jti, user_epoch) against an in-memory revocation filter synced from Regional Redis (< 2 ms p99).
Revocations write to an authoritative multi-region store and stream via async fan-out workers (with bounded retry + DLQ) to all regions within 5 seconds, expiring automatically once the JWT's exp passes.
alg, kid, jku), skip audience/issuer checks, or confuse asymmetric public keys with HMAC secrets.Read/Write Asymmetry & Revocation Memory Footprint.
Why this matters: Size the 2M RPS read path and bounded revocation set so edge memory stays tiny and predictable.
- Read Path: 2M auth checks/sec globally (~500K RPS/region) at
< 2 msp99.
- Write Path: ~1,000–5,000 revocations/sec (logouts, password resets, risk triggers).
Read/Write Asymmetry & Revocation Memory Footprint
Short-Lived Access Tokens + User Session Epoch.
Why this matters: Support both single-session logout (jti) and global 'log out all devices' (epoch) without storing every active token.
Include two compact claims in every 10-minute access JWT:
jti(Token ID): Enables surgical revocation of a single compromised device/session.
ver(User Security Epoch): A monotonically increasing integer per user.
Short-Lived Access Tokens + User Session Epoch
- Problem
- How to implement Design a Multi-Region Session & Token Revocation Service without hitting unbounded tail latency, state divergence, or operational fragility.
- Naive Solution
- Use a single unpartitioned path with unbounded retries and synchronous global coordination.
- Why It Fails
- Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
- Alternatives
- Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
- Engineering Decision
- If latency budgets leave no room for synchronous retries, never make synchronous cross-region database calls on every API request; keep the hot read path in edge memory and bound the revocation window with short JWT TTLs + fast push invalidation.
- Trade-Offs
- Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
When Design a Multi-Region Session & Token Revocation Service experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?
Sub-2 ms Edge Verification via Local Filter + Regional Redis.
Why this matters: Keep 99.9%+ of API requests off the network using in-memory edge filters and fail-closed/fail-open risk tiers.
Each Edge Gateway maintains an in-memory map of (revoked_jti -> exp) and (user_id -> min_valid_epoch) synced via streaming deltas from its regional Redis cluster:
- Verify JWT signature locally with cached JWKS.
- Check local in-memory filter (
O(1),< 50 µs). - If the edge filter is stale (
last_sync_age > 5s), fall back to Regional Redis for high-risk endpoints (payments, password change) while allowing low-risk reads if configured.
Edge Gateway Sub-2 ms Token Verification Path
Authoritative Store, Cross-Region Stream & Push Invalidation.
Why this matters: Propagate revocations globally in under 5 seconds using durable writes + async fan-out + periodic anti-entropy.
When a user revokes a session or resets their password:
- Authoritative Write: Update the multi-region DB (or revoke refresh token family) transactionally.
- Publish Event: Emit
{ type: 'REVOKE_JTI' | 'BUMP_EPOCH', id, ttl }to a cross-region replicated stream (e.g., Kafka MirrorMaker / DynamoDB Streams). - Regional Fan-Out: Workers in all 4 regions write to Regional Redis (
SETEXwith remaining JWT TTL) and push via pub/sub to Edge Gateways.
Authoritative Store, Cross-Region Stream & Push Invalidation
- Stolen token works everywhere
- JWKS rotation triggers 500s
- Confused-deputy escalation
- Stale-while-revalidate JWKS
- Strict alg/aud/iss pinning
- Least-privilege hop attenuation
Idempotent Regional Invalidation Worker with Bounded Retry & DLQ.
Why this matters: Ensure transient regional Redis or network failures never drop revocations or block healthy regions.
Each regional fan-out worker must apply epoch updates monotonically (never overwrite a newer epoch with a stale out-of-order event) and route persistent failures to a DLQ:
import time, randomIdempotent Regional Invalidation Worker with Bounded Retry & DLQ
Handling Cross-Region Partitions & Refresh Token Rotation.
Why this matters: Combine refresh-token reuse detection with fail-closed sensitive endpoints during regional isolation.
Think of Handling Cross-Region Partitions & Refresh Token Rotation as the intuition layer for Design a Multi-Region Session & Token Revocation Service: Combine refresh-token reuse detection with fail-closed sensitive endpoints during regional isolation.
- Refresh Token Reuse Detection: Refresh tokens are always validated against the authoritative store; if a rotated/revoked refresh token is replayed, immediately bump the user's
epoch. - Partition Mode: If a region loses stream connectivity (
sync_lag > 10s), high-risk endpoints (/transfer,/password) fail closed to the authoritative store while non-sensitive reads stay available.
Clock Skew, Out-of-Order Epochs & Cache Stampedes.
Why this matters: Mitigate JWT clock-skew leaks, epoch regressions, and JWKS rotation thundering herds.
- Clock Skew: Add a 30–60s buffer to revocation
SETEXTTLs so a token accepted by a slightly skewed edge clock cannot slip past an expired deny entry.
- Out-of-Order Events: Always compare
new_epoch > current_epochatomically in Redis Lua.
Practice: Make the trade-off yourself.
A user clicks 'Log out of all devices' after an account compromise, and they have 14 active sessions across mobile and web. How can the service revoke all 14 access JWTs in O(1) state?