The Brief
Idempotent Webhook Processor
You receive webhooks from a payments provider. The provider retries on any non-2xx response (and sometimes on 2xx too — networks lie). Your handler must be idempotent: replaying the same event must not double-charge, double-refund, or duplicate a row.
Provided
- A mock provider that fires 300 events with ~12% retry duplicates.
- A Postgres connection (pg is in scope).
- A failing test suite that asserts: (a) every event processed exactly
once, (b) handler returns 200 within 500ms p95, (c) DB has no
duplicate rows.
Success rubric
1. All tests pass.
2. Handler uses the event id as the idempotency key — not a hash
of the payload (payloads can change on retry).
3. Race-condition safe: 50 concurrent retries of the same event
land exactly one row.
Allowed tools code_run, file_search.