UPI-based payment app

Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2020-10-18

Problem Statement

Design a Unified Payments Interface (UPI)-based mobile payment system that enables users to send and receive money instantly between bank accounts using their mobile numbers or virtual payment addresses (VPAs).


The system should handle real-time transactions, ensure high availability, low latency, and strong security, and be compliant with financial and regulatory requirements (e.g., NPCI, RBI guidelines).


📋 Functional Requirements


👤 User Features


1.User Registration & Authentication
•Register using phone number linked with a bank account.
•Verify identity using OTP and link to bank via UPI SDK/API.
•Create a Virtual Payment Address (VPA), e.g., username@bank.
2.Bank Account Management
•Fetch user’s linked bank accounts via UPI.
•Add or remove bank accounts.
•Set a primary account for transactions.
3.Money Transfer
•Send money via:
•VPA (user@bank)
•Phone number
•QR code (scan & pay)
•Account number + IFSC
•Receive money through UPI collect requests.
•Split bills with multiple users.
4.Transaction History
•View recent transactions, status (Success, Pending, Failed).
•Filter by date, contact, or type (debit/credit).
5.Notifications
•Real-time alerts for money sent/received.
•Transaction confirmations and reminders.
6.Security
•2FA (PIN + Device Binding).
•Device-level encryption.
•Fraud detection & limits for suspicious activity.


🏦 Admin / Backend Features


1.Transaction Routing
•Interface with NPCI’s UPI switch for request validation and settlement.
•Handle retries and transaction reconciliation.
2.Settlement & Reconciliation
•Manage inter-bank settlements via UPI and bank partners.
•Generate audit and compliance logs.
3.Dispute Management
•Allow users to raise transaction disputes or refunds.
•Track chargebacks and escalation workflows.
4.Analytics & Reports
•Transaction volume, success/failure rate, fraud analysis.
•Settlement reports for partner banks.
5.Integrations
•Support external apps (e.g., bill payments, merchants, and wallets).
•Interface with UPI SDKs (BHIM, NPCI Sandbox).


⚙️ Non-Functional Requirements


AspectRequirement


Performance

End-to-end payment latency < 3 seconds.


Scalability

Should support millions of concurrent users and transactions.


Availability

99.999% uptime (5 nines).


Security

PCI-DSS compliant, data encryption (AES-256), secure PIN storage.


Reliability

Retry mechanism for failed payments and idempotent APIs.


Compliance

Follow NPCI, RBI, and ISO 20022 guidelines.


Observability

Real-time monitoring, logging, and fraud detection.


🧩 Core System Components


1.Mobile App / Web UI
•UPI user interface for registration, payments, and transaction history.
•Built with strong encryption and biometric/PIN authentication.
2.API Gateway
•Authenticates API requests and routes them to the appropriate services.
•Enforces throttling, caching, and rate-limiting.
3.User Management Service
•Handles onboarding, user profiles, and device binding.
•Manages linked bank accounts and UPI IDs.
4.Transaction Service
•Core service to initiate, process, and confirm UPI transactions.
•Maintains idempotency keys to prevent duplicate payments.
5.Payment Gateway / Bank Integration Service
•Connects to NPCI UPI Switch and partner bank nodes.
•Implements collect/push flow and handles settlement acknowledgments.
6.Notification Service
•Sends real-time updates via SMS, email, or in-app alerts.
7.Security & Fraud Detection Service
•Monitors for unusual activity and flags or blocks transactions.
•Uses ML-based anomaly detection (optional).
8.Ledger Service
•Maintains an immutable record of all transactions for auditing.
•Supports reconciliation and reporting.
9.Analytics & Reporting Service
•Aggregates data for dashboards and system health metrics.
10.Database Layer
•Stores user profiles, transactions, and audit logs.
•Uses strong consistency for transactions (e.g., PostgreSQL, CockroachDB).
•Redis cache for session and recent transaction lookups.


🏗️ High-Level Architecture Overview

1 2+-----------------------------+ 3| Mobile App / Web UI | 4+-------------+---------------+ 5 | 6 ▼ 7 +--------------+ 8 | API Gateway | 9 +--------------+ 10 | 11 +-------+-------+ 12 | | 13 ▼ ▼ 14+--------------+ +------------------+ 15| User Service | | Transaction Svc | 16+--------------+ +------------------+ 17 | | 18 ▼ ▼ 19+--------------+ +-------------------+ 20| Bank Adapter |→→→| NPCI / UPI Switch | 21+--------------+ +-------------------+ 22 | 23 ▼ 24+---------------------+ 25| Ledger & Reporting | 26+---------------------+ 27 | 28 ▼ 29+----------------------+ 30| Analytics & Monitoring| 31+----------------------+


🔐 Security Considerations


•PIN & OTP encryption — Secure PIN storage using HSM (Hardware Security Module).
•Data in transit — TLS 1.3 enforced for all communication.
•Device Binding — Each device tied to user credentials to prevent account sharing.
•Audit Trails — Immutable logs for all user and admin actions.
•Fraud Detection — Velocity checks, pattern analysis, and blocklisting.


🔍 Design Discussion Points


•How will you ensure idempotency in duplicate transaction requests?
•How to handle transaction retries when NPCI or bank nodes fail?
•How will you secure inter-service communication and protect PINs?
•What database schema ensures fast lookups for high-volume transactions?
•How do you achieve 5-nines availability across multiple regions?
•How can you implement real-time fraud detection at scale?


✅ Summary

Design a highly available, secure, and compliant UPI-based payment platform that enables real-time peer-to-peer and merchant transactions, ensures financial integrity, supports fraud detection, and integrates seamlessly with banking and regulatory infrastructure.


Solution

Comments