Search DistillSys

Find a concept

Type at least two characters to search lessons, designs, papers, and interview prep.

Messaging incident · Senior

Orders are fulfilled twice after a consumer restart

At-least-once delivery meets a non-idempotent warehouse side effect.

01
Establish the operating contract

Incident brief

Business impact

A warehouse ships duplicate packages after a consumer deployment. Refund and recall costs are rising.

Current architecture

Order events are read from a partitioned log. The consumer calls a warehouse API, writes a local processed-event row, then commits its offset.

Protected invariant

Each order may create at most one shipment, while no paid order may be silently skipped.

Constraints
  • The log and local database support transactions independently, not together.
  • The warehouse API accepts an optional client reference but does not document retention.
  • Losing a paid order is worse than delayed fulfillment.
02
Build a causal model

Evidence timeline

  1. Consumers restart after processing events but before committing offsets.

  2. The same event IDs are delivered again, as designed.

  3. The local deduplication row exists for some duplicates, but warehouse shipment IDs differ.

  4. Operators propose committing offsets before calling the warehouse.

03
Reason before revealing

Your response

1Diagnose

Where is the unsafe gap in the current operation order?

Need a nudge?

List every crash point between external effect, local record, and offset commit.

2Stabilize

How do you stop new duplicates without losing events?

Need a nudge?

Keep at-least-once input and make the side effect safely repeatable.

3Recover

How do you identify and reconcile already duplicated shipments?

Need a nudge?

Event IDs alone are not enough if the external provider created new identities.

4Prevent

Which patterns work when the transactional boundary ends at an external API?

Need a nudge?

Think idempotency contracts, inbox/outbox records, and explicit state machines.

04
Compare reasoning, not wording

Model response

Reveal structured response
Diagnosis

The warehouse call occurs outside the atomic boundary. A crash after shipment creation but before the dedup row or offset commit causes redelivery and a second external side effect.

Stabilize now
  1. Pause the affected consumer partitions while retaining the log backlog.
  2. Require a stable shipment idempotency reference derived from order ID for every warehouse call.
  3. Query the warehouse by that reference before retrying ambiguous requests.
  4. Do not commit offsets early; that trades duplicates for silent loss.
Recover safely
  1. Join event IDs, orders, client references, and warehouse shipment records to locate duplicates.
  2. Define compensating actions—cancel, intercept, or refund—based on shipment state.
  3. Resume from known offsets with idempotent calls and bounded concurrency.
  4. Record every ambiguous external outcome for operator reconciliation.
Prevent recurrence
  1. Persist an inbox/state-machine transition before dispatch and an outbox command for shipment work.
  2. Contractually define idempotency-key scope and retention with the warehouse.
  3. Make consumers safe under crash injection at every boundary.
  4. Monitor duplicate deliveries separately from duplicate business outcomes.
05
Use evidence-based self-assessment

10-point rubric

Your score0 / 10

Check only the signals your answer demonstrated.

Common traps
  • Committing the offset before the side effect
  • Assuming the broker can deduplicate warehouse calls
  • Keeping deduplication records for less time than redelivery is possible
  • Calling compensation without checking shipment state
06
Strengthen the underlying concepts

Related refreshers