RRQ

Closed-loop payment ledger on sharded Postgres with a Kafka outbox

Image 1 of 2: Grafana service health dashboard with request rates, error rates, latency quantiles and circuit breaker states

Moves money only between wallets inside the system, so a transfer on one shard is one serializable Postgres transaction, and cross-shard transfers go through a two-phase clearing-account saga. Go services publish through a transactional outbox to Kafka, behind Envoy, with webhooks, a DLQ and replay.

  • 3,000+ RPSBurst (live K8s)
  • <40 msP50 at burst

Trade-offs

  • Closed loop: money only moves between wallets inside the system. Same-shard transfers need no saga or distributed lock, and only cross-shard ones pay for a two-phase clearing-account saga.
  • Ledger history is append-only, so mistakes are fixed by correction postings, never by editing entries.
  • Webhooks are ordered per merchant by partitioning the Kafka topic on merchant_id, which orders delivery per merchant but not across them.

Q&A4

A UNIQUE(merchant_id, idempotency_key) constraint on jobs gives at-most-once execution, alongside the other written invariants.

Reviews

Loading reviews

    More in Payments

    See all 9 →
    • OffPayOffline UPI payments over *99# USSD, with no data connection
    • go-ledgerMulti-tenant double-entry payment ledger API in Go, built in public
    • SellfSelf-hosted storefront for digital products on the seller's own Stripe account
    • PandaPayLensPayment error decoder and event timeline that runs in the browser
    • PartageEnd-to-end encrypted, local-first bill splitting with no accounts
    • minshopSmall store on Cloudflare Workers that agents can pay

    More in Ledgers

    See all 7 →
    • pgledgerDouble-entry ledger implemented entirely in PostgreSQL functions and views
    • HisabDouble-entry ledger kept by texting a WhatsApp agent, in Urdu or English
    • Accountant24Personal finance agent that keeps an hledger ledger in plain text under git
    • OpenBilanzLocal tool for a German GmbH's opening balance, annual accounts and E-Bilanz
    • franken_accountingEvidence-native double-entry accounting system of record in Rust

    More in Distributed systems

    See all 20 →
    • arbiterPostgreSQL job queue for Haskell, with no broker and no leader
    • RuvioRust key-value server that speaks RESP, with locks and queues as commands
    • EgresPostgres-compatible database in Zig for heavy, multi-tenant workloads
    • clinkC++ stream processing engine that stays correct when processes die
    • pg-statusSidecar that reports PostgreSQL master, replicas and replication lag
    • LassoSelf-hosted Ethereum JSON-RPC proxy that routes each call to the best provider