Inspiration
Every single day in India, payment gateways reduce billions of rupees in lost transactions to a single, oversimplified word: FAILED.
In legacy gateway architectures, the system's reaction is stubbornly binary: whether a transaction dropped because SBI’s core banking servers timed out, an honest loyal customer got tripped by an over-sensitive fraud filter, a mutual fund SIP bounced for the third time, or a customer hesitated on a ₹4,000 cart, the gateway does the same thing: it runs a blind 3-attempt retry loop or blasts generic 10% discount WhatsApp messages.
This naive approach creates massive unseen damage:
- It burns ₹250 to ₹500 in bank bounce penalties on recurring mandates.
- It triggers Asset Management Companies (AMCs) to permanently cancel investor SIPs.
- It trains customers to abandon carts, eroding operating margins through Return-To-Origin (RTO) delivery losses.
We asked a fundamental question: What if a payment gateway had an autonomous immune system? An intelligent platform that diagnoses the exact root cause in single-digit milliseconds, applies causal econometrics to protect merchant margins, and operates with strict statutory compliance under Indian banking and tax regulations. That became the genesis of the Razorpay Autonomous Revenue Recovery Ecosystem.
What it does
The Razorpay Autonomous Revenue Recovery Ecosystem is an end-to-end, 9-pillar autonomous intelligence platform powered by 8 specialized machine learning models and deterministic governance daemons:
- Root-Cause Diagnostic Intelligence (Pillar 1): A 5-layer classification waterfall parsing raw ISO 8583 and NPCI response codes in < 10 ms with 96.05% accuracy, isolating whether an issue is bank-side, user-side, network-side, or risk-driven before taking any action.
- The NACH Mandate Shield (Pillar 2): An autonomous recurring engine for SIPs, EMIs, and insurance premiums. It pre-emptively escalates at failure #2 before AMC auto-cancellation, guards borrower CIBIL scores at Day 28, and permanently suppresses retries on frozen accounts—delivering a +51.3% revenue lift and saving ₹28,500 in bounce fees in a 100-batch empirical trial.
- Causal Net-EV Maximizer (Pillar 3): A LightGBM Causal S-Learner that calculates the Individual Treatment Effect ($\tau_a$) minus coupon cost and ₹250 COD Return-To-Origin (RTO) downside. If net expected profit $\max(\Delta\Pi) \le 0$, it strictly suppresses discount intervention to protect gross margins.
- False-Decline Legitimacy Reversal (Pillar 4): A 97%+ accuracy classifier identifying genuine buyers caught in rigid fraud blocks, instantly executing
reverify_and_reversestep-up OTP prompts without merchant delays. - Sub-50ms Edge BNPL Rescue (Pillar 5): A synchronous edge decision tree intercepting hard card limit declines at checkout, offering an on-screen 1-click Buy Now, Pay Later split in < 15 ms.
- AI Chargeback Dispute Pre-emption (Pillar 6): A 5-Model Stacking Ensemble (Random Forest, XGBoost, LightGBM, Logistic Regression, GBDT) with Variance Gating ($\sigma \le 0.10 \implies$ auto-submit; $\sigma > 0.10 \implies$ human triage), generating fact-grounded merchant defense briefs.
- B2B MSME Statutory Tax Collector (Pillar 7): An autonomous corporate dunning engine citing Section 43B(h) of the Income Tax Act (buyer disallowance penalty) and CGST Rule 37 (ITC reversal) for invoices overdue past 45 days.
- RBI Mandate UI Compliance Scanner (Pillar 8): An automated schema auditor inspecting recurring mandate checkout screens against RBI 2026 guidelines (24h pre-debit notices, no dark patterns, 1-click cancel buttons).
- NPCI Invariant Governor (Pillar 9): A hard mathematical clearing guard guaranteeing strict compliance with NPCI retry caps ($\le 4$ retries per 24 hours).
How we built it
We engineered the ecosystem as a production-grade, containerized distributed architecture across 13 microservices:
- Diagnostic Core & Edge Gateways: Built in Go (
bnpl-edge-service,nach-recovery-service,b2b-recovery-service) for microsecond-level concurrency, high-throughput webhook digestion, and deterministic Layer 0 invariant gating. - ML & Inference Gateway (
:8000): Built in Python & FastAPI, loading all 8 production models into active memory:- Causal S-Learner & RTO Classifier (LightGBM)
- 5-Model Stacking Ensemble (Scikit-Learn, XGBoost, LightGBM)
- Payment Success Random Forests & Fast Edge Decision Trees
- Statutory Legal Reasoning Engine
- Data & Message Streaming: Redis Streams & ZSETs for real-time checkout drop-off telemetry and stateful session tracking; PostgreSQL with acid-compliant audit trails for all statutory notices and representment logs.
- Executive Mission Control & Models Hub: Built with Next.js 15, React 19, TypeScript, and Vanilla CSS with frosted-glass dark-mode aesthetics. Connects via Next.js Server Actions directly to the live Python inference gateway, featuring real-time millisecond latency counters, interactive parameter sliders, SHAP feature signals, and raw JSON tensor payloads.
Challenges we ran into
Sub-50ms Latency Budget vs. Heavy ML/LLM Inference: Synchronous cloud LLM calls took 2,500ms+, causing checkout timeouts during real-time card declines and high-throughput webhooks.
Solution: We created a 5-layer waterfall architecture. Layer 0 (deterministic statutory checks) and Layer 2 (Scikit-Learn/LightGBM localized in Go/Python) resolve decisions in 3–9ms. Complex multi-LLM reasoning (dispute briefs and statutory notices) was decoupled into asynchronous background queues via Redis.Causal Treatment Cannibalization & The "Discount Spam" Trap: Standard commercial recovery bots spam 10% coupon codes to 100% of cart drop-offs, giving away margin to customers who would have purchased organically ($P_0$) and accelerating expensive Return-To-Origin (RTO ≈ ₹250) losses on COD orders.
Solution: We formulated and enforced a strict Causal Net Expected Value equation: $$\Delta\Pi_a = P_a[(1 - r_a)(CM - D_a) - r_a K_{RTO}] - P_0[(1 - r_0)CM - r_0 K_{RTO}] - K_a$$ If $\max(\Delta\Pi) \le 0$, the system enforces programmaticNO_ACTIONsuppression, capturing ~88% of maximum oracle net profit.Autonomous Agents vs. Regulatory Banking Invariants: Giving autonomous AI free rein to retry payments risks triggering NPCI bank gateway bans ($\le 4$ attempts/24h) or causing AMC SIP auto-cancellations.
Solution: We implemented hard Layer 0 Deterministic Governors upstream of all machine learning models. Hard database constraints and policy checks halt retries on terminal errors regardless of downstream model confidence.Model Variance in Friendly-Fraud Representments: A single model can be dangerously overconfident on incomplete evidence, risking non-refundable $15–$25 arbitration fees.
Solution: We engineered a 5-Model Stacking Ensemble with a Variance Gating Rule: representments are auto-submitted only when cross-model standard deviation $\sigma \le 0.10$ and win probability $P_{\text{win}} \ge 0.70$. High disagreement automatically routes to human triage review.
Accomplishments that we're proud of
- Zero Static Fallacy: The entire platform runs real machine learning models in real time. Visiting the
/modelshub executes live inference against our FastAPI gateway with sub-10ms round-trip measurements. - +51.3% Measured Lift in NACH Mandates: Proven in a live 100-batch empirical benchmark, lifting revenue from ₹2,42,659 to ₹3,67,117 while eliminating 114 wasted bank attempts (saving ₹28,500 in penalty fees).
- Sub-15ms BNPL Edge Execution: Achieving edge-speed credit routing on hard declines before the customer abandons the page.
- Deep Regulatory Grounding: Enforcing Indian financial frameworks directly into software—including Section 43B(h) MSME tax laws, CGST Rule 37, and RBI February 2026 recurring payment mandate guidelines.
What we learned
- Payment failures are multi-dimensional, not binary: SBI core downtime requires rail rerouting; user price shock requires causal nudges; e-mandate failure requires balance-aware timing; corporate invoice delay requires statutory legal pressure.
- Causal Inference > Predictive Classification: Knowing that a user will buy if given a discount is useless if they would have bought anyway. Measuring the treatment effect ($\tau$) is the difference between bleeding margin and maximizing net revenue.
- Software architecture must enforce statutory guardrails: Autonomous AI in fintech cannot operate unconstrained. Hard mathematical and legal governors (Layer 0) are non-negotiable.
What's next for Autonomous Revenue Recovery Ecosystem
- Direct Account Aggregator (AA) Integration: Integrating with RBI-licensed Account Aggregators to inspect real-time user bank balance health before scheduling recurring NACH mandates, predicting balance peaks with even greater accuracy.
- UPI Circle & Delegated Payments Engine: Extending our sub-50ms edge recovery to India's new UPI Circle ecosystem (secondary user authorizations and delegated merchant mandates).
- Federated Cross-Merchant Fraud Defense: Training local edge models across merchant networks to detect emerging friendly-fraud syndicates while keeping raw customer financial data strictly privacy-preserved.