Payment Processing Service

Six Rust microservices that move money with an orchestrated saga, a double-entry ledger, idempotent payments and an append-only audit log.

  • Rust
  • Axum
  • PostgreSQL
  • SQLx
  • Docker
  • nginx
  • Angular
  • JWT

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.

Six services, one database each. The saga orchestrator coordinates every transfer.

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

  1. payment.create

    Payment record created with status PENDING.

  2. account.debit(source)

  3. ledger.record(DEBIT)

  4. account.credit(destination)

  5. ledger.record(CREDIT)

  6. payment.complete

    Status COMPLETED.

  7. audit.append(SUCCESS)

  1. on failure → COMPENSATE

    Reverse debits and credits, write offsetting ledger entries.

  2. payment.fail

    Status FAILED, failure reason recorded in the audit log.

If any step fails, the orchestrator runs the compensating actions in reverse, so money is never debited without appearing in the ledger.

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.

Demo

Planned / Interactive demo

Transfer simulator: step through the saga, inject a failure, resend the same idempotency key. Runs in your browser.

Next project

Java, Drools, risk

Fraud Detection System

A rule-based credit card fraud engine in Java and Drools that scores transactions in real time and explains every decision.