feat: add webhook delivery persistence, idempotency keys, and retry queue#34
Open
brightcli-stack wants to merge 1 commit into
Open
Conversation
…ueue Webhook notifications were delivered fire-and-forget with no persistence, no retry, and no idempotency key. If the consumer endpoint timed out, returned 5xx, or the backend restarted mid-delivery, the event was permanently lost. Changes: - Add eventId (UUID v4) to NotificationPayload for consumer-side deduplication and included it in HMAC signature input - Add webhook_deliveries table to track delivery attempts with status - Persist delivery attempts before and after sending - Add BullMQ webhook-delivery queue with exponential backoff retries (4 attempts: 10s → 20s → 40s → 80s) - Create webhookDeliveryWorker with rate limiting (10/min) - Include X-SentientFi-Event-Id header in webhook requests Fixes grantFoxin#30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #30
What changed
eventId(UUID v4) toNotificationPayload— auto-generated if not providedwebhook_deliveriestable to track every delivery attempt with status, attempt count, and timestampsWebhookProvider.send()now persists delivery state before and after sendingwebhook-deliveryqueue with exponential backoff retries (4 attempts: 10s → 20s → 40s → 80s)webhookDeliveryWorkerwith rate limiting (10 deliveries/min) and concurrency of 3X-SentientFi-Event-Idheader in webhook requests for consumer-side deduplicationeventId— consumers can use it as an idempotency key005_add_webhook_deliveries(up + down)Why
Webhook notifications were delivered fire-and-forget with no persistence. If the consumer endpoint timed out, returned 5xx, or the backend restarted mid-delivery, the event was permanently lost. There was also no idempotency key, so consumers couldn't distinguish a legitimate retry from a duplicate.
How to test
pending→failedinwebhook_deliveriesX-SentientFi-Event-Idheader is present on webhook requestseventIdis consistent across retries for the same event