Problem
Financial systems have unusually strict correctness requirements. Money must never be created or destroyed by a software failure, every operation must be traceable, and executing the same payment twice must be safely rejected.
I built this project to implement those constraints from first principles, without relying on managed payment infrastructure.
Architecture
The system is split into six independently deployable services. Each service owns its own PostgreSQL database: no shared state and no cross-service database access. An Angular frontend talks to the orchestrator and the auth service through an nginx reverse proxy.
Services
-
saga-orchestrator
Coordinates the distributed payment workflow across all services.
-
payment-service
Payment records, idempotency enforcement, status tracking.
-
account-service
Account lifecycle, balance storage, debit and credit operations.
-
ledger-service
Double-entry bookkeeping: every transfer produces a paired DEBIT and CREDIT entry.
-
audit-service
Append-only event log of all system actions and outcomes.
-
auth-service
Registration, login, JWT issuance and validation.
The transfer saga
Distributed ACID transactions don’t exist across independent databases, so a transfer is a sequence of local transactions, each with an explicit compensating action.
Saga: happy path and compensation
-
payment.create
Payment record created with status PENDING.
-
account.debit(source)
-
ledger.record(DEBIT)
-
account.credit(destination)
-
ledger.record(CREDIT)
-
payment.complete
Status COMPLETED.
-
audit.append(SUCCESS)
-
on failure → COMPENSATE
Reverse debits and credits, write offsetting ledger entries.
-
payment.fail
Status FAILED, failure reason recorded in the audit log.
Key decisions
- Orchestrated saga over distributed transactions. One coordinator owns the workflow and its compensations, which keeps the failure handling explicit and in one place.
- Double-entry ledger as a correctness mechanism. Every transfer produces exactly one debit and one credit, so the sum of all debits always equals the sum of all credits, and the ledger can be checked for consistency at any time.
- Idempotency at the payment service. The payment service tracks payment state and rejects duplicate execution of the same payment. Semantically invalid requests (same-account transfers, non-positive amounts) are rejected at the boundary, before any state changes.
- Append-only audit trail. Every action, successful or failed, is recorded, and no entry is ever modified or deleted, so the full history of any payment is traceable.
- Database per service. Strong isolation between services, at the cost of giving up cross-service transactions. That trade-off is what the saga exists to handle.
- JWT propagated through the call chain. The token travels from the frontend through the orchestrator to downstream services, and each service validates it independently. There’s no single auth bottleneck.
Tech
Rust for every backend service, Axum (Tower ecosystem) for HTTP, SQLx for compile-time verified async SQL, PostgreSQL with one isolated database per service, Docker Compose for deployment, nginx as reverse proxy and static file server, and an Angular SPA as the client.