| Scale | Users | Transactions per Second (TPS) | Key Changes |
|---|---|---|---|
| Small | 100 users | 1-5 TPS | Single payment gateway, single app server, simple DB setup |
| Medium | 10,000 users | 50-200 TPS | Multiple app servers behind load balancer, payment gateway failover, DB read replicas |
| Large | 1,000,000 users | 1,000-5,000 TPS | Horizontal scaling of app servers, sharded DB, caching, multiple payment gateways, async processing |
| Very Large | 100,000,000 users | 50,000+ TPS | Microservices architecture, global load balancing, multi-region DB clusters, advanced fraud detection, CDN for static content |
Payment integration architecture in HLD - Scalability & System Analysis
Start learning this pattern below
Jump into concepts and practice - no test required
At small to medium scale, the database is the first bottleneck. Payment transactions require strong consistency and ACID properties, so the DB must handle many writes and reads reliably. As TPS grows beyond a few thousand, the DB can become overwhelmed by write locks and transaction volume.
At larger scales, the application servers handling payment processing and communication with external payment gateways become bottlenecks due to CPU and network limits.
- Database scaling: Use read replicas for read-heavy queries, implement sharding by user or transaction ID to distribute writes, and optimize indexes.
- Application scaling: Horizontally scale app servers behind load balancers to handle more concurrent payment requests.
- Caching: Cache non-sensitive data like payment method metadata to reduce DB load.
- Payment gateway: Integrate multiple payment gateways with failover and load balancing to avoid single points of failure.
- Asynchronous processing: Use message queues for non-critical tasks like sending receipts or fraud checks to reduce latency.
- Security and compliance: Ensure PCI DSS compliance and encrypt sensitive data to maintain trust and avoid penalties.
- At 1,000 TPS, expect ~86 million transactions per day.
- Each transaction record ~1 KB, so daily storage ~86 GB; monthly ~2.5 TB.
- Network bandwidth depends on payload size; assume 2 KB per transaction -> 2 MB/s at 1,000 TPS.
- Database must handle ~1,000 writes/sec plus reads; a single PostgreSQL instance can handle up to ~5,000 QPS with tuning.
- App servers: each can handle ~1,000 concurrent connections; scale horizontally as needed.
Start by clarifying the expected transaction volume and latency requirements. Then identify the main components: app servers, database, payment gateways. Discuss bottlenecks at each scale and propose targeted solutions like caching, sharding, and horizontal scaling. Emphasize security and compliance. Use real numbers to justify your choices.
Your database handles 1,000 QPS. Traffic grows 10x to 10,000 QPS. What do you do first?
Answer: Add read replicas to offload read queries and implement sharding to distribute write load. Also, consider caching and asynchronous processing to reduce DB pressure.
Practice
Solution
Step 1: Understand the role of each component
The Payment Gateway acts as the secure bridge that transmits payment data from your system to the bank or processor.Step 2: Identify the secure transmission responsibility
Other components like Merchant Database or User Interface do not handle secure transmission of payment data.Final Answer:
Payment Gateway -> Option AQuick Check:
Secure transmission = Payment Gateway [OK]
- Confusing Payment Gateway with Merchant Database
- Thinking User Interface handles security
- Assuming Inventory Management is involved in payments
Solution
Step 1: Identify the logical payment flow
The user starts the payment, which goes to the Payment Gateway, then to the Payment Processor, and finally to the Bank for authorization.Step 2: Verify the order of components
Options B, C, and D have incorrect sequences that do not match the real-world payment flow.Final Answer:
User initiates payment -> Payment Gateway -> Payment Processor -> Bank -> Option BQuick Check:
Payment flow order = A [OK]
- Reversing the order of components
- Placing Bank before Payment Gateway
- Confusing Payment Processor and Gateway roles
sendPaymentRequest(userData) {
gatewayResponse = callPaymentGateway(userData)
if (gatewayResponse.status == 'success') {
processorResponse = callPaymentProcessor(gatewayResponse.data)
return processorResponse.status
} else {
return 'failed'
}
}What will be the output if
callPaymentGateway returns {status: 'success', data: 'txn123'} and callPaymentProcessor returns {status: 'approved'}?Solution
Step 1: Analyze the gateway response
The gateway returns status 'success' and data 'txn123', so the if condition is true and the processor is called.Step 2: Analyze the processor response
The processor returns status 'approved', which is returned by the function.Final Answer:
'approved' -> Option DQuick Check:
Processor status returned = 'approved' [OK]
- Returning gateway status instead of processor status
- Returning transaction data instead of status
- Ignoring the else branch
Solution
Step 1: Identify silent failure cause
Silent failures usually happen when errors are not caught or logged properly, indicating missing error handling.Step 2: Evaluate other options
Using HTTPS, encrypting data, and validating input improve security and correctness but do not cause silent failures.Final Answer:
Missing error handling after calling the payment gateway -> Option AQuick Check:
Silent failure = Missing error handling [OK]
- Blaming HTTPS or encryption for failures
- Ignoring the need for error handling
- Assuming validation causes silent failures
Solution
Step 1: Identify scalability needs
Handling 10,000 TPS requires distributing load and decoupling components to avoid bottlenecks.Step 2: Evaluate architectural choices
Asynchronous queues and horizontal scaling allow parallel processing and fault tolerance. Single server or unsharded DB cause bottlenecks. Skipping retries reduces reliability.Final Answer:
Use asynchronous message queues between components and horizontally scale payment processors -> Option CQuick Check:
High TPS needs async queues + horizontal scaling [OK]
- Choosing synchronous single server processing
- Ignoring database sharding or partitioning
- Skipping retries reduces payment reliability
