All projects

Personal project

PayCore.

Payment orchestration & ledger

  • Java
  • Spring Boot
  • PostgreSQL
  • Kafka

The problem

A payment request can time out after the server accepts it, and a capture event can be delivered again. Each retry needs to resolve to the same logical payment and journal entry.

What I owned

I built a Java and Spring Boot backend with separate payment and ledger services. PostgreSQL stores payment state and accounting records, and Kafka carries capture events between services.

From payment request to ledger

  1. Create payment

    The client sends an amount, currency, and Idempotency-Key. The payment service stores the request against the merchant and key.

  2. Process with a provider

    A worker claims the payment and submits it through a provider adapter. If the outcome is unknown, the service records an uncertain state for recovery.

  3. Publish the capture

    When the payment transitions to captured, an outbox record carries the capture event to Kafka.

  4. Post balanced entries

    The ledger consumes the capture event and debits gateway receivable while crediting merchant payable. The payment ID identifies the posting for deduplication.

Engineering decision

Scope retry keys to the merchant

If the same merchant retries with the same key, amount, and currency, the service returns the existing payment. Reusing that key with a different amount or currency returns a conflict. A concurrent insert race resolves to the payment that won.