Handling Uncertainty: Abstain, Ask, or Escalate
Lesson 1 of 4
Bound Repeat Work
Estimated time: 10 minutes
Bound Repeat Work
A request that arrives twice should not do its work twice. The cheapest guard is a key that names the work, so the second arrival is recognised as the same job.
Name the work with a key
Derive the key from the parts that make the request unique, not from the wall clock.
def key(req):
return f"{req.user}:{req.action}:{req.target}"
Keep the first result
Store the result under the key and return it for later arrivals. Release the key when the work is genuinely done.
A missing key costs a duplicate side effect that nobody notices until it compounds.