urBackend icon indicating copy to clipboard operation
urBackend copied to clipboard

[FEATURE] Add webhook retry mechanism with exponential backoff for failed webhook deliveries

Open Abhushan187 opened this issue 5 months ago • 5 comments

Problem

When a webhook endpoint is temporarily down or returns a non-2xx response, urBackend currently does not retry the delivery. This causes data loss for users relying on webhooks for real-time synchronization (e.g., syncing user signups to CRM, triggering CI pipelines on data changes). A single transient failure permanently drops the event.


Proposed Improvement

Implement an automatic retry mechanism with exponential backoff for failed webhook deliveries. The system should:

  • Retry failed webhooks up to 5 times with delays: 1s, 2s, 4s, 8s, 16s
  • Store retry state in Redis (attempt count, next retry timestamp)
  • Use BullMQ to schedule retry jobs asynchronously
  • Mark webhooks as "failed permanently" after max retries and notify the project owner via email
  • Expose retry status in the dashboard (pending / retrying / failed / delivered)
  • Respect a Retry-After header if the endpoint returns 429

Expected Impact

  • Better reliability for webhook-dependent integrations
  • Reduced data loss from transient network failures
  • Improved user trust in urBackend's event delivery guarantees
  • Better long-term scalability with BullMQ-based job scheduling

Possible Implementation

  • Add webhookRetryQueue in apps/public-api/services/ using BullMQ
  • Extend WebhookLog schema with retryCount, maxRetries, nextRetryAt, finalStatus
  • Add processWebhookRetry worker that re-attempts delivery with exponential backoff
  • Add POST /api/webhooks/{id}/retry manual retry endpoint for dashboard
  • Update dashboard UI to show retry timeline and status badges
  • Write tests for retry logic, backoff timing, and max-retry exhaustion

I'm GSSoC'26 contributor, Please assign this task to me!

Abhushan187 avatar Jun 06 '26 13:06 Abhushan187

/assign

Abhushan187 avatar Jun 07 '26 06:06 Abhushan187

/assign

SHRUTIDHEPE avatar Jun 24 '26 13:06 SHRUTIDHEPE

I think we alredy have exponential retry login on webhooks? @coderabbitai

yash-pouranik avatar Jul 20 '26 09:07 yash-pouranik

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '=== Issue `#276` ==='
gh issue view 276 --repo geturbackend/urBackend --json number,title,body,state,comments \
  --jq '{number,title,state,body,comments:[.comments[]|{author:.author.login,body:.body}]}'

echo
echo '=== Candidate webhook/retry files ==='
fd -HI -t f . | rg -i '(^|/)(webhook|retry|queue|job|delivery|notification)[^/]*\.(ts|tsx|js|jsx|py|go|java|rb|php)$' || true

echo
echo '=== Webhook/retry references (source-like files, excluding dependencies/build output) ==='
rg -n -i -C 4 \
  -g '*.{ts,tsx,js,jsx,py,go,java,rb,php}' \
  -g '!node_modules/**' -g '!dist/**' -g '!build/**' \
  '(exponential|backoff|retry|webhook|webhook.*deliver|deliver.*webhook)' \
  . || true

Length of output: 201012


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '=== Issue `#276` (title and body) ==='
gh api repos/geturbackend/urBackend/issues/276 \
  --jq '{number, title, state, body, html_url}'

echo
echo '=== Webhook retry implementation ==='
sed -n '1,330p' packages/common/src/queues/webhookQueue.js

echo
echo '=== Webhook retry tests ==='
rg -n -i -C 3 \
  -g '*.{test,spec}.{js,ts,jsx,tsx}' \
  -g '!node_modules/**' -g '!dist/**' -g '!build/**' \
  '(RETRY_DELAYS|MAX_ATTEMPTS|nextRetryAt|retrying|permanently failed|webhook.*attempt)' \
  packages apps || true

Length of output: 11964


@yash-pouranik, yes—the core exponential webhook retry mechanism already exists in packages/common/src/queues/webhookQueue.js.

It uses BullMQ, persists delivery attempts/status in WebhookDelivery, and retries transient failures on this schedule:

  • 1 minute
  • 5 minutes
  • 15 minutes
  • 1 hour
  • 4 hours

However, #276 is only partially covered:

  • HTTP 429 is currently treated as a non-retryable 4xx response, so Retry-After is not honored.
  • No project-owner email notification is sent after terminal failure.
  • The issue proposes a different backoff schedule (1s → 16s).
  • No targeted retry tests were found.
  • There is an off-by-one boundary: attemptNumber <= MAX_ATTEMPTS causes a sixth delivery attempt after the fifth failure.

I’d recommend closing or re-scoping #276 to the missing behavior rather than implementing a second retry system.

coderabbitai[bot] avatar Jul 20 '26 09:07 coderabbitai[bot]

invalid issue @Abhushan187

yash-pouranik avatar Jul 20 '26 09:07 yash-pouranik