Problem Statement: Killing the Forever Credential
Frames the rotator as a credential-lifecycle control plane, not a refresh endpoint.
Problem statement
Design an API Access Token Rotator: a central service (and client library) that forcibly expires access tokens after a short, policy-defined TTL, issues replacement tokens automatically in the background, invalidates or grace-windows the old credential, and logs every rotation event. The goal is to shrink the blast radius of a leaked credential from “forever” to “minutes”.
The classic failure mode this system attacks is the forever credential: a personal access token minted in 2019, pasted into a CI variable, copied into a laptop dotfile, synced to a backup drive, and still valid today. When that token leaks — via a public repository, a compromised laptop, or an insider — the attacker gets indefinite access. Rotation does not prevent the leak; it caps the value of a leak in time.
Why this is a real system, not a cron job
A naive solution is a scheduled job that revokes tokens older than N days. That breaks production: long-running jobs die mid-stream, mobile users get logged out, and every team builds its own brittle refresh loop. A serious rotator must solve four hard problems at once:
- Continuity during rotation. Old and new tokens must both work during a configurable overlap (grace) window, or every rotation becomes an outage. In-flight requests holding the old token must not 401 mid-flight.
- Deterministic invalidation. After the grace window, the old token must be rejected everywhere — every region, every resource server, every cache layer — within a bounded time. “Eventually invalid” is a vulnerability with a timer.
- Stolen-refresh detection. If a refresh token is rotated on every use, then the second presentation of an already-rotated refresh token is proof of theft (two parties hold the same credential). The system must detect reuse and revoke the whole grant family.
- Rotation at scale without a hot database. Token validation happens on the request path of every API call. If validation requires a round trip to the rotator’s database, the rotator becomes the slowest, most attacked component in the platform.
The three token classes
The design handles three distinct credential classes with different lifecycles:
- Access tokens — short-lived bearer proofs (target TTL 5 minutes) presented to resource servers. Stateless (JWT) where possible so validation is local.
- Refresh tokens — long-lived, single-use, rotated-on-use credentials (target TTL 24 hours) that mint new access tokens. They are the root of the grant family and the target of theft detection.
- Machine credentials — service-account tokens, personal access tokens (PATs), and workload identities with app-level rotation policies (target TTL 1 hour, rotated by the client library or a daemon before expiry).
Why the problem is distinctive
Most auth systems answer “who are you?” The rotator answers a harder question: “are you still allowed to be you, as of this exact second, across every region?” That question forces explicit answers to consistency problems that other systems can fudge: clock skew between validators, cache TTLs that outlive revocation, split-brain rotation schedulers handing out two “current” tokens, and the tension between stateless validation (fast, but hard to revoke) and stateful validation (revocable, but a hot path).
The public record shows this matters operationally. GitHub enforced PAT expiry for newly issued tokens and now pushes fine-grained, expiring tokens; its public security incidents have repeatedly involved leaked long-lived credentials. Stripe’s API keys are deliberately non-expiring by default, which is exactly why Stripe built leak detection and a documented rotation procedure instead. These two strategies — expiry-by-default versus detection-plus-rotation — are the design tension at the heart of this question.
The four architectural planes
- Issuance plane — mints access and refresh tokens, binds them to a grant family, signs with versioned keys.
- Rotation plane — the scheduler and engine that forces rotation before expiry, manages grace windows, bumps token generations.
- Validation plane — how resource servers check tokens fast: local signature verification, generation checks, denylist checks.
- Governance plane — per-app and per-user rotation policies, audit trail, anomaly detection, compliance evidence.
A strong answer keeps these planes separate: the validation plane must keep working when the rotation plane is down, and a policy change in the governance plane must never silently change what the validation plane accepts mid-rotation.
Key Highlights
- •Rotation caps the value of a leaked credential in time; it does not prevent the leak itself.
- •Grace windows make rotation survivable; bounded invalidation makes it safe. Both are mandatory.
- •Refresh-token rotation-on-use turns theft into a detectable event: reuse of a rotated token proves two holders.
- •Validation must stay off the rotator's database hot path or the rotator becomes the platform's choke point.
- •Three token classes — access, refresh, machine — each need their own TTL, rotation trigger, and failure mode.
Section Rescue Kit
Buzzwords to use:
Safe statements:
- "Let me separate the four concerns first: issuance, rotation, validation, and governance — they fail differently."
- "Before choosing databases, I want to pin down what 'invalidated' must mean and how fast it must be true everywhere."