Skip to content

feat: Resilient Webhook Ingestion System for Frontend External Triggers - #237

Closed
ACodehunter wants to merge 1 commit into
StellarDevHub:mainfrom
ACodehunter:feature/resilient-webhooks
Closed

feat: Resilient Webhook Ingestion System for Frontend External Triggers#237
ACodehunter wants to merge 1 commit into
StellarDevHub:mainfrom
ACodehunter:feature/resilient-webhooks

Conversation

@ACodehunter

Copy link
Copy Markdown
Contributor

Closes #223

Summary

Builds a highly resilient, decoupled webhook ingestion pipeline that survives database outages by using a Redis-based message queue with a dedicated worker, exponential backoff retries, and a Dead Letter Queue.

Changes

New Files

  • backend/src/routes/webhooks.ts — Fast-ingest endpoint (POST /api/v1/webhooks/ingest). Verifies signature and immediately enqueues; returns 200 OK within milliseconds.
  • backend/src/services/queue.service.ts — Redis list-backed queue: enqueueWebhook, dequeueWebhook, and enqueueDLQ.
  • backend/src/services/webhookWorker.ts — Standalone worker process that consumes the queue, processes business logic, and retries with exponential backoff before moving to DLQ.
  • backend/src/utils/signature.ts — HMAC-SHA256 signature verification using crypto.timingSafeEqual to prevent timing attacks.
  • backend/src/utils/redis.ts — Shared Redis client.

Modified Files

  • backend/src/routes/index.ts — Registered webhook router at /webhooks.
  • backend/.env.example — Added WEBHOOK_SECRET and REDIS_URL.

Implementation Details

Phase 1 — Fast-Ingest Endpoint

POST /api/v1/webhooks/ingest verifies the X-Webhook-Signature header and pushes the payload onto a Redis list immediately, returning 200 { status: 'accepted' } without any business logic.

Phase 2 — Worker Service

webhookWorker.ts runs as a separate process via BLPOP on the Redis queue (blocking pop, zero-overhead). Processes each webhook with the actual business logic.

Phase 3 — Cryptographic Signature Verification

HMAC-SHA256 signature is verified using crypto.timingSafeEqual preventing timing-based spoofing attacks. Unsigned requests are immediately rejected with 401.

Phase 4 — Dead Letter Queue + Exponential Backoff

  • Max 5 retries with delay calculated as 2^attempt * 1000ms.
  • After max retries, payload is moved to webhooks:dlq Redis list for manual inspection and replay.

@ACodehunter

Copy link
Copy Markdown
Contributor Author

Closing — opened from incorrect account. Will be re-opened from the correct account.

@ayomideadeniran

Copy link
Copy Markdown
Contributor

pr under review, if i find any wrong implementation i will notify you.

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.

2 participants