One flow, four ways to build it
A customer pays; the shop must learn whether the payment succeeded and then ship. Four honest designs exist, and the team will build whichever one the ticket implies, so the ticket had better choose.
| Pattern | How information moves | Latency | What can go wrong |
|---|---|---|---|
| Synchronous call | we call them and wait for the answer in the same request | milliseconds | their slowness becomes our slowness; timeouts leave us not knowing |
| Webhook | they call us when something happens | seconds | we may be down; events arrive twice, late, or out of order |
| Polling | we ask them every N seconds or minutes | N | wasted calls; rate limits; "did we miss one?" |
| Queue / event | one side writes a message, the other reads when ready | seconds to minutes | messages pile up; ordering and duplicates must be handled |
None is "best". The choice depends on three questions you can answer for any flow in five minutes.
The three questions
- Does the user wait for the answer? If the customer is looking at a spinner, the first step has to be synchronous (or feel like it). Nobody waits for a nightly report; that is a queue or a batch.
- Who knows first? If the other system learns about the event (payment settled, parcel scanned), a webhook or their event stream is the natural source. If only we know (we created an order), we push.
- What happens if a message is lost or doubled? Money, stock and legal records need delivery guarantees and idempotency. A "recommended for you" update does not.
For the payment flow the answers are: yes, the user waits for the attempt; the provider knows the outcome first; a doubled "paid" must not ship twice. So: synchronous call to start, webhook to confirm, polling as a safety net, and idempotency on the handler. That combination is what most payment integrations actually look like.

Synchronous call: the rules that make it safe
- Set a timeout and say what happens after it. "Call the provider with a 5 s timeout; on timeout show 'we are confirming your payment' and switch to the webhook/polling path." A missing timeout is an outage waiting to happen.
- Do not chain more than two. A request that calls A, which calls B, which calls C, fails whenever any of them does; latency adds up and nobody can tell whose fault it was.
- Decide what the user sees on each failure: provider down (try again later), declined (choose another method), timeout (we will e-mail you). Three answers, three sentences in the ticket.
Webhook: the rules
- Acknowledge fast, process later. Return 200 within a second, store the event, process it from a queue. A slow handler makes the sender retry, and now you have duplicates.
- Verify the sender. Signature header or shared secret; the ticket names which.
- Expect duplicates and disorder. The same event can arrive twice; "shipped" can arrive before "paid" if the network is unkind. The handler keys on the event id and checks the state machine before acting (see Statuses are a state machine).
- Expect gaps. Webhooks do get lost. Every webhook integration needs a reconciliation path: a poll or a daily report that finds events you never received.
Polling: when it is the right answer
Polling is unfashionable and often correct: when the other side offers no webhook, when volume is small, when a few minutes of delay are fine. Rules: an interval the other side tolerates (read their rate limit), a since parameter or a cursor so that you ask only for what is new, and backoff when they answer 429 or 503.
Queue: when the work can wait
A queue decouples "the order is placed" from "the warehouse is told". The order service writes a message; the warehouse integration reads it when ready; if the warehouse system is down for an hour, nothing is lost, it is just late. Rules: a dead-letter queue for messages that fail repeatedly (and a person who reads it), idempotent consumers, and a ticket line about ordering ("messages for the same order are processed in order; across orders, order does not matter").
Drawing it: the sequence diagram
The artefact that gets an integration reviewed is a sequence diagram: participants across the top, time downwards, one arrow per message, with the failure branches drawn in. Three rules for a diagram developers trust:
- Name the real systems (Checkout, Payment provider, Orders service), not "frontend/backend".
- Show the unhappy arrows: timeout, retry, duplicate event. The happy path alone is a sales slide.
- Put the data that matters on the arrow: the idempotency key, the event id, the status.
Checkout -> Payment provider : POST /payments (amount, idempotency key) [timeout 5 s]
Payment prov. -> Checkout : 201 pending (payment_id)
Payment prov. -> Orders service : webhook payment.succeeded (event_id, payment_id)
Orders -> Orders : seen event_id before? yes → 200 and stop
Orders -> Orders : order status New → Paid; reserve stock
Orders -> Payment prov. : GET /payments/{id} every 60 s if no webhook in 5 min
The same content as the picture above, in text, for the ticket. Both are fine; the reviewer needs one of them.
With AI
Models explain the patterns well and can draft a sequence diagram from a paragraph. They tend to produce the happy path and forget the reconciliation sentence, the timeout value and the duplicate handling. Use the draft, then add the three unhappy arrows yourself; that is the whole analytical content of the ticket.
Try it (5–10 minutes)
Flow: "When a customer's parcel is delivered, send them a review request 24 hours later, unless they have already returned the item."
- Answer the three questions. Which parts are webhook, queue, poll, synchronous?
- Write the sequence in text (as above) with at least three unhappy arrows: carrier webhook lost, duplicate delivered event, return registered during the 24 h.
- Fill the sentence: "If the delivered event never arrives, we find out by ___ within ___."
Where this shows up in real work
- System analyst and integration analyst job posts ask for "designing integrations with third-party systems", "webhooks", "message queues" and "sequence diagrams"; the interview is usually a payment or shipping flow.
- In real incidents, "we never got the webhook" and "we processed it twice" are the two most common integration post-mortems; the reconciliation sentence and the idempotency rule are the fixes.
- Freelance "connect A to B" projects are scoped by the pattern: a webhook with reconciliation is a different estimate from a nightly file, and the client needs to hear which one they are buying.
Sources worth reading
- Stripe docs: webhooks best practices (retries, signatures, idempotency)
- Gregor Hohpe and Bobby Woolf: Enterprise Integration Patterns (pattern catalogue online)
- Standard Webhooks: an open specification for webhook payloads, signatures and retries
- AWS Builders' Library: timeouts, retries and backoff with jitter
Practice it on real drills
Integration between two systemsSync vs async / batch vs real-time decisionEvent-driven design (events & consumers)