Secret rotation

Fetch secrets at run time, then cache them for less than the rotation overlap. With 20 keys and a 4-minute TTL, the secret store gets about 0.1 reads/s instead of 1,500, and each rotation reaches checkout within 4 minutes.

Play a level

See it on the board

The same traffic runs on two boards. The simulator measured both when this page was built.

Board to show
HTTP/2UsersLoad balanc…API serverSecret storeKey-value s…0.5 vCPU · 1 GB
HTTP/2HTTP/2HTTP/2UsersLoad bala…API serverSecret st…Key-value…
Every request reads the secret store: misses a goal
UsersLoad balanc…API serverSecret storeKey-value s…0.5 vCPU · 1 GBLocal cache
HTTP/2HTTP/2UsersLoad bala…API serverSecret st…Key-value…Local cac…
Keys cached for 4 minutes: meets the goals
See it on the board
Measure Goal Every request reads the secret store Keys cached for 4 minutes
Error rate under 0.1% 74.9% Fail 0% Pass
p99 latency under 100 ms 10.1 s Fail 27 ms Pass
Data age under 300 s 0 ms Pass 242 s Pass
Monthly cost 20 USD/mo 21 USD/mo

Key numbers

Default part values from the catalog. The mini board has 20 keys and an overlap of 5 minutes.
NumberValue
Reads per second, one secret store10,000 ops/s
Secret read, median0.1 ms
Default time to live of a local cache60 s
One data key seals many recordsTap or press Space to change how records get a key

Envelope keys · < 1 key service calls/s · limit 10,000/s

How it works

A leaked key must be replaced. The safe place for a key is a secret store, not the code or a config file. The service fetches the key at run time. After a leak you rotate the key: make a new one, and retire the old one.

Rotation has an overlap. The old key keeps working for a short time after the new key exists, so services that still hold the old key do not fail. In the mini board the old key stops 5 minutes after each rotation.

A service that reads the secret store on every request is a problem. In the mini board checkout reads the key on each request, and the store serves 1,000 reads/s. The reads are many more than the store can serve, so errors rise and p99 passes its limit.

Cache the key in each service for a short time. The cache must live for less than the overlap, so that a rotated key is picked up before the old key dies. With a 4-minute time to live, each service asks again every 4 minutes. With 20 keys the store sees about 0.1 reads/s instead of 1,500, and every rotation reaches checkout within 4 minutes, before the old key stops.

If the secret store is down, the services keep running on cached keys. That is another gain.

In the levels you set the cache life from the overlap and check errors and freshness.