WEBHOOK INTEGRATION

Exactly-once delivery, even when the sender retries

A working Python receiver for the shape most integrations need: an inbound event must create-or-update a record in a second system, once, no matter how many times the sender retries it or when the process dies.

A reference implementation, not a sketch — 213 lines, syntax-checked.

1Verify before you parse

The HMAC runs over the raw request body. Decode the JSON first and you are verifying a re-serialised object, not the bytes the sender signed — a check that passes on payloads nobody ever signed. Stale timestamps are rejected for the same reason: a captured request replayed tomorrow should not authenticate.

expected = hmac.new(SECRET, f"{timestamp}.".encode() + raw, sha256).hexdigest()
return hmac.compare_digest(expected, signature)   # constant time

2Idempotency keyed on the sender's event id

Not your own request id. Not a hash of the body. Senders retry the same event id, so the claim row collapses those retries into one downstream effect. A body hash breaks the moment the sender re-serialises with different key order.

3Claim → call → commit

The claim row is written before the outbound call, not after. Crash between claim and commit: the retry re-reads the claim and reconciles. Crash after the call but before commit: same path, and no double-create. This is the only ordering that survives a process kill mid-request — write-after-call loses the record entirely.

44xx does not retry, 5xx does

A target rejecting a payload rejects it identically on attempt two. Returning 200 after recording the failure stops the retry storm and lets an alert fire once. Returning 503 on a genuine transient failure lets the sender retry safely — because of point 3.

What ships with the milestone

Where this generalises

The claim/finish skeleton stays for every later event. Only the field map and the target call change. Adding order.refunded is a new map plus a new call, not a new service — which is why the mapping lives in one isolated function on purpose.

Need this wired into your system?

$200 fixed for the first milestone, 5 days from having the payload example and API docs. Python or Node — I match your existing stack rather than adding a second runtime.

Order on Freelancer →