Payment Hold, Charge, and Settlement
Design a payment lifecycle that durably accepts hold and charge work, resolves upstream outcomes, releases unused holds, and incrementally builds parallel network-specific settlement batches.
Problem statement
Design a payment processor that places holds on cards, charges them later, and settles the charges with each payment network every night.
Holds. A hold reserves an amount on the card without taking the money yet. A merchant sends a hold request with an account or card number and an amount. The service may save the request durably in Kafka or a similar retained work log and reply before the network answers. That early reply is not an approval. A worker then sends the request to the right upstream payment network, which later approves it, denies it, or leaves the result uncertain. The merchant gets the final result by polling or through a callback.
Charges and releases. After a successful hold, the merchant can make a separate charge later, after the customer signs or adds a tip.
Nightly settlement. Charges are grouped by payment network. Each night at 10 p.m. there is a cutoff, and each network's charges are paid in one large wire-transfer batch. Don't do all the work at the cutoff. Prepare the batch during the day instead. Record each eligible charge as an entry that never changes. Split the entries by network into chunks that can be retried, and process the chunks in parallel. At the configured cutoff, seal the batch so no more entries can join it, then finalize one wire result per network. The source gives no time zone or holiday calendar, so treat both as settlement-calendar settings.
No duplicates. Duplicate checks must rely on durable state that survives retries, worker restarts and adding more workers. A retry must never create a second hold, charge, release, batch entry, chunk result or wire transfer. Every state change must be recorded so it can be audited and reconciled, that is, matched against the payment network's records.
Out of scope: refunds, disputes, recurring billing, foreign exchange and merchant onboarding.
What to build
- A merchant can request a hold and retry safely. Right away, before the network answers, the merchant gets a stable operation ID and an explicit queued or pending status. Later the merchant sees the network's result: approved, declined, pending or uncertain.
- A merchant can charge up to the amount of the hold that is still valid, and retry safely. A hold that is never charged is eventually released, with one released result that can be audited.
- Each confirmed charge goes into exactly one 10 p.m. batch and wire result for its payment network.
- Merchants and operators can look up the authoritative history (the service's own record) of holds, charges, releases, batches, wire transfers and reconciliation. An uncertain network reply is shown as uncertain, not as a failure.
At scale
- Peak about 10,000 transactions per second, counting hold, approval, release and capture work together.
- The upstream payment network (the external processor) can take up to 5 seconds, or give no clear answer at all.
- A merchant may retry a timed-out request up to 10 times.
- Updates from the payment network can arrive up to 15 minutes out of order.
- Lifecycle lookups return within 500 milliseconds at p95.
- When the service can't prove whether money actually moved, being correct comes before staying available.