Payment System
Design a Payment System
A robust, secure payment system processes financial transactions globally while guaranteeing idempotency and zero data loss.
1. High-Level Design
Payment systems must interface with external, unreliable third-party Payment Service Providers (PSPs) like Stripe, PayPal, or Visa.
Client App ---> API Gateway ---> Payment Service (Pending) ---> PSP Gateway (Stripe)
|
Idempotency Key (Redis)Components
1. Idempotency Service: Utilizes a Redis cache to store transaction tokens. If a client retries due to network failure, the token prevents double-charging.
2. Payment Service: Orchestrates transaction states (PENDING, SUCCESS, FAILED) and logs audit records to database.
3. PSP Gateway: Interfaces with external financial processors.
4. Reconciliation Service: A background processor comparing internal ledger tables with daily settlement reports from PSPs.
2. Potential Deep Dives
- Idempotency Mechanics:
On page load, the client requests a unique idempotency token. When clicking "Pay", this token is sent in the header. The server attempts to store the token in Redis with a distributed lock. If the token already exists, the server returns the cached response instead of processing the transaction again.
- Dual-Write Mitigation:
Use the transactional outbox pattern. Write both the transaction record and the corresponding event to the database in a single transaction, then emit to Kafka asynchronously.
3. References & Tech Blogs
Related Topics
Expand your knowledge by learning about adjacent concepts in system design.
Design a URL Shortener (TinyURL)
Build a high-throughput shortener analyzing base58 encodings and database sharding.
Networking Essentials
Learn the important parts of networking that you'll need to know for your system design interviews
API Design
Learn about API design for system design interviews
Cheat Sheet Utility
View and print a concise system design reference card.