Skip to content

Insights — Automation

Webhooks, queues and retries: the boring plumbing that keeps automations alive

Most broken automations were never wrong, just unlucky: a timeout, a duplicate, a deploy at the wrong moment. The unglamorous parts that make a workflow survive its first bad day.

When an automation fails, the post-mortem is rarely dramatic. A partner's API was down for four minutes. A webhook was delivered twice. A deploy restarted the worker halfway through a batch. None of these are bugs in the sense of wrong logic. They are just the normal behaviour of networks, and a workflow that does not expect them will eventually lose or duplicate something that mattered.

Treat every incoming webhook as a rumour

A webhook tells you that something probably happened. It can arrive late, out of order, or more than once, and sometimes it never arrives. So the first thing our handlers do is verify the signature, store the raw event, and answer immediately with a success code. Doing the real work inside the request is how you end up timing out, getting the same event redelivered, and doing the work twice.

Put a queue in the middle

Storing the event and processing it later is the single most useful habit in this whole area. The queue absorbs bursts, lets you pause processing during an incident without losing anything, and gives you a place to look when somebody asks what happened to a particular order. It does not need to be fancy. A table with a status column and a worker that polls it is a perfectly respectable queue for a small business.

Make every step safe to repeat

Retries only help if running a step twice is harmless. That property has a name, idempotency, and the practical version is simple: give every operation a key derived from the thing it is about, such as the order number plus the action, and check that key before acting. Creating an invoice for an order that already has one should return the existing invoice, not make a second.

  • Retry with increasing delays, and stop after a sensible limit
  • Keep failed events where a person can see them, rather than dropping them
  • Alert on the number of stuck items, not on every single failure
  • Record what was done and why, in plain language, next to the technical log

Decide what a human sees

The last piece is the one people skip. When the machine gives up, somebody has to find out, understand the problem in under a minute, and fix it or push it through by hand. We build a simple screen or a daily message listing anything stuck, with a button or an instruction for each. It is not glamorous, and it is the difference between an automation people trust and one they quietly work around.

A small example

Suppose a shop sends an order to a courier whenever a customer pays. The payment provider calls our webhook. If we booked the courier inside that call and the courier's service was slow, the provider would time out and call again, and we might book two collections. Instead we record the payment event, return success, and let a worker book the courier using the order number as the key. If the courier is down, the worker waits and tries again. If it is still down after an hour, a person gets a message with the order and a link to retry. Nothing was lost, nothing was doubled and nobody had to guess what happened.

Keep a trail you can read

Logs written for machines are not enough at two in the morning. For each business event we keep a short, readable history: payment received, courier booked, label printed, customer notified. When a customer writes in asking where their order is, somebody can answer from that history without reading code. It costs very little to build and it is the part the operations team ends up using most.

Test the bad days

It is tempting to test only that the workflow works when everything goes well. We also try the bad days on purpose: switch off a dependency, send the same event twice, restart the worker in the middle of a batch. If we have not seen the system recover in a test, we should not expect it to recover in production.

None of this is clever, and that is the point. The reliable automations we have built look dull from the outside: events in, a queue, small safe steps, a clear list of what went wrong. If yours is held together by one long chain of steps that has to succeed in a single go, it is worth an hour of looking at where it would hurt to be interrupted.

Keep reading

More notes.