Handling Concurrent Peak-Hour UPI Payments Without Order Collisions or Double Credits

Production engineering strategies for high-traffic checkout spikes: unique order ID generation, bounded session windows, atomic SQL locking, and multi-handle gateway failover.

Why Identical Rupee Amounts Cause Collisions on Naive Systems

Consider an esports tournament opening registration at 8:00 PM where 40 players launch checkout for the exact same ₹199 entry pass within 45 seconds. If a custom payment script only scans bank SMS text for 'Credited Rs 199', dozens of concurrent `PENDING` checkouts race against a single transfer notification—leaving orders misaligned or double-credited.

High-concurrency UPI automation solves this through a combination of unique session references, strict post-order creation timestamp guards, database-enforced UTR uniqueness, and non-blocking multi-handle failover.

How UPIGateway.dev & Merchant Backends Eliminate Collisions

Concurrency LayerProduction MechanismProtection Guaranteed
Gateway Session GenerationEmbedded merchant transaction reference (`paytm_txn_ref` / order reference) + immutable `create_date`Links bank notifications cleanly and excludes historical transfers
Atomic UTR RegistryUnique 12-digit Bank UTR verification inside Supabase PostgreSQLPrevents a single bank transfer from closing two separate orders
Underpaid GuardAmount validation inside `/api/check-order-status` (`FLAGGED_UNDERPAID`)Stops altered partial amounts from satisfying full-price orders
Multi-Handle FailoverChecks assigned gateway first, then iterates active non-expired user handlesMaintains checkout throughput if a single merchant session expires

4 Mandatory Engineering Rules for Peak Traffic Workloads

  1. Never reuse `order_id` values across retries: generate globally unique identifiers (`crypto.randomUUID()` or `ORD_${ms}_${hex}`) whenever a customer re-opens checkout.
  2. Bound active checkout sessions to short windows (300 seconds default countdown inside `Checkout.tsx`) and expire stale local pending records.
  3. Create a `UNIQUE (utr)` database constraint on your own fulfilled ledger table so parallel webhook delivery and return-page polling cannot grant balance twice.
  4. Select the plan tier matching your API concurrency quota: `60 req/min` (Growth), `120 req/min` (Business Plus), or `300 req/min` (Enterprise).

Atomic PostgreSQL Schema & Fulfillment Update Pattern

-- Enforce strict double-spend and replay protection in PostgreSQL
CREATE TABLE merchant_payments (
  order_id TEXT PRIMARY KEY,
  user_id BIGINT NOT NULL,
  expected_amount NUMERIC(12, 2) NOT NULL,
  status TEXT NOT NULL DEFAULT 'PENDING' CHECK (status IN ('PENDING', 'SUCCESS', 'FAILED')),
  utr TEXT UNIQUE,
  verified_at TIMESTAMPTZ
);

-- Conditional transition executed after POST /api/check-order-status confirms SUCCESS:
UPDATE merchant_payments
SET status = 'SUCCESS', utr = $2, verified_at = NOW()
WHERE order_id = $1 AND status = 'PENDING' AND expected_amount <= $3
RETURNING order_id, user_id;

Dual Reconciliation: Combining Webhooks With Active Polling

Never depend exclusively on a single notification path during flash sales. UPIGateway.dev dispatches `POST` callbacks (`UPIGateway-Webhook-Dispatcher/2.0`, 8,000ms bounded timeout) while logging attempts into `webhook_logs`. Meanwhile, hosted checkout tabs and your return route (`redirect_url`) query `POST /api/check-order-status`. Pairing conditional database state locks (`WHERE status = 'PENDING'`) with `UNIQUE(utr)` guarantees exactly-once fulfillment regardless of whether webhook or client poll wins the race.

What happens if two buyers scan separate QRs of the same amount at once?

Each session receives a distinct merchant reference (`paytm_txn_ref` / order reference) and strict `create_date` timestamp boundary. Paired with database UTR uniqueness locking and amount validation, verified settlement applies once per unique 12-digit NPCI bank reference.

Related Integration Guides & Developer Resources

Explore more technical articles, code examples, and architecture guides on our official blog. Automate your Indian payment collection at zero percent fees with UPIGateway.dev.

We provide comprehensive developer documentation, ready-to-deploy SDKs for PHP and Node.js, and plug-and-play e-commerce plugins for WordPress and WooCommerce. Build modern payment checkout flows with direct bank settlement and full financial autonomy.

Back to Blog Index | Engineering Reports | View API Documentation | Explore Pricing Plans