T

TechIdea

Ecosystem

← Back to System Design Hub
StripeDifficulty: Advanced

How Payment Gateways Work (Stripe)

Payment systems prioritize consistency (CP in CAP theorem) over availability. You cannot afford to lose a transaction or charge a user twice.

High-Level Architecture

[Client] -> (API) -> [Payment Service] -> (Idempotency Check) -> [Bank Gateway]

Database Design

Relational databases (PostgreSQL/MySQL) are strictly required for ACID compliance. Every state change is recorded in an append-only ledger.

Caching Strategy

Caching is avoided for transaction balances to prevent stale data. It is only used for merchant config and API keys.

Scaling & APIs

Scaling: Database sharding by merchant ID. Processing queues (Kafka) handle asynchronous tasks like sending receipts, but core charges are synchronous or use Two-Phase Commits.

API Design: REST APIs with mandatory Idempotency-Key headers.

Real-World Challenges

  • Network timeouts: Did the bank charge the card or not? (Solved via Idempotency).
  • PCI DSS compliance for storing credit card data.
  • Reconciliation: ensuring internal ledgers match external bank reports.

Growth Newsletter

Get practical AI tools, SEO tips, and growth guides weekly.

Join creators, students, and businesses scaling with TechIdea.