Volume 12 · Chapter 2 — System Design Case Studies

Case Study: Payment Processing System

Goutham Mayaluri 8 min read AWSCloudSystem Design

2.1 The Problem and Requirements

Design a system that processes customer payments and transfers for a bank. Clarifying requirements: functionally, it must accept a payment request, move money between accounts correctly, and confirm to the customer, while triggering downstream effects (notifications, fraud checks, ledger updates). Non-functionally, correctness is paramount - money must never be created, lost, or double-counted, so strong consistency and exactly-once effect are required; it must be highly available (customers need payments to work) and secure and compliant; it must handle significant load with spikes (payday); and latency should be low for the customer-facing confirmation. The defining constraint is that this is money, so correctness dominates every design decision.

2.2 High-Level Architecture

Requests enter through CloudFront and a WAF, then an API gateway that authenticates and rate-limits, routing to a stateless payment service running in an Auto Scaling group across multiple AZs. The payment service performs the money movement as an ACID transaction on the authoritative ledger (Aurora PostgreSQL, Multi-AZ), then confirms to the customer. Downstream effects are handled asynchronously: the payment service publishes a “PaymentMade” event, which fans out (SNS-to-SQS) to notification, fraud, and analytics consumers that process independently. This keeps the customer-facing path fast and consistent while decoupling the rest.

flowchart TB
  Client((Customer)) --> Edge[CloudFront + WAF]
  Edge --> GW[API Gateway - auth, rate limit]
  GW --> Pay[Payment service - stateless, multi-AZ]
  Pay --> DB[(Aurora PostgreSQL - ACID ledger, Multi-AZ)]
  Pay --> Topic[(SNS: PaymentMade)]
  Topic --> Qn[(SQS)] --> Notif[Notification consumer]
  Topic --> Qf[(SQS)] --> Fraud[Fraud consumer]
  Topic --> Qa[(SQS)] --> Analytics[Analytics consumer]
  Pay --> Cache[(Cache - reference data)]

2.3 Ensuring Correctness

Correctness is engineered with the transaction-integrity techniques from Volume 5. The money movement is a single ACID transaction on the ledger - the debit and credit both commit or both roll back (atomicity), the result survives crashes (durability), and row locking with appropriate isolation prevents concurrent transfers on the same account from corrupting balances. Every payment request carries an idempotency key, so a retry after a timeout or a redelivered message applies the transfer exactly once, never twice. The authoritative balance always comes from the ACID ledger, never a cache. For downstream consistency, the “PaymentMade” event is published via the outbox pattern (event written in the same transaction as the ledger update) and consumers are idempotent. If a transfer spans services, a saga with compensations coordinates it. This is the heart of the design.

2.4 Scaling and Resilience

The stateless payment service scales horizontally in an Auto Scaling group across AZs, absorbing payday spikes by adding instances, with the load balancer distributing to healthy ones. The ledger runs Multi-AZ with automatic failover and read replicas offload read-heavy queries (balance and history lookups) from the write path, with a cache for hot reference data. Downstream work is asynchronous, so a slow fraud or notification consumer never blocks or fails the payment - the queues absorb bursts and consumers scale to their depth. Resilience patterns protect calls to any external payment networks (timeouts, retries with backoff, circuit breakers). The result is a system that stays available and correct under load and partial failure.

2.5 Security, Observability, and Trade-Offs

Security: the payment service and ledger run in private subnets with no internet exposure, accessed via IAM roles (no stored keys), with data encrypted in transit and at rest using KMS, secrets fetched at runtime, and least- privilege throughout. Observability: metrics (payment success rate, latency, error rate), structured logs with correlation IDs, and distributed tracing across the flow, with alerts on the business metrics. The key trade-offs: the customer-facing money movement is synchronous and strongly consistent (correctness demands it), while downstream effects are asynchronous and eventually consistent (decoupling and resilience matter more there, and the work can happen slightly later) - so the customer sees “payment confirmed” immediately for the money movement, while notifications and fraud scoring complete shortly after. This deliberate split - strong consistency where money moves, eventual consistency for the rest - is the central design decision.

2.6 Banking Production Notes

