Try
↑ ↓ move↵ openesc close
In this lesson · topic 4 of 7
  1. 1. The retry that charges twice
  2. 2. Keys and the dedup table
  3. 3. Retry, crash and publish
  4. 4. Keys that expire
  5. 5. Two writes and a crash between them
  6. 6. Publishing twice on purpose
  7. 7. Keys, the outbox and repeats

Topic 4

Keys that expire

5 min read

Forgetting

Every request leaves a key, and the table grows with the traffic. The service must delete old keys. In the lab, a 600 tick lifetime kept 800 keysmeasured at the end of the run. A 30 tick lifetime kept 60 keysmeasured. A smaller table is cheaper to store and to look up.

The price is that a retry that comes after the key is gone looks new. With keys on and a lifetime of 30 ticks, the lab created 109 duplicate ordersmeasured, compared with 0measured at 600 ticks. Retries in the lab come up to 120 ticks later, so a short lifetime misses many of them.

Choosing a lifetime

The lifetime must exceed the longest time a client may retry one operation, plus the time a request can wait in a queue. Look at the client. A mobile app that retries when it comes back online may retry hours later. A server with a three attempt backoff loop retries within a minute.

There is a second reason to keep keys long. A request in flight can finish after its key would have expired. Count the lifetime from the end of the first request, not its start.

Predict first

You cut the idempotency key lifetime to save space. What can go wrong?

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms