Open
Conversation
|
@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! 🚀 |
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.
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 forWebhookPayloadandDLQEntry.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
setTimeoutwith 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 Output Snippet:
📖 Step-by-Step Verification (For Reviewers)
Follow these steps to verify the implementation locally:
Environment Setup:
Ensure you are on the branch
feature/backend-16-webhook-retry-and-dlq-strategy.Run
npm installto ensure all dependencies (likeaxios) are present.Run Unit Tests:
Execute:
npm test src/services/webhook.service.test.ts.Verify: All tests pass, specifically the "Exponential Backoff" timing test.
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.Check Documentation:
Open
docs/backend/webhooks.mdto 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)