In this lesson · topic 2 of 7
Topic 2
Keys and the dedup table
4 min read
The key
The client makes one unique value for each logical operation, such as a random id, and sends it with the request. It sends the same value on every retry. The value names the operation. It must not change from one attempt to the next.
The dedup table
The service keeps a table of keys it has seen, and the result of each. When a request arrives, the service looks up its key. If the key is there, it returns the stored result and does nothing else. If not, it runs the operation and stores the key and the result.
The key and the operation’s effect must commit in one transaction. If they did not, a crash between them would leave an effect with no key, and the retry would run again. Many services make the key a column with a unique constraint, so two requests with one key cannot both insert it.
In the lab with keys on and a lifetime of 600 ticks, the service absorbed 131 retriesmeasured and created 0 duplicate ordersmeasured. Without keys it created 133measured.
What the key does not do
It does not make the operation itself idempotent. It makes the service refuse to run the operation twice. Keys also do nothing for a request whose body changed. The same key with a different body is a bug in the client. A careful service stores a hash of the body and rejects the mismatch.