Design PhonePe's UPI Payment Switch
Problem
Design the UPI payment switch — the core routing layer that processes UPI transactions between payer PSP, NPCI, and payee PSP.
Requirements
Functional:
- Initiate, route, and confirm UPI transactions
- Handle collect and pay flows
- Callback / webhook to merchant
- Transaction history query
Non-functional:
- 1M TPS at peak (festival sales)
- p99 latency < 1.5s (NPCI mandate)
- Zero fund loss — atomicity across ledger entries
- Regulatory audit log retention: 7 years
Discussion points
- NPCI protocol constraints and timeouts
- Idempotency across retries with bank failures
- Double-entry ledger design
- Saga pattern for distributed transaction across PSPs
- Horizontal scaling of stateful switch nodes
added …