Chris Butcher, Python automation

Webhook receiver with dedupe and sync log

The problem

A webhook from one tool must update another tool exactly once. Retries and duplicate deliveries are normal, and without dedupe they become duplicate records.

The artefact

A FastAPI app that accepts POST /webhook with an event ID and a payload, processes each event ID once, and writes a sync log row per event in SQLite. Each row carries a status (pending, synced, or failed), an attempt count, and the last error. The artefact README and source are copied under files on this page.

Input and output sample

Input:

POST /webhook
{"event_id": "evt-1", "payload": {"name": "Sam"}}

Output, first delivery and repeat delivery:

{"event_id": "evt-1", "status": "synced", "attempts": 1}
{"event_id": "evt-1", "status": "duplicate", "attempts": 1}

A payload with "fail": true returns HTTP 502 and its log row shows status failed with attempts 1. Posting the same event again without the fail flag retries and lands at synced with attempts 2. GET /sync-log shows every row.

What can break

The fix or design choice

Dedupe by event ID in SQLite: a repeat delivery of a synced event returns a duplicate result without reprocessing, proven by a counting processor in the tests. A repeat delivery of a failed event retries the downstream step and increments the attempt count. The downstream step is a stub that fails only on the fail flag, so a real API call swaps in without changing dedupe, retry state, or log behavior.

Verification log

Verified 2026-11-19

Files

Price shape

Middleware from $500 fixed. The first deliverable is the receiver with dedupe, the sync log, and a written acceptance check against your two tools.

Start here

Email the sending tool, the receiving tool, and one sample payload. I reply with the fixed quote and the first deliverable plan.