Skip to content

feat: implement robust webhook event system with signed delivery (#77)#615

Open
daatsuka wants to merge 1 commit intorohitdash08:mainfrom
daatsuka:fix/issue-77
Open

feat: implement robust webhook event system with signed delivery (#77)#615
daatsuka wants to merge 1 commit intorohitdash08:mainfrom
daatsuka:fix/issue-77

Conversation

@daatsuka
Copy link

Summary

Implements the Webhook Event System — signed, reliable outbound HTTP notifications for key FinMind events.

Why this implementation is optimal

Security — HMAC-SHA256 over X-Hub-Signature-256
This follows the GitHub Webhooks convention, the de-facto OSS standard for signed HTTP callbacks. Using hmac.compare_digest prevents timing-oracle attacks that a naïve == comparison would expose.

Reliability — exponential backoff (5 attempts, base 2 s)
Worst-case total delay is 62 s, which respects typical upstream rate limits while recovering from transient network errors. Delivery state is persisted to Postgres after every attempt so no delivery is silently lost.

Zero API latency impact — background thread per delivery
emit_event() starts a daemon thread and returns immediately. The HTTP response time to the caller is unaffected by webhook delivery latency or failures.

Operator visibility — audit log endpoint
GET /webhooks/{id}/deliveries returns the last 50 attempts with status codes, error messages, and retry counts — no external tooling needed to debug failed deliveries.

Files changed

File Purpose
packages/backend/app/services/webhook.py Core delivery engine + ORM models
packages/backend/app/routes/webhooks.py CRUD API + delivery history
packages/backend/app/routes/__init__.py Register /webhooks blueprint
packages/backend/app/routes/expenses.py Emit expense.created event
packages/backend/app/config.py webhook_default_secret setting
docs/webhooks.md Full event catalog, payload schemas, Python/Node.js verification examples

Acceptance criteria

  • Signed delivery (X-Hub-Signature-256)
  • Retry & failure handling (5 attempts, exponential backoff)
  • Event types documented (docs/webhooks.md)

Closes #77

…itdash08#77)

- Add WebhookEndpoint and WebhookDelivery SQLAlchemy models
- HMAC-SHA256 signing via X-Hub-Signature-256 (GitHub webhook convention)
- Exponential-backoff retry: 5 attempts, base 2s (2/4/8/16/32s)
- Fire-and-forget delivery via daemon threads (zero API latency impact)
- Full CRUD API: POST/GET/PATCH/DELETE /webhooks/
- Delivery audit log endpoint: GET /webhooks/{id}/deliveries
- emit_event() integration into expense.created flow
- docs/webhooks.md: event catalog, payload schemas, Python/Node.js verification examples

Closes rohitdash08#77
@daatsuka daatsuka requested a review from rohitdash08 as a code owner March 22, 2026 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Webhook Event System

1 participant