Design a key rotation scheduler

Design the component that rotates signing and encryption keys on a schedule: an explicit key lifecycle state machine, a pure planning function that is trivial to test, publish-before-use and retire-after-last-use windows, a single active rotator through leases and compare-and-set, and destruction only when nothing still needs the key.

● Hard🔒 PROBy ·Design problem·20 min read·Advanced → Staff
key rotationkey lifecycleJWKSstate machinecompare-and-setcrypto-shredding

01Understand the problem

✓What you will learn
  • Model keys with an explicit lifecycle: pending, primary, retired, disabled, destroyed
  • Size the propagation and grace windows from cache lifetimes and token or data lifetimes
  • Separate a pure planner from an executor with leases and compare-and-set
  • Make destruction safe: only after nothing references the key, with a reversible step first
◎Interview radar

What they probe: in what order you publish, switch and remove a signing key so no valid token is ever rejected, what stops two scheduler instances both rotating, how you know an encryption key is no longer needed, and how rotation fails safely. Where candidates slip: signing with a new key before verifiers have fetched it, deleting the old key as soon as the new one is active, a cron job on every replica, irreversible deletion on a timer, and no audit trail.

Rotation limits how long a stolen key is useful and keeps the rotation machinery exercised, so an emergency rotation is routine rather than a first attempt. The danger is availability: rotate carelessly and verifiers reject valid tokens, or data encrypted under a destroyed key becomes unreadable. A rotation scheduler is a small state machine plus timing rules derived from the systems that use the keys.

  1. Keys move through pending -> primary -> retired -> disabled -> destroyed, and nowhere else.
  2. There is at most one primary at any moment.
  3. A new key is published (pending) for at least the propagation window before it becomes primary.
  4. A retired key stays usable for verification or decryption until the grace window has passed and nothing references it.
  5. Disabled is reversible; destroyed is not, and happens only after a further waiting period.
  6. Exactly one scheduler acts at a time, and every transition is audited.
StateSigning keys (JWKS)Encryption keys
pendingIn the JWKS so verifiers can cache it; not used to signKnown to decrypters; not used to encrypt
primarySigns new tokensEncrypts new data
retiredStill in the JWKS until the longest token signed with it has expiredDecrypts old data while a re-encryption job moves it
disabledRemoved from the JWKS; can be restoredDecrypt calls fail and alert; can be restored
destroyedKey material deletedKey material deleted; any data left under it is gone (crypto-shredding)

This is an advanced module

Problems: policy and crypto engines is part of the Pro pass. 4 more sections — the deep dives, the final design, follow-ups and the test — unlock with it.

Already a cyart.io or studio.cyart.io member? Your pass code is in your Studio account.