In production, this design lets the bank process payments correctly and confirm quickly while the surrounding effects happen reliably in the background. Payday spikes are absorbed by horizontal scaling and queue buffering; a fraud-service slowdown never blocks payments; an AZ or database failure triggers automatic failover; idempotency makes client retries safe; and the ACID ledger guarantees money is never lost or double-counted. The whole flow is observable and auditable. This is a canonical banking design that combines nearly every concept in the series, anchored by the non-negotiable requirement of correctness for money.

2.7 Troubleshooting the Design

Weaknesses in a payment design are recognizable. Making downstream effects synchronous would let a fraud or notification slowdown block or fail payments - decouple them asynchronously. Omitting idempotency would let retries double-process payments - add idempotency keys. Reading the balance from a cache to authorize a payment risks using stale data - read the authoritative ledger. Skipping the outbox pattern risks the ledger update and its event diverging. Running the ledger single-AZ risks an outage - use Multi-AZ. Not using ACID transactions for the money movement risks half-applied transfers - wrap it in one transaction. The design’s correctness rests on ACID transactions, idempotency, the outbox pattern, and reading balances from the source of truth, with async only for the effects that can be eventually consistent.

Interview Question

Design a payment processing system for a bank. What are the key decisions?

I’d start from the defining requirement: this is money, so correctness dominates - money must never be created, lost, or double-counted - alongside high availability, security and compliance, low customer-facing latency, and handling spiky load like payday. The high-level architecture: requests enter through CloudFront and a WAF, then an API gateway that authenticates and rate-limits, routing to a stateless payment service in an Auto Scaling group across multiple Availability Zones. The payment service performs the money movement as a single ACID transaction on the authoritative ledger - Aurora PostgreSQL running Multi-AZ - then confirms to the customer, and it publishes a “PaymentMade” event that fans out via SNS to per-service SQS queues for notification, fraud, and analytics consumers that process independently. The key decisions center on correctness. The money movement is one ACID transaction so the debit and credit are atomic and durable, and row locking with appropriate isolation prevents concurrent transfers on the same account from corrupting balances. Every request carries an idempotency key so a retry after a timeout or a redelivered message applies the transfer exactly once, never twice - essential because duplicates are inevitable in a distributed system. The authoritative balance is always read from the ACID ledger, never a cache, because authorizing a payment on stale data would be wrong. Downstream consistency uses the outbox pattern - the event is written in the same transaction as the ledger update so they can’t diverge - with idempotent consumers, and a saga with compensations coordinates any multi-service transfer. The second major decision is what’s synchronous versus asynchronous: the customer-facing money movement is synchronous and strongly consistent because correctness demands it, while downstream effects like notifications and fraud scoring are asynchronous and eventually consistent because they can happen slightly later and decoupling means a slow fraud service never blocks or fails a payment - so the customer gets immediate confirmation while the surrounding effects complete shortly after. For scaling and resilience, the stateless service scales horizontally across AZs to absorb spikes, the ledger is Multi-AZ with automatic failover and read replicas plus a cache offloading read-heavy lookups, queues absorb bursts for the async work, and resilience patterns protect calls to external payment networks. For security, everything sensitive is in private subnets accessed via IAM roles with encryption in transit and at rest and least privilege, and the whole flow is observable with metrics like payment success rate, correlated logs, and tracing. The central trade-off I’d articulate is strong consistency where money moves versus eventual consistency for the effects around it - which correctly prioritizes correctness on the money path while gaining decoupling and resilience everywhere else - and the correctness foundation of ACID transactions, idempotency, the outbox pattern, and reading balances from the source of truth is what makes the whole design trustworthy for handling money.

Chapter Revision Notes

  • Requirement: correctness for money dominates - strong consistency and exactly-once effect - plus HA, security, low latency, spiky load.
  • Money movement is one ACID transaction on a Multi-AZ ledger; idempotency keys make retries exactly-once; balance read from the source of truth, never a cache.
  • Downstream effects (notification, fraud, analytics) are asynchronous via SNS-to-SQS fan-out, with the outbox pattern and idempotent consumers.
  • Central trade-off: synchronous strong consistency where money moves; asynchronous eventual consistency for the surrounding effects.
  • Scale statelessly across AZs, Multi-AZ ledger with read replicas + cache, resilience patterns for external calls, security and observability throughout.