Skip to main content
← PROBLEMS / SYSTEM-DESIGN
An end-to-end domain learning journey

Design a Multi-Region Session
& Token Revocation Service.

Pair short-lived stateless JWTs (5–15 min TTL) with an in-memory edge revocation filter, an authoritative multi-region session store, and async cross-region push invalidation with bounded retries and DLQ.
Start the journey7 stages· Last modified Nov 22, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

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.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Passkeys, WebAuthn & FIDO2 Passwordless Auth
WebAuthn/FIDO2 replaces passwords with per-site asymmetric keypairs generated inside a user's hardware authenticator, where private keys never leave the device and signatures are cryptographically bound to the exact Relying Party origin.
API Security: OAuth 2.1, JWT & mTLS
Modern API security pairs OAuth 2.0 (for delegated user/client authorization), signed JWTs (for stateless, verifiable claims), and Mutual TLS (mTLS) (for cryptographic workload and high-assurance client identity).
JWT Validation Pitfalls & Hardening (RFC 8725)
Stateless JSON Web Tokens fail catastrophically when verifiers trust header fields (alg, kid, jku), skip audience/issuer checks, or confuse asymmetric public keys with HMAC secrets.
Full walkthrough · 7 stages
01
STAGE 01 · REQUIREMENTS & MATHfoundation

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 ms p99.
  • Write Path: ~1,000–5,000 revocations/sec (logouts, password resets, risk triggers).
Request & State Flow

Read/Write Asymmetry & Revocation Memory Footprint

Client / WorkloadEdge PolicyEnforcerIdP / JWKS / VaultProtected API1. Present signed token / mTLScert2. Verify signature via cachedJWKS3. Forward attenuated identityclaims4. Return scoped resource response
02
STAGE 02 · TOKEN DESIGNfoundation

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.
Component Topology

Short-Lived Access Tokens + User Session Epoch

ClientingressEdge GatewaycomputeJWKS / VaultstorageTarget ServicecontrolBearer / mTLSkey lookupscoped call
Engineering Decision Framework
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.
Decision Exercise · Make the Call

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?

03
STAGE 03 · EDGE HOT PATHintermediate

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:

  1. Verify JWT signature locally with cached JWKS.
  2. Check local in-memory filter (O(1), < 50 µs).
  3. 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

Inbound JWTLocal JWKS VerifyIn-Memory FilterRegional Redis
04
STAGE 04 · WRITE & PROPAGATIONintermediate

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:

  1. Authoritative Write: Update the multi-region DB (or revoke refresh token family) transactionally.
  2. Publish Event: Emit { type: 'REVOKE_JTI' | 'BUMP_EPOCH', id, ttl } to a cross-region replicated stream (e.g., Kafka MirrorMaker / DynamoDB Streams).
  3. Regional Fan-Out: Workers in all 4 regions write to Regional Redis (SETEX with remaining JWT TTL) and push via pub/sub to Edge Gateways.
Design Trade-Off

Authoritative Store, Cross-Region Stream & Push Invalidation

Before · Long-Lived Bearer + Implicit Trust
  • Stolen token works everywhere
  • JWKS rotation triggers 500s
  • Confused-deputy escalation
After · Short-Lived mTLS + Scoped Claims
  • Stale-while-revalidate JWKS
  • Strict alg/aud/iss pinning
  • Least-privilege hop attenuation
05
STAGE 05 · SAFE PROPAGATION CODEintermediate

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, random
Lifecycle & Failure Recovery

Idempotent Regional Invalidation Worker with Bounded Retry & DLQ

check pubkeyRBAC/ABAC matchkid/TTL mismatchUnauthenticatedSignature VerifiedPolicy AllowedExpired / Revoked
06
STAGE 06 · RESILIENCEadvanced

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.
07
STAGE 07 · GOTCHASadvanced

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 SETEX TTLs 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_epoch atomically in Redis Lua.
Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

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?

Recommended Learning Flow