All Essays
May 30, 20269 min readBy Bright Bediako

Defensive Webhooks: Handling Intermittent Mobile Money Callbacks Cleanly

#Node.js#Fintech#TypeScript#Backend
Defensive Webhooks: Handling Intermittent Mobile Money Callbacks Cleanly

Every fintech developer in Africa has experienced the dreaded 3:00 AM incident: a payment gateway retries a transaction callback 14 times because their timeout threshold was 2 seconds, while your server took 2.1 seconds.

Without strict defensive webhook handling, your customer receives 14 credit alerts or your warehouse dispatches duplicate inventory.

Step 1: Never perform heavy business logic inside the initial webhook HTTP request. Validate the cryptographic signature, save the payload into an append-only event store with an idempotency lock, and return an HTTP 200 OK immediately.

Step 2: Process the event asynchronously via a background queue with Redis and BullMQ. Use a database unique constraint on (provider, transaction_id) to make duplicate writes structurally impossible.

Step 3: Monitor your dead-letter queue metrics. When you treat webhooks as hostile, unpredictable streams, your platform sleeps peacefully at night.

Bright Bediako

Founder @ CodeCraft LTD • Lead Organizer @ Barcamp Takoradi

Work Together