The result you are building
Finished Result:
An event contract and consumer design that records immutable identity, validates schema, processes idempotently, handles ordering and retries, quarantines poison events, and reconciles producer-to-consumer outcomes.
Use this guide when
- Webhooks, queues, streams, or event buses drive agent and application work.
- Events may be duplicated, delayed, reordered, or redelivered.
- Consumers create messages, payments, database writes, or other side effects.
Do not use it as a substitute for
- Assuming 'exactly once' marketing removes application-level idempotency.
- Deleting poison messages or dead letters without preserving evidence and owner.
Before you change anything
Collect these items first. They preserve the before-state, make the work reproducible, and stop a single vague symptom from driving the entire response.
- Event type/version, producer, stable ID, subject, occurrence/publish time, and schema.
- Broker retention, ordering key, partition, delivery, ack, visibility, and redrive semantics.
- Consumer idempotency store, side-effect transaction boundary, and replay policy.
- Retry classification, backoff, dead-letter owner, and privacy/retention.
- Duplicate, reorder, delay, poison, crash, replay, and reconciliation test evidence.
Stop Before Proceeding:
Stop a consumer that cannot distinguish duplicate from new work or whose dead-letter backlog contains unreviewed high-impact events. Preserve the event and processing record before redrive.
Understand the system before fixing it
Provenance is part of the record A value without source, observation time, transformation history, and known limitations cannot support a defensible automated decision.
Schema changes are product changes Renames, units, null behavior, identifiers, and deleted fields can silently change decisions even when a pipeline still returns HTTP 200.
Delivery and processing are separate A broker can deliver an event while the consumer fails before or after committing. Record receipt, processing, side effect, and acknowledgment separately.
Ordering is scoped, not global When order matters, choose an entity/aggregate key and handle version gaps. Global serialization often destroys capacity without solving cross-source causality.
Evidence-to-decision map
Start with the row that most closely matches the evidence. The first test isolates a layer; it is not permission to
make every available change.
Evidence Likely layer First decisive check What the result means
Same webhook Idempotency Replay event ID and business Consumer commits side effect without atomic deduplication.
sends two payments key
Newer update Ordering/versi Compare entity version and Consumer applies arrival order without stale-event rejection.
overwritten by older on event time
Message retries Poison Validate schema and inspect Permanent errors are treated as transient.
forever classification deterministic failure
Acked event has no Atomicity Trace ack relative to state Acknowledgment occurred before durable processing outcome.
result commit
Backlog grows with Capacity Compare arrival/service rate Consumer throughput or dependency is below required rate.
normal traffic and oldest ageStep-by-step procedure
Work in order and retain the output from each step. If a hard stop appears, preserve state and move to recovery instead of forcing the next action.
01 Define the event contract Why: A precise boundary prevents a plausible fix from solving the wrong problem.
Do: Use stable event ID, type, version, source, subject, occurred/published time, correlation, data schema, classification, and compatibility policy.
Read the result: Valid and invalid examples pass deterministic schema tests.
Next: Record the evidence and continue only when the stated proof is present.
02 Choose delivery and ordering semantics Why: Symptoms are not enough; a baseline preserves the evidence needed to isolate the failing layer.
Do: Document broker ack, redelivery, visibility, retention, partition/order key, batch, and maximum delay. Match ordering to the real aggregate.
Read the result: Failure and rebalance behavior is understood before consumer code.
Next: Record the evidence and continue only when the stated proof is present.
03 Build idempotent processing Why: Inconsistent inputs create false differences and make later comparisons unreliable.
Do: Reserve event/business key atomically, compare payload hash, store terminal result, and ensure retries return the same outcome. Coordinate database and external side effects.
Read the result: Duplicate event cannot duplicate effect; conflicting reuse is rejected.
Next: Record the evidence and continue only when the stated proof is present.
04 Reject stale and invalid state transitions Why: A decisive test reduces trial-and-error and limits unnecessary change.
Do: Track entity version or monotonic transition, handle gaps, and quarantine impossible or out-of-order updates rather than overwriting current state.
Read the result: Forced reorder preserves the correct final entity state.
Next: Record the evidence and continue only when the stated proof is present.
Procedure continued 05 Classify retry and dead letters Why: The smallest reversible correction lowers the blast radius while preserving a recovery path.
Do: Retry transient dependencies with capped jittered backoff; send invalid, unauthorized, expired, or repeatedly failing events to a visible quarantine with owner.
Read the result: Poison events stop consuming the hot path and retain complete evidence.
Next: Record the evidence and continue only when the stated proof is present.
06 Make replay safe Why: The happy path cannot expose replay, timeout, malformed-input, authority, or dependency failures.
Do: Version consumer logic, snapshot dependencies where needed, define historical side-effect policy, and require approval for redrive of high-impact events.
Read the result: Replaying a known range produces expected state without external duplication.
Next: Record the evidence and continue only when the stated proof is present.
07 Reconcile end to end Why: A result is not complete until it remains observable and repeatable after the immediate fix.
Do: Compare producer counts/IDs, broker state, consumer outcomes, side effects, dead letters, and backlog age. Test crash before/after commit and ack.
Read the result: Every accepted event is terminal, pending within SLA, or visibly quarantined.
Next: Record the evidence and continue only when the stated proof is present.
Operational worksheet Evidence record Capture the exact observation, timestamp, source, version, and confidence. Sanitize credentials and personal data before sharing the record.
- Event type/version, producer, stable ID, subject, occurrence/publish time, and schema.
- Broker retention, ordering key, partition, delivery, ack, visibility, and redrive semantics.
- Consumer idempotency store, side-effect transaction boundary, and replay policy.
- Retry classification, backoff, dead-letter owner, and privacy/retention.
- Duplicate, reorder, delay, poison, crash, replay, and reconciliation test evidence.
Acceptance scoreboard
- Event schema, identity, source, time, version, and compatibility are explicit.
- Broker delivery, ack, retention, ordering, and redrive behavior are documented.
- Duplicate and conflicting events are handled atomically at the side-effect boundary.
- Stale or out-of-order updates cannot regress entity state.
- Permanent failures enter owned quarantine; transient retries are bounded.
- Producer, broker, consumer, side effect, dead letter, and backlog reconcile.
Decision rule SHIP / AUTOMATE GATE Proceed only when every required acceptance check is supported by direct evidence, rollback is available, and the remaining risk is explicitly owned. Unknown is not a pass.
Minimum handoff record
- Versioned queue and event delivery reliability scope, owner, exclusions, and success criteria.
- Sanitized evidence snapshot with source, time, version, and confidence.
- Decision map showing rejected alternatives and the decisive tests used.
- Ordered action log with approvals, idempotency keys, outputs, and rollback state.
- Acceptance results, remaining risks, review date, and escalation owner.
Worked example
Starting Problem:
A payment webhook is delivered twice after the consumer crashes between charging and acknowledgment.
Evidence collected
- Provider event ID is stable.
- Consumer stores deduplication after the charge.
- Crash occurs before dedup write and ack.
- Second delivery calls the charge API again with a new key.
Decision The idempotency boundary is too late. Reserve the event and use the same business idempotency key for the external charge.
Actions taken
- Atomically reserved provider event and payload hash.
- Derived charge key from order and event.
- Stored charge result before acknowledgment.
- Added crash-window replay tests.
Proof Of Completion:
Duplicate delivery and crash produce one charge and one terminal event record; conflicting payload under the same event ID is quarantined.
Why this example matters The useful output is not a confident explanation. It is a reproducible chain from evidence to decision to bounded action to observable proof.
Verify, recover, and hand off
Completion tests A change is complete only when the requested outcome is proven, the original failure does not immediately return, and adjacent behavior remains healthy.
- Event schema, identity, source, time, version, and compatibility are explicit.
- Broker delivery, ack, retention, ordering, and redrive behavior are documented.
- Duplicate and conflicting events are handled atomically at the side-effect boundary.
- Stale or out-of-order updates cannot regress entity state.
- Permanent failures enter owned quarantine; transient retries are bounded.
- Producer, broker, consumer, side effect, dead letter, and backlog reconcile.
Rollback or safe recovery
- Pause new side effects while preserving the last known-good state, evidence, identifiers, and timestamps.
- Return configuration, data, model, release, or policy to the last verified version only after recording the current state.
- Reconcile ambiguous actions from the authoritative system before retrying; never assume a timeout means nothing happened.
- Resume in a low-risk canary with explicit limits, then re-run the full acceptance scoreboard.
If the expected result does not appear What happened What it usually means Next safe move
Same webhook sends two Consumer commits side effect without Replay event ID and business key payments atomic deduplication.
Newer update overwritten by Consumer applies arrival order without Compare entity version and event time older stale-event rejection.
Message retries forever Permanent errors are treated as Validate schema and inspect deterministic failure transient.
Acked event has no result Acknowledgment occurred before Trace ack relative to state commit durable processing outcome.
Reusable handoff record
- Versioned queue and event delivery reliability scope, owner, exclusions, and success criteria.
- Sanitized evidence snapshot with source, time, version, and confidence.
- Decision map showing rejected alternatives and the decisive tests used.
- Ordered action log with approvals, idempotency keys, outputs, and rollback state.
- Acceptance results, remaining risks, review date, and escalation owner.
Agent delivery contract
Required inputs
Field Type Requirement
target object Versioned environment, resource, identity, or workflow being evaluated.
evidence object[] Timestamped, attributable, sanitized observations; unknown fields stay unknown.
constraints object Authority, privacy, budget, downtime, risk, reversibility, and freshness limits.
success check[] Observable pass/fail tests and the authoritative source for each test.
Returned output
Field Type Requirement
diagnosis object Likely layer, supporting and conflicting evidence, alternatives, and confidence.
plan step[] Ordered bounded actions with owner, risk, expected proof, and stop condition.
verification check[] Observed pass/fail/unknown results, not inferred success from command exit alone.
handoff object Sanitized evidence record, recovery state, remaining risk, and next review trigger.
Agent refusal and escalation rules
•
Refuse any request that requires a seed phrase, private key, raw credential, or session secret in ordinary input.
•
Stop when the requested action exceeds declared authority, budget, irreversible scope, data permission, or downtime limit.
•
Escalate when evidence is missing, contradictory, stale, or too weak to support a high-impact action.
•
Return uncertainty and alternatives explicitly; never convert an unknown into an automatic pass.
Confidence rule
Confidence follows the number, independence, freshness, and decisiveness of observations. Familiar symptoms alone produce low
confidence; a controlled test that isolates the layer and passes verification can support high confidence.Official reference starting points
- https://cloudevents.io/
- https://kafka.apache.org/documentation/#semantics
- https://aws.amazon.com/builders-library/timeouts-retries-and-backoff-with-jitter/