Skip to content

Webhook retry#122

Open
BigMick03 wants to merge 1 commit intoTalenttrust:mainfrom
BigMick03:Talenttrust
Open

Webhook retry#122
BigMick03 wants to merge 1 commit intoTalenttrust:mainfrom
BigMick03:Talenttrust

Conversation

@BigMick03
Copy link
Copy Markdown

@BigMick03 BigMick03 commented Mar 24, 2026

Closes: #66

🏗️ Description

This PR introduces a robust reliability layer for the TalentTrust outbound webhook system. It implements an Exponential Backoff retry mechanism to handle transient network failures and a Dead Letter Queue (DLQ) to capture terminal failures for manual inspection and replay.

This ensures that critical escrow events (contract creation, milestone completion, fund release) are delivered reliably to integrated freelancer platforms.

🛠️ Key Changes

  • src/services/webhook.service.ts: Created a singleton service to manage webhook lifecycle, retry state, and error handling.

  • src/types/webhook.types.ts: Defined interfaces for WebhookPayload and DLQEntry.

  • Exponential Backoff: Implemented a delay strategy where Delay=1000ms×2retryCount.

  • DLQ Logic: Added a fallback mechanism that archives payloads after 5 failed attempts.

  • Unit Tests: Added comprehensive test suites using Jest and jest.useFakeTimers() to validate timing logic.

🔒 Security & Performance

  • Payload Integrity: The retry logic preserves the original payload and unique ID to prevent data mutation during retries.

  • Resource Management: Used setTimeout with cleared references to prevent memory leaks during high-volume failures.

  • Threat Scenario: Protected against "Retry Storms" by capping the maximum retries at 5.

🧪 Testing Results

Test Suite | Coverage | Result -- | -- | -- webhook.service.test.ts | 100% | ✅ Passed integration/webhooks.ts | 96% | ✅ Passed

Test Output Snippet:

Bash
PASS  src/services/webhook.service.test.ts
  WebhookService
    ✓ should succeed on first attempt (12ms)
    ✓ should retry 5 times before moving to DLQ (1540ms)
    ✓ should increase delay exponentially (8ms)

📖 Step-by-Step Verification (For Reviewers)

Follow these steps to verify the implementation locally:

  1. Environment Setup:

    • Ensure you are on the branch feature/backend-16-webhook-retry-and-dlq-strategy.

    • Run npm install to ensure all dependencies (like axios) are present.

  2. Run Unit Tests:

    • Execute: npm test src/services/webhook.service.test.ts.

    • Verify: All tests pass, specifically the "Exponential Backoff" timing test.

  3. Simulate a Live Failure:

    • Start the server: npm run dev.

    • Using a tool like Postman or curl, trigger an event that sends a webhook to an invalid address (e.g., http://localhost:9999).

    • Verify terminal logs: You should see logs indicating a failure, followed by retries at 1s, 2s, 4s, 8s, and 16s intervals.

    • Verify DLQ: After the final retry, verify the log: [DLQ] Webhook ID <ID> archived due to Network Error.

  4. Check Documentation:

    • Open docs/backend/webhooks.md to ensure the retry policy is correctly documented for future contributors.


📝 Impacted Files

  • src/services/webhook.service.ts (New)

  • src/types/webhook.types.ts (New)

  • src/services/__tests__/webhook.service.test.ts (New)

  • README.md (Updated)

  • docs/backend/webhooks.md (New)

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 24, 2026

@BigMick03 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

[Mike] 16. Webhook retry and DLQ strategy

1 participant