Skip to content
All studies

Payments / Independent study

Payment Orchestration Platform

A timeout is not a failed payment.

Separating payment intent from provider attempts, so retries and late confirmations don't create a second charge.

Scope

Independent Java / Spring Boot / PostgreSQL service, architecture proposal and TypeScript browser model. Local fictional payments; no employer code or live payment provider.

Architecture stack: Java · Spring Boot · PostgreSQL · AWS SQS

Executable model: TypeScript

Runnable independent demonstration

From browser model to a durable Java slice.

Java 21, Spring Boot and PostgreSQL implement intent creation, a stable provider attempt, transactional outbox and confirmation inbox. A deterministic stub accepts the fictional payment and loses its response; a later demo confirmation resolves the uncertainty.

  • Merchant-scoped request keys and payload conflict detection enforced with PostgreSQL constraints.
  • Tests race 12 callers and workers, deduplicate confirmation events, and replay a stable attempt after simulated process loss.
  • Docker Compose runs everything locally. The database worker stands in for SQS; the provider stub makes no network calls.
cd projects/payment-orchestration/java
docker compose up --build -d
# Java 21 + Maven + Docker: run PostgreSQL integration tests
mvn -B verify
Source, curl walkthrough and test instructions

This service is separate from the TypeScript model below and from employer production work. The public site does not host the Java backend. Authentication, signature verification, automatic reconciliation and real provider adapters remain outside this local slice.

The problem

A checkout request crosses a boundary the application cannot control. If a provider times out after accepting it, blindly retrying through another provider can turn a network problem into a duplicate charge.

The approach

Give the payment intent one owner. Persist the merchant-scoped idempotency key and request fingerprint before starting a provider attempt. Treat an ambiguous response as awaiting confirmation, then use a verified webhook or reconciliation result to resolve it.

Architecture

One intent. Explicit uncertainty.

Proposed system boundariessync / durable / async
  1. 01

    Merchant API

    Authenticate merchant; validate amount and key.

  2. 02

    Payment domain

    Own intent, attempt history and legal transitions.

  3. 03

    Provider adapter

    Translate requests; classify definite vs ambiguous failures.

Durable boundary

PostgreSQL: payment intent + request fingerprint + attempt + outbox record. Unique merchant/key constraint. Never hold a database transaction open across a provider call.

Asynchronous work

Outbox relay → SQS → attempt worker. Verified webhooks enter an inbox; reconciliation resolves missing confirmations. Each consumer deduplicates independently.

Logical boundaries, not a deployed topology. The interactive model below covers state transitions only.

Exercise the failure path

The response was lost. Now what?

Submit a simulated CAD 75.00 payment, retry the request, then deliver its provider confirmation twice.

Interactive model
Payment state
ready
Provider attempts
0
Confirmed amount
Not confirmed

key: checkout-001 / event: evt-001 / currency: CAD

Ready. Submit the payment to simulate a provider timeout.

Model limits: Single payment, in-memory TypeScript model. The webhook is assumed verified. No provider calls, persistence, concurrency or signature verification.

API design

An explicit command boundary.

Download OpenAPI sketch

Illustrative request and response. This contract specifies one command, not the entire proposed API.

POST /v1/payments

Idempotency-Key: command_demo

{
  "amountMinor": 7500,
  "currency": "CAD",
  "providerToken": "tok_demo"
}

Response

202 Accepted
Location: /v1/payments/pay_demo

{ "id": "pay_demo", "status": "awaiting_confirmation" }

Technical decisions

What I would choose. What it costs.

01Separate intent from attempts

A merchant payment can have several traceable attempts, but an unresolved attempt prevents blind rerouting.

Trade-off: Lower apparent availability during uncertainty; operational reconciliation is required.

02Provider-specific idempotency

Reuse a provider key for the same attempt, only where the provider guarantees that behaviour. Store the relationship locally.

Trade-off: Providers have different key retention and retry contracts. An abstraction cannot erase those differences.

03Start with a modular service

Keep domain, adapter and webhook modules explicit inside one Spring Boot service before introducing more deployable services.

Trade-off: Less independent scaling initially, but simpler transaction boundaries and incident investigation.

Operating the system

What needs attention in production.

Unknown outcomes

Alert on age of awaiting-confirmation payments, not just HTTP error rates. Route unresolved items to a reconciliation queue with evidence.

Safe recovery

Bound retries for definitively retryable failures. Dead-letter exhaustion for review. Never replay a financial operation without checking its current state.

Trust boundary

Verify provider signatures and replay windows before inbox insertion. Redact tokens and sensitive payloads; retain correlation IDs and audit metadata.

Outcome & limits

What this study establishes.

The TypeScript model illustrates request identity and confirmation deduplication. The independent Java slice exercises those boundaries against real PostgreSQL, including concurrent requests and a simulated crash after stub acceptance. Neither is a production reliability claim.

View study source

Next steps

Before calling it production-ready.

  • Extend the PostgreSQL slice with per-provider policies and authenticated merchant boundaries.
  • Test crash recovery around the outbox relay and webhook inbox.
  • Define retention, reconciliation SLAs and per-provider retry policies before a real integration.

Start a conversation

Building a backend team?

I'm interested in senior backend and Tech Lead roles across fintech, payments, SaaS and platform engineering in Canada.

Next study: Money Movement & Ledger