Scaling a High-Throughput B2B Payment Reconciliation Engine
How CustQ redesigned an enterprise settlement pipeline to process 1.2M+ transactions monthly, eliminating database deadlocks and accelerating payment verification.
The Challenge
The client was operating on a legacy monolithic Ruby on Rails backend backed by a single MySQL database instance. As their B2B merchant volume scaled past 800,000 monthly invoices, month-end billing cycles induced severe database locking. Merchants experienced checkout timeouts, and manual reconciliation backlogs frequently took up to 3 business days to resolve.
Key engineering bottlenecks identified during our Day 1 technical audit included:
- Synchronous ledger insertion blocking API gateway request threads
- Unindexed polymorphic tables causing full-table scans during dispute matching
- Lack of idempotent request handling leading to duplicate webhooks during connection timeouts
Our Solution & Architecture
CustQ’s engineering team engineered a modular, event-driven settlement service designed for horizontal scaling:
- Asynchronous Event Queuing: Implemented Redis-backed BullMQ queues with rate limiting to buffer incoming payment webhooks from multiple bank partners.
- Optimized PostgreSQL Ledger: Designed an immutable double-entry ledger schema using PostgreSQL with partitioned tables by merchant and fiscal quarter.
- Idempotency Layer: Enforced cryptographically hashed transaction keys at the API gateway layer to eliminate duplicate settlements under retried network requests.
- Automated Dead-Letter Queue (DLQ): Automated mismatch alerting to notify compliance engineers only when bank responses deviated from recorded webhook payloads.
The Technical Stack
Measurable Business Impact
Following blue/green deployment with zero downtime, the new settlement engine processed month-end volumes in under 42 minutes compared to the prior 72-hour window. The client successfully onboarded 4 additional regional enterprise retailers without requiring any incremental server provisioning.