The Status That Changed Itself

A product's status blinks between published and draft, nothing errors, and the guard you wrote first works right up until it doesn't. The loop was never an echo.

Read in Indonesian

The complaint arrives as a UI bug. A product's status blinks between published and draft, and the person watching it is a merchandiser who has not touched anything for an hour. Your error tracker stays quiet, the store admin shows no alerts, and every health check in the app is green.

The loop is hard to see because every hop is a network round trip. Your app writes a status, the store accepts it and sends a webhook back, your handler reads it, decides the store is wrong, writes again. In a log that reads as a sync running more often than it should. It does not read as a failure, because nothing failed.

Key takeaways

  • A status that flips back and forth comes from two rules with no state both of them accept.
  • Comparing against the last value the store sent works until your copy is stale, someone flips the field back, or two events land together.
  • Suppressing your own events only hides the conflict and leaves the product in whichever state won last.
  • Diffing against live state is necessary but not sufficient: if the other side's rule re-applies, the diff never clears.
  • Fix agreement before convergence, or the two systems keep flipping the same product until you hit the rate limit.

The fix everyone writes first

You keep a copy of the last status the store told you about, and you compare before writing. If what you would write is what the store already said, you skip. The chain stops.

This guard works on the single-writer path, in demos, and in tests where the fake store never calls back. It survives review because the reviewer cannot picture the interleaving that breaks it:

  • Your cached copy goes stale, showing published while the store has already moved to draft, so you skip a needed write or send an unnecessary one.
  • Someone flips the status back and forth within a second (published, draft, published), leaving your cache holding the first value so you skip and your database drifts from the store.
  • Two events arrive together, both handlers read the same cached copy, and both write.

Those are three real failure modes, yet fixing the cache still leaves the loop running.

Read the write log, not the handler

When you look at the sequence of writes instead of the code that produced them, the shape changes. Two rules are firing, both correct, and they disagree.

Your app decides a product should be draft, because the supplier has no stock. The store has an automation the merchant installed, and it decides anything with stock in it should be published. Neither rule is a bug, yet together they have no state that satisfies both, so each write triggers the other.

Treating the problem as an ownership conflict rather than a webhook echo rules out both common patches. Suppressing your own events only hides the conflict and leaves the product in whichever state won last. Diffing against live state also keeps looping: you compute draft, live is published, you write, the store automation flips it back, and the diff returns on the next cycle.

The fourth way an event reaches you

I have written before about three shapes this problem takes: the same event arriving twice, one fact arriving by two paths, and events arriving out of order. Those three come from delivery mechanics, whereas this one comes from causality: the event arrives because you wrote it.

Deduplication cannot solve it because the event is accurate, timely, and describes a change you actually requested.

What actually stops it

Fix agreement first, then convergence.

Start with agreement: one field, one owner. Where both sides genuinely must enforce a rule, your desired state has to satisfy the other side's invariant so that your write reaches a stable state. In the stock case, that means zeroing the inventory in the same write that drafts the product, so the store automation has no reason to flip it back.

Then add convergence: read live before deciding, write only when the desired value differs, keep one lane per object so two handlers cannot decide at the same time, and cap writes per object as an alarm rather than a throttle. Building convergence without agreement gives you clean diffs, no duplicates, and proper locking while the same product still flips until the store rate-limits you.

The lab that reproduces this is here, and the answer is here.

If receiving your own write back as an event would make your handler write again, a guard cannot stop the loop; the two rules have to agree on a shared state.

Get better at shipping code.

Join the other developers getting tech updates, tips, and relaxed tutorials in their inbox every week.

Stay in the loop

Tech updates, coding tips, and relaxed insights straight to your inbox every week.

No spam. Unsubscribe anytime.

Read next

See all
WebhookEvery Write Comes Back as News

A supplier file says the mug is gone, the app drafts it, the store puts it back, forty times. Seven checks, and the eager webhook handler is only the second problem.

Struktur DataWhat a Linked List Actually Is

A linked list is a linear chain of nodes, each holding data and a pointer to the next node. Here is what that chain looks like, what it costs next to an array, and the same minimal implementation in Java, Python, and JavaScript.

For developers who learn by struggling

© 2026 Inva.dev.