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 Layer | Production Mechanism | Protection Guaranteed |
|---|---|---|
| Gateway Session Generation | Embedded merchant transaction reference (`paytm_txn_ref` / order reference) + immutable `create_date` | Links bank notifications cleanly and excludes historical transfers |
| Atomic UTR Registry | Unique 12-digit Bank UTR verification inside Supabase PostgreSQL | Prevents a single bank transfer from closing two separate orders |
| Underpaid Guard | Amount validation inside `/api/check-order-status` (`FLAGGED_UNDERPAID`) | Stops altered partial amounts from satisfying full-price orders |
| Multi-Handle Failover | Checks assigned gateway first, then iterates active non-expired user handles | Maintains checkout throughput if a single merchant session expires |
4 Mandatory Engineering Rules for Peak Traffic Workloads
- Never reuse `order_id` values across retries: generate globally unique identifiers (`crypto.randomUUID()` or `ORD_${ms}_${hex}`) whenever a customer re-opens checkout.
- Bound active checkout sessions to short windows (300 seconds default countdown inside `Checkout.tsx`) and expire stale local pending records.
- Create a `UNIQUE (utr)` database constraint on your own fulfilled ledger table so parallel webhook delivery and return-page polling cannot grant balance twice.
- 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.