Skip to content

API & data design · 4 of 4

Did it go through?

Step 1 · The pattern

The API waits for the bank, then answers

The app sends a payment; the API calls the bank and waits about 1.2 seconds for the answer, then replies paid. One request, one answer. (All numbers are illustrative.)

  • a payment
  • paid

In short

Did it go through?: how it works and how it breaks

Some operations take longer than a request should wait: a payment that waits on a bank, an export, a video encode. If the API holds the request open and it times out, the client does not know whether it happened. Asking again and again ('check status', or retrying) lands on the same slow system, slows it further and turns a delay into an outage. Answer at once instead: 202 Accepted with a status URL the client can poll, and Retry-After saying how long to wait. Record the operation in your own database and answer status from there, updating it when the bank replies, rather than forwarding every check to the bank. Make the original request safe to retry with an idempotency key, push the result where you can, and limit polling.

What this simulation simplifies

  • The background worker that talks to the bank in the fix is folded into the API.
  • Status checks arrive at a fixed rate; real ones snowball as timeouts grow.

How this comes up in interviews

"Design the API for a payment that can take up to 30 seconds at the bank."

Then they ask

  1. What does the client see in the meantime?
  2. How do you stop double payments?
  3. How should clients poll?

A strong answer covers

  • 202 Accepted with a status resource, instead of holding the request open.
  • Record the payment first; answer status from your own store.
  • Idempotency key on the create call; retries return the same payment.
  • Retry-After and server-side limits on polling; push results where possible.
  • Reconcile payments left unknown.

Points to cover, not a script. Say them in your own words and tie them to a system you have worked on.

On one page: the track cheat sheet.

Last reviewed: Official documentation

Diagrams are our own simulations: the timings, rates and counts in them are illustrative, not measurements. Captions are original wording.