In this lesson · topic 4 of 7
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