Building a Fault-Tolerant Money Transfer Service
System DesignModel answerLast updated
Design a backend service that processes monetary transfers reliably despite retries, crashes, network failures, and ambiguous external responses.
Building a Fault-Tolerant Money Transfer Service
You need to architect a backend service that processes customer money transfers with absolute correctness guarantees. The system must handle incoming transfer requests, execute them through external processing systems, and provide status visibility—all while ensuring that network failures, process crashes, retry storms, and ambiguous third-party responses never result in lost funds, duplicate charges, or unreconciled states.
Structure your design by addressing: core requirements, API contracts, storage schema, failure scenarios, and operational tooling. Avoid assuming specific throughput numbers; instead explain what capacity considerations would influence your architectural decisions.
Requirements & Constraints
- Each transfer must have a stable identifier and progress through well-defined states
- Both end-user clients and internal processing components will retry operations
- External payment processors may accept work but fail to return a response, creating outcome uncertainty
- All monetary amounts must use precise decimal representation with explicit currency codes
- Users must be able to retrieve transfer status after the initiating request completes
Questions Worth Exploring
- Are transfers contained within your system's ledger, or do they exit to external bank networks?
- What cancellation semantics and user-visible state transitions should exist?
- What latency and consistency expectations govern status queries?
- Where does authoritative settlement occur, and how are chargebacks or corrections processed?
- What regulatory, audit trail, data retention, and geographic compliance requirements apply?
Hints
Hint 1
Separate the durable recording of user intent from the potentially-failing execution of external effects
Hint 2
Design explicit retry semantics for every component boundary, including how to handle the case where you cannot determine if an external call succeeded
Hint 3
Build reconciliation into your standard workflow rather than treating it as a break-glass emergency procedure
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer: Fault-Tolerant Transfer Service Design
Core Architecture Principles
The fundamental challenge is maintaining correctness when partial failures occur at any point. The solution centers on three pillars: idempotent request handling, durable state tracking with explicit uncertainty states, and proactive reconciliation as a normal operational path.
API Design and Request Acceptance
Initiation Endpoint: Accept transfer requests with client-provided idempotency keys (UUID format). The endpoint performs synchronous validation (amount positivity, account existence, balance sufficiency, currency compatibility) and atomically writes both the transfer record and an outbox entry within a single database transaction. Return the transfer ID immediately; actual processing occurs asynchronously.
POST /v1/transfers
{
"idempotency_key": "uuid",
"source_account": "account_id",
"destination_account": "account_id",
"amount": "100.00",
"currency": "USD"
}
The idempotency key ensures duplicate requests (from network retries or user mistakes) create only one transfer. If a key collision occurs, return the existing transfer without modification.
Status Query: GET /v1/transfers/{id} returns current state, timestamps, amount, and any failure reason. This must be strongly consistent—reading from the primary database to avoid showing stale states during critical windows.
State Machine and Data Model
Transfer States: pending → processing → completed | failed | needs_review
The needs_review state handles the ambiguous timeout case: we submitted work to an external processor but received no response. This signals operators that manual reconciliation is required.
Schema Design:
transferstable: id, idempotency_key, source, destination, amount, currency, state, created_at, updated_at, external_reference_idtransfer_eventstable: transfer_id, previous_state, new_state, timestamp, reason (immutable audit log)ledger_entriestable: transfer_id, account_id, amount, entry_type (debit/credit), timestamp (double-entry bookkeeping)outboxtable: id, aggregate_id, payload, processed_at (transactional outbox pattern)
Monetary amounts use DECIMAL(19,4) or equivalent fixed-precision types. Never use floating-point for money.
Asynchronous Processing and External Calls
A worker polls the outbox table, processes unhandled entries, and marks them complete. This guarantees at-least-once delivery without losing messages if the worker crashes after committing the transfer but before publishing an event.
External Processor Integration: When calling third-party payment rails, include a provider-specific idempotency token (separate from the client's key). If the call times out, transition to needs_review rather than blindly retrying. Log the external reference ID if one was returned before the timeout.
Retry Strategy: Use exponential backoff for transient errors (HTTP 5xx, network failures). Non-retryable errors (insufficient funds, invalid account) immediately transition to failed. The ambiguous timeout gets at most one automatic retry after a delay, then escalates to manual review.
Reconciliation as Normal Operations
Every day (or hourly for high volumes), fetch settlement reports from external processors and match them against local transfers in processing or needs_review states. Discrepancies trigger alerts. This catches:
- Transfers stuck in
processingthat actually completed externally needs_reviewtransfers awaiting resolution- External settlement with no corresponding local record (duplicate/fraud detection)
Reconciliation updates transfer states and creates ledger adjustments if needed. All adjustments are logged immutably in transfer_events.
Correctness Invariants and Monitoring
Implement continuous invariant checks:
- Sum of ledger debits equals sum of credits across all accounts
- Every
completedtransfer has matching debit and credit entries - No transfer remains in
processinglonger than threshold (e.g., 10 minutes) - External reference IDs are unique per processor
Alert on violations immediately. These catch bugs before they compound.
Capacity and Partitioning Considerations
Low-Medium Volume (< 1000 tps): Single PostgreSQL primary with read replicas suffices. Use row-level locking and serializable isolation for state transitions. Outbox polling scales by adding worker instances.
High Volume (> 10k tps): Partition by account ID or transfer ID prefix. Each partition gets its own database shard. Outbox polling becomes per-partition. Cross-partition transfers require distributed transactions (2PC) or saga patterns with compensating actions.
Availability choice: Prioritize consistency over availability. A brief outage is preferable to corrupting financial data. Use synchronous replication for durability.
Security and Compliance
- Authentication: OAuth 2.0 or mTLS for API access; service accounts for internal workers
- Authorization: Role-based access control; users can only query their own transfers
- Encryption: TLS 1.3 in transit; AES-256 at rest for PII and account numbers
- Audit Trail: Immutable event log with who, what, when for every state change
- Data Retention: Keep transfer records for 7+ years per financial regulations
- PII Minimization: Store only essential account identifiers; reference external systems for full details
Operational Remediation
Provide operator tools to:
- Manually transition
needs_reviewtransfers after confirming external state - Issue corrective ledger entries with justification comments
- Replay reconciliation for specific time windows
- Query full event history for any transfer
All remediation actions must require two-person authorization and be fully auditable.
Common Pitfalls
- Using client retries as the primary reliability mechanism (requires idempotency everywhere)
- Treating timeouts as failures rather than unknown states (can cause duplicates)
- Building reconciliation as an afterthought (too late to design in data needed)
- Ignoring the distributed transaction problem for cross-account transfers
- Underestimating audit and compliance needs until production
This design prioritizes correctness and auditability over raw throughput. Financial systems must fail safe—returning an error is acceptable; silently corrupting balances is not.