VINOTH S

Architecting high-performance digital environments with intentional asymmetry and technical precision.

© 2024 Digital Architect.

Built with Intentional Asymmetry.

VINOTH S

Architecting high-performance digital environments with intentional asymmetry and technical precision.

© 2024 Digital Architect.

Built with Intentional Asymmetry.

Bulletproof Razorpay Webhooks
Payment Systems 6 min read

Bulletproof Razorpay Webhooks

Building idempotent payment webhook handlers that survive network retries, race conditions, and duplicate delivery with MongoDB change streams.

Library
Bulletproof Razorpay Webhooks
01

The Problem with Webhooks

Razorpay, like all payment providers, guarantees 'at-least-once' delivery for webhooks. This means the same payment.captured event can arrive multiple times. Without proper handling, this leads to duplicate order fulfillment — a critical business bug.

02

Idempotency via MongoDB

The solution was to use the Razorpay payment ID as an idempotency key. Before processing any webhook, the handler checks MongoDB for an existing order with that payment ID.

Implementation
// Idempotent handler
const existing = await Order.findOne({ razorpayPaymentId: paymentId });
if (existing) {
  return res.status(200).json({ status: 'already_processed' });
}

Verified Outcomes

Zero duplicate orders in production across 1,500+ webhook events

All webhook events processed within 500ms average

Webhook handler handles bursts of 50 concurrent retries gracefully

Architect Info

Vinoth S

Full Stack Developer & Digital Architect specializing in scalable systems and premium user experiences.

Collaborate

Related Deep Dives

Scaling to 10x Traffic with Redis

Scaling to 10x Traffic with Redis

Next.js Performance Patterns for E-commerce

Next.js Performance Patterns for E-commerce

VINOTH S

Architecting high-performance digital environments with intentional asymmetry and technical precision.

© 2024 Digital Architect.

Built with Intentional Asymmetry.