System Design: Basic Online Banking with Safe Money Movements
Context
Design a minimal but production-minded online banking service. It must support core money operations while ensuring correctness under retries and concurrency, and provide strong auditability and security.
Assume a single region deployment with a relational database (e.g., PostgreSQL). Currency is fiat (e.g., USD) with integer minor units (cents) to avoid floating point error.
Functional Requirements
-
Create accounts for users.
-
Deposit funds into an account.
-
Withdraw funds from an account.
-
Transfer funds between accounts.
Non-Functional Requirements
-
Atomicity: Money movements are all-or-nothing.
-
Idempotency: Safe client retries without duplicate movements.
-
Concurrency safety: Prevent double-spend and race conditions.
-
Immutable ledger/audit trail: Append-only financial records with reversals, not edits.
-
Security: Authentication, authorization, input validation.
-
Consistency and error handling: State guarantees and clear error semantics.
Deliverables
-
Data model (schemas at the level of tables and key fields).
-
API design (endpoints, key request/response fields, idempotency).
-
Transaction flow for deposits, withdrawals, and transfers (including concurrency control).
-
Approach to an immutable ledger and auditability.
-
Security considerations.
-
Consistency guarantees and error handling strategy.