Overview
A multi-location health clinic had a lifecycle automation in place: booking activity flowing from their clinic management platform through an automation layer into their CRM and email marketing tool, tagging every contact by treatment and stage. It had been flagged and paused for consuming far more resource than it should. The obvious assumption was a badly built automation. It turned out to be something else entirely.
The Problem
The automation kept getting flagged for runaway task consumption, far beyond what the clinic's actual booking volume could explain. Every time it was patched, it would fail again within days. On the surface, this looked like exactly the kind of thing you fix by finding the broken step and correcting it.
Investigation
The first hypothesis was the obvious one: something in the automation's own logic was wrong. Reviewing the build turned up a real issue quickly, a path condition was referencing the output of the wrong prior step, which meant some contacts were being tagged incorrectly. That got fixed. The runaway consumption continued anyway.
The second hypothesis was that the automation's duplicate-handling logic itself was flawed, an idempotency key design that wasn't reliably distinguishing one event from another. That got corrected too. The task volume dropped, but not by nearly enough to explain what was happening, and the pattern of failures didn't match a logic bug, it matched something closer to a flood.
That mismatch was the actual turning point. Rather than continuing to look for a third logic bug, the investigation moved a level down, into the raw webhook payloads arriving from the clinic platform itself. Laid out over time, a pattern became obvious that no amount of automation logic would have fixed: the platform was not sending a single event per booking. It was resending the same booking repeatedly, and at the payload level, a genuine new booking and a resend of an old one were indistinguishable.
That reframed the entire problem. This was never a bug in the automation. The automation was doing exactly what it was built to do, faithfully processing every event it was handed. The platform underneath it simply wasn't producing reliable events in the first place, which meant no amount of patching the automation itself could ever fully fix it.
BEFORE
Clinic Platform (resends same booking repeatedly)
|
v
Automation Layer
|
v
processes every event as if new
|
v
runaway task consumption
AFTER
Clinic Platform (resends same booking repeatedly)
|
v
Filtering Layer (tracks genuinely processed events)
|
+----+----+
| |
new duplicate
| |
v v
Automation discarded
Layer silentlyThe Solution
Once the root cause sat at the platform's data feed rather than in the automation, the fix had to sit there too. A small filtering layer was introduced ahead of the automation entirely, tracking which events had genuinely already been processed and only allowing real, new activity through. The automation downstream never needed to know the difference, by the time anything reached it, the noise had already been removed.
The filter itself is intentionally simple, a lookup against a small store of already-seen events before anything is forwarded on.
prefilter-worker.jsexport default {
async fetch(request, env) {
const payload = await request.json();
const eventKey = `event:${payload.booking_id}:${payload.updated_at}`;
const alreadyProcessed = await env.PREFILTER_KV.get(eventKey);
if (alreadyProcessed) {
return new Response("Duplicate event filtered", { status: 200 });
}
await env.PREFILTER_KV.put(eventKey, "1", { expirationTtl: 60 * 60 * 24 });
return fetch(AUTOMATION_WEBHOOK_URL, {
method: "POST",
body: JSON.stringify(payload),
});
},
};Engineering Trade-offs
The real decision here wasn't a specific technology choice, it was where in the system duplicate detection should live. Handling it inside the automation tool itself would have meant every future automation built on this data source would need to solve the same duplicate-detection problem all over again, forever inheriting the platform's unreliable event stream. Moving that responsibility to the ingestion point, before the data reached any automation at all, meant fixing it exactly once, at the layer where the actual instability originated, rather than treating every downstream symptom individually.
Challenges
The hardest part of this wasn't building the fix, it was resisting the pull to keep patching the automation every time a new symptom appeared. Two real bugs were found and fixed along the way, and both were worth fixing, but neither explained the scale of the problem. Recognising that a third round of logic fixes wasn't going to work, and that the investigation needed to move outside the tool entirely, was the actual turning point.
Outcome
- ✓ Genuine automation triggers dropped from an estimated several thousand a day to a small number reflecting real bookings only
- ✓ Zero errors in the new filtering layer during overnight production testing
- ✓ The automation itself simplified rather than made increasingly defensive
- ✓ The filtering layer's design became the foundation for a second, larger marketing attribution project
Reflection
It would have been easy to stop after the second bug fix and call the problem solved, the task volume had genuinely dropped, just not enough. The more valuable outcome came from treating that gap as a signal rather than a rounding error, and being willing to look outside the tool everyone assumed was at fault. The same instinct, that a partial improvement which doesn't match the expected scale is worth investigating further rather than accepting, is one I'd apply to any system that looks fixed but isn't quite behaving as the fix should predict.