APEX WEBHOOK RELIABILITY
What this is: Webhook contract: HMAC signatures, dedupe, DLQ, retry windows - what consumers must verify.
How it works
Webhooks carry an HMAC signature over the payload; consumers must verify before acting. Delivery is at-least-once with dedupe on the event id, retries on a schedule, and a dead-letter queue after the window.
Development guide
Code map
apex/webhooks/__init__.pyapex/webhooks/service.py
Public surface
service.py: Webhook delivery on top of the outbox dispatcher.validate_url(url: str)create_subscription(conn, *, merchant_id, url: str, events: list[str] | None = None)sign(secret: str, timestamp: int, body: bytes)verify_signature(secret: str, header: str, body: bytes, *, now: int | None = None)http_transport(url: str, body: bytes, headers: dict)fanout_pending(connect, *, limit: int = 500)make_publisher(connect, transport)publish(event: dict)
HTTP endpoints
GET /v1/webhooks/deliveriesGET /v1/webhooksPATCH /v1/webhooks/{sub_id}POST /v1/webhooks/testPOST /v1/webhooks/{sub_id}/disablePOST /v1/webhooks
Schema owned
0073_checkout_collect_email.sql
Depends on
outbox_events · webhook_deliveries · webhook_subscriptions
Tests
tests/test_webhooks.py
Step-by-step: extending this subsystem
- Schema - add a numbered file in
schema/if new tables are needed; never edit an applied migration. - Service - implement logic in
apex/webhooks/service.pyinside aconn.transaction()block; post financial effects throughapex/ledger/, never direct balance math. - Route - expose it in
apex/api/(or the module's router) with scope checks via the existing auth dependency. - Events - emit outbox events for anything a consumer/webhook needs to observe.
- Test - add cases in
tests/near the files listed above; run.venv/bin/python -m pytest -k webhooks. - Invariants - money stays integer minor units; ledger writes
stay balanced; sandbox stays behind
APEX_ENVgating.
Classification: see below. Inspected against the live codebase in forensic cycle 1.
UPDATED (2026-11-04): IMPLEMENTED - see apex/webhooks/service.py
(subscriptions, HMAC sign/verify with timestamp tolerance, fanout_pending
delivery, dead-letter replay gating - A8-14). Original Phase-1 finding
follows: NOT IMPLEMENTED - no webhook subsystem; payment_events table
provides the event stream source.
See APEX_SYSTEM_INVENTORY.md and APEX_DEFECT_REGISTER.md for the full picture.