KatInterview

Card Payments With Tips and Nightly Batch Capture for a Café Chain

System DesignModel answer
MediumModel answerSystem Designpaymentsidempotencybatch-processing

Last updated

Design a card-present payment flow for a multi-location café chain: hold at swipe, tip added later, and a scalable nightly capture per location with safe retries and reconciliation.

You are designing the payment backend for a café chain's point-of-sale terminals. The payment flow works like this:

  1. At checkout, the customer's card is authorized for the purchase price. This places a hold but moves no money.
  2. After the fact, often on a separate screen while the transaction is still open, the customer may enter a tip. The tip is recorded as an adjustment to the original authorization.
  3. Money actually moves only when the location's nightly settlement runs. All finalized transactions for that location are captured together, using the purchase amount plus the tip.

Treat the card network and the payment processor as external black boxes that you call. You are not designing them.

Points to clarify first

State your assumptions about the following (or ask):

  • Scale: number of locations, terminals, and transactions per day, and the length of the nightly window.
  • Whether all locations share one cutoff time or each closes on its own local clock.
  • Until when a tip may change, and what happens to a tip that arrives after the batch has gone out.
  • Whether the processor takes a settlement file, per-transaction API calls, or both, and whether it supports idempotency keys or batch references.
  • Whether paying out to each location is in scope.

Part 1: Authorization and tip adjustment

Design the data model and API for authorizing a swipe and later attaching a tip. Terminal connections are unreliable, so every call may be retried. Cover:

  • The lifecycle states of a transaction (authorized, tip-adjusted, captured, and so on) and what each state stores.
  • Idempotency for both the authorize call and the tip-adjust call.
  • How to handle a processor timeout on authorization without placing two holds on the same card.

Part 2: Making nightly settlement scale

When a location closes for the day, its completed transactions must be captured. Design this so it keeps fitting in the nightly window as the chain adds locations and volume, and so a crash mid-run can neither lose a transaction nor charge it twice. Cover:

  • How you partition the work so it parallelizes as the chain grows.
  • Exactly-once submission to the processor, including what happens when a worker dies mid-batch.
  • Reconciliation: how you detect a transaction where the processor's report disagrees with your records, and what a location operator sees.

Your answer should be a structured design discussion with the trade-offs you are making, not just a list of components.

Hints

Hint 1

Generate identifiers on the client for each physical action (one per swipe, one per tip-entry attempt) and reuse them on every retry, then enforce uniqueness on them server-side and pass them to the processor.

Hint 2

Avoid modeling nightly settlement as one big job per location. Think about the smallest independently retryable unit, and how a lease or visibility timeout lets another worker take over from a crashed one.

Hint 3

Money discrepancies should not be auto-corrected. Think about what the processor's next-day report is compared against, where mismatches go, and what a tip arriving after the cutoff should do.