Webhook Processing System
Relevant source files
The following files were used as context for generating this wiki page:
The Webhook Processing System in BankChase provides a robust, secure, and asynchronous framework for handling real-time event notifications from external payment providers and internal banking operations. The system is designed to facilitate immediate updates for critical financial activities, such as fund transfers and balance adjustments, while maintaining strict security through cryptographic verification.
This system serves as a bridge between BankChase and third-party services like Stripe, Paystack, and international payment networks (SWIFT, Wise). It ensures that internal ledgers and user balances remain synchronized with external transaction statuses through a reliable delivery and retry mechanism.
Sources: WEBHOOK_IMPLEMENTATION.md:3-10, PHASE_1_COMPLETION_SUMMARY.md:12-19, MONEY_TRANSFER_START_HERE.md:21-25
Architecture and Data Flow
The architecture follows a non-blocking, event-driven pattern where webhook deliveries are initiated asynchronously to prevent latency in core banking flows. The system categorizes webhooks into management (CRUD), event triggering, and background retry processing.
System Components
| Component | Description |
|---|---|
| Webhook Manager | Handles CRUD operations for webhook configurations and event subscriptions. |
| Signature Verifier | Performs HMAC-SHA256 verification to ensure the integrity and authenticity of incoming payloads. |
| Event Dispatcher | Asynchronously triggers events (e.g., transfer.completed) and manages initial delivery attempts. |
| Retry Worker | A background job that processes failed deliveries using exponential backoff logic. |
Sources: WEBHOOK_IMPLEMENTATION.md:219-234, PROJECT_COMPLETION.md:16-25, lib/webhook-verifier.ts
Webhook Event Life Cycle
The following diagram illustrates the lifecycle of a webhook event from initiation to successful delivery or final failure after retries.
The diagram shows the asynchronous flow of event triggering, persistent logging, and the retry loop for failed deliveries.
Sources: WEBHOOK_IMPLEMENTATION.md:154-175, PHASE_1_COMPLETION_SUMMARY.md:46-60
Security and Verification
Security is a primary pillar of the webhook system, utilizing industry-standard cryptographic methods to prevent unauthorized data manipulation or spoofing.
HMAC-SHA256 Signature Verification
Every webhook delivery includes a X-Webhook-Signature header. The receiver must compute the HMAC-SHA256 hash of the raw request body using a shared secret and compare it to the header value. This ensures that the payload was not tampered with during transit and originated from the BankChase system.
Sources: WEBHOOK_IMPLEMENTATION.md:135-152, lib/webhook-verifier.ts, app/api/webhooks/stripe-events/route.ts
Encryption and Storage
Webhook secrets are never stored in plaintext. They are encrypted using AES-256-GCM before being persisted in the database, with the encryption key managed through secure environment variables.
Sources: WEBHOOK_IMPLEMENTATION.md:153-156, PROJECT_COMPLETION.md:48-52
Database Schema
The system utilizes three primary tables to manage configurations, audit trails, and delivery attempts.
Webhooks and Events Tables
| Table | Field | Type | Description |
|---|---|---|---|
| webhooks | secret | Encrypted String | Shared secret for HMAC signing. |
| webhooks | events | Array | Subscribed event types (e.g., balance.updated). |
| webhook_events | status | Enum | Current state: pending, succeeded, failed, max_retries. |
| webhook_retries | attempt_number | Integer | The current attempt count (1-5). |
| webhook_retries | response_code | Integer | HTTP status code received from the endpoint. |
Sources: WEBHOOK_IMPLEMENTATION.md:14-53, MONEY_TRANSFER_START_HERE.md:45-72
Retry Logic and Reliability
To ensure high availability, the system implements an exponential backoff strategy for failed deliveries. This window extends up to 24 hours to handle temporary receiver downtime.
Backoff Schedule
- Attempt 1: Immediate upon initial failure.
- Attempt 2: 5 minutes.
- Attempt 3: 30 minutes.
- Attempt 4: 2 hours.
- Attempt 5: 24 hours.
After the fifth attempt, the event is marked as failed and no further processing occurs.
Sources: WEBHOOK_IMPLEMENTATION.md:158-166, PHASE_1_COMPLETION_SUMMARY.md:126-128
Sequence of Webhook Delivery
The following sequence diagram represents the interaction between the Internal Banking Engine, the Webhook Service, and the External Client Endpoint.
This diagram highlights the non-blocking nature of the engine and the persistence of delivery status.
Sources: WEBHOOK_IMPLEMENTATION.md:189-204, PHASE_1_COMPLETION_SUMMARY.md:46-60
API Reference
Webhook Management Endpoints
| Endpoint | Method | Description |
|---|---|---|
/api/webhooks | POST | Creates a new webhook configuration. |
/api/webhooks/{id} | PATCH | Updates URL or subscribed event list. |
/api/webhooks/{id}/stats | GET | Returns delivery success rates and response times. |
/api/webhooks/payment-provider | POST | Entry point for external provider callbacks. |
Sources: WEBHOOK_IMPLEMENTATION.md:57-111, PHASE_1_COMPLETION_SUMMARY.md:92-96, MONEY_TRANSFER_START_HERE.md:104-106
Conclusion
The Webhook Processing System is a production-ready module that guarantees ACID-compliant updates through its ledger-integrated architecture. By combining HMAC verification, encrypted storage, and a resilient retry mechanism, it provides the reliability required for high-volume banking operations while ensuring developer extensibility via standard API endpoints and detailed audit logs.
Sources: WEBHOOK_IMPLEMENTATION.md:243-248, PROJECT_COMPLETION.md:124-129, PHASE_1_COMPLETION_SUMMARY.md:173-178