Part 3 of 12 · 2 min read
Checkpointing survives a crash; it does not make a side effect happen only once
Think of a printer that keeps the print job in its queue if the power flickers. The page comes out again when power returns, which is good. The exception is when the page had already printed once before the flicker. Then you now have two copies.
In plain words: a side effect is a change in the outside world such as a refund or an email, at-least-once execution means a step may run again after a crash so it can run more than once, and an idempotency key is a unique id sent with a request so the receiver ignores a repeat -- checkpointing alone only gives at-least-once execution, because a crash between doing the effect and saving the checkpoint still repeats that step on resume, so closing the gap needs both at-least-once execution and an idempotent receiver.
A worked example. At a 15% crash rate, the checkpointed graph without idempotency keys produces 0.34 duplicate side effects per run on average -- a crash lands between a refund or email firing and the checkpoint recording it, so resume fires that same step again. Adding an idempotency key to every effect, with no other change, brings that to exactly 0.00 duplicates at every crash rate tested (5%, 15%, 30%) -- and does so without saving a single model call, because the key only suppresses the repeated effect, not the repeated attempt.
The key lines. From code/mini-paradigms/paradigms.py:
# from code/mini-paradigms/paradigms.py
def do(self, step, key=None):
if key is not None and key in self.keys:
return "ignored-duplicate"
if key is not None:
self.keys.add(key)
self.effects.append(step)
return "ok"
Read it as: the duplicate check happens inside World.do itself, on the receiving side. This mirrors the real mechanism exactly. An idempotency key only works because the receiver remembers which keys it has already seen. It does not work because the caller tries any harder not to repeat itself. The caller in this code still happily calls do twice with the same key. The receiver is what makes the second call a no-op.
Side effect, at-least-once execution, idempotency key
A side effect is a change in the outside world (a refund, an email). At-least-once execution means a step may run again after a crash, so it can run more than once. An idempotency key is a unique id sent with a request so that the receiver ignores a repeat; at-least-once plus an idempotent receiver gives an exactly-once effect.
Example: 0.34 duplicates per run falling to exactly 0.00 once every effect call carries a key is the clearest possible demonstration that checkpointing and idempotency solve two different problems -- one makes the run finish, the other makes the refund happen only once.