Skip to content

docs: fan-out fixes an event's handlers; how to change them safely (with design proposal) - #101

Merged
dillonstreator merged 1 commit into
mainfrom
docs/fanout-handler-set
Nov 28, 2026
Merged

dillonstreator merged 1 commit into
mainfrom
docs/fanout-handler-set

Conversation

@dillonstreator

Copy link
Copy Markdown
Member

What was wrong (TXOB-CONS-001, verified High)

Fan-out creates deliveries once per event, using only the handler map of the processor that leased the event, and then sets fanned_out_at. Nothing ever fans an event out again. So:

  • Rolling deploy that adds a handler: events fanned out by old pods during the overlap never reach the new handler, even after the rollout. The audit PoC on Postgres 17: 20 events, crm delivered 2. There was no error, no dead row and no metric. Which events are hit depends on which pod wins the NOTIFY race.
  • Removing a handler: old pods keep creating deliveries that nobody claims. They stay pending forever.
  • Type: {} / several services on one store: a processor marks those events fanned out with zero deliveries, so a second service's handlers never see them.

The README said "one delivery per registered handler" and "at-least-once delivery per handler" and never mentioned this.

What changed (docs only, as asked; no behavior change)

  • How It Works: deliveries are created for handlers registered in that processor, once per event.
  • New "Changing handlers" section:
    • rolling-deploy add: either use Recreate for processors (publishers can still roll) or back-fill. A Postgres back-fill statement is included; I ran it against Postgres 17 (it inserts only the missing deliveries, pending and due now).
    • remove: delete the orphaned pending deliveries after the rollout.
    • shared store / {}: give each service its own tables via the prefix options, or run one processor deployment.
  • The {} sentence in Quick Start now says what {} does to a shared store.

No changeset: README only.

Design proposal: making the handler set safe to change

The goal: an event reaches every handler that is registered "eventually everywhere", with no manual back-fill, and without slowing down the common path.

Option A: reconcile within a bounded window (recommended long-term)

Record the handler set an event was fanned out with: a fanout_handlers text[] / array attribute, or a hash of the sorted handler names. When a processor starts, or its handler map changes, it re-fans recent events that are missing one of its handlers. "Recent" is bounded by a reconcileWindowMs option (default e.g. 1 h, which covers any rollout), and the re-fan uses the existing idempotent completeFanout (ON CONFLICT DO NOTHING and equivalents).

  • Pros: automatic and safe under any deploy strategy. Cost is paid once per processor start, not per poll. Handles the shared-store case partly (only within the window).
  • Cons: a schema change on every store (one column/attribute, plus a partial index on Postgres). The reconcile query has to be written five times. Back-filled events may be old, so handlers must tolerate late delivery, which at-least-once already implies. It doesn't help with removals.

Option B: an explicit back-fill API (recommended first step)

processor.backfill({ handlers: ["UserCreated.crm"], since: Date }), or a store-level backfillDeliveries, which creates the missing deliveries for already fanned-out events, computing priority/key/defer through the real handler config.

  • Pros: additive, off by default, and no schema change (created_at/fanned_out_at already exist). It gives the documented manual SQL a supported, cross-store form, and it computes priority and keys correctly, which hand-written SQL can't. It is also the primitive Option A would call.
  • Cons: still a deploy step the operator has to remember.

Option C: per-service consumer names

Key deliveries and fan-out state by a consumer name (e.g. fanned_out_at per consumer) so several services can share one outbox, each fanning out for its own handlers.

  • Pros: makes shared stores a supported topology.
  • Cons: changes the core data model (fan-out state moves from the event to a per-consumer table). The README already points multi-consumer setups at a broker. The largest change of the three.

Option D: fail loudly instead

Record the handler-set hash per event (as in A), and have processors warn or emit telemetry when they see events fanned out with a different set.

  • Pros: cheap, and it turns silent loss into a signal.
  • Cons: detects without fixing. Useful mostly as a step towards A.

Recommendation

  1. Merge these docs now.
  2. Add B (the back-fill API) in the next minor. It is additive and testable through the contract suite on every store, and it makes the documented workaround safe.
  3. Add A later, built on B, once you're willing to take the schema change (store the handler-set hash, reconcile on start within a window). Worth pairing with D's telemetry.
  4. Don't do C unless a multi-service use case appears. A broker fed by txob covers it better.

The owner needs to decide whether to take on the schema change for A, and whether shared stores should ever be supported (C) or stay explicitly unsupported, as these docs now say.

How it was tested

  • prettier --check README.md: clean.
  • The back-fill SQL ran against Postgres 17 on a schema created by migrate, with one event that already had the delivery and one that didn't. Result: 1 row inserted, both deliveries pending/due.

Not in this PR

No implementation of A–D. The brief allowed an optional off-by-default draft, but I left it out so you can pick the design first.

…ge them safely

Deliveries are created once, from the handler map of whichever processor
fans the event out. Document what that means for rolling deploys that add
or remove a handler, for {} handler maps, and for several services on one
store, with a Postgres back-fill for the deploy overlap.
@codecov

codecov Bot commented Nov 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.13%. Comparing base (b9a22f4) to head (86d69ca).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #101   +/-   ##
=======================================
  Coverage   96.13%   96.13%           
=======================================
  Files          34       34           
  Lines        2355     2355           
  Branches      478      478           
=======================================
  Hits         2264     2264           
  Misses         74       74           
  Partials       17       17           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dillonstreator
dillonstreator merged commit f550c3b into main Nov 28, 2026
4 checks passed
@dillonstreator
dillonstreator deleted the docs/fanout-handler-set branch November 28, 2026 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant