After a weekend downstream outage failed thousands of asynchronous order-event invocations, how do you find every failed event and redrive it safely once the fix ships?
answer
- the destination is not the full count
- reconcile against the source of truth
- send back through the normal path
- slowly, the downstream just recovered
- superseded events need a decision
basics
~20 sCount three groups: events in the failure destination, events dropped before reaching it, and half-applied ones. Reconcile against the order store, test one replay, then redrive through the normal path at a controlled rate, parking superseded events.
solid answer
~50 sFirst I size the loss. The **failure destination** holds events that used up their retries or age, but it misses events dropped where no destination was set or after its retention ran out, so I **reconcile** against the source of truth: orders created in the outage window with no matching downstream record. Then I confirm the downstream is healthy and replay **one** event end to end. The bulk redrive goes back through the **normal path** (republished to the source) so the same delivery settings apply, at a **controlled rate** through a capped replay worker, because a burst plus live traffic can knock the recovering downstream over again. Each event is checked against current state first: a reservation for an order cancelled on Sunday is parked, not applied. Replayed events carry a replay marker for tracing. Records leave the destination only after success, and the follow-up is an alarm on destination arrivals.
code
pseudocode · 13 linesfor record in failure_destination.receive(batch_size):
event = record.original_event
if already_applied(event):
failure_destination.delete(record)
continue
if superseded(event, current_state(event.order_id)):
park(record, reason = "superseded")
continue
rate_limiter.wait()
ok = republish_to_source(event, markers = { replay: true, original_time: event.time })
if ok:
failure_destination.delete(record)
# otherwise the record stays in the destination for the next passgo deeper
Remember that a failure destination holds failed events for replay, and that a replay only happens after the cause is fixed.
Explain why replays go back through the normal path and why they need a rate limit while the downstream is recovering.
Show the full sequence: reconcile against the source of truth, test one replay, redrive at a controlled rate, park superseded events, then add the missing alarms.
Argue for a shared, tested replay tool and reconciliation reports as platform features, so no team improvises a redrive during an incident.
## The situation An order-events pipeline invokes several functions asynchronously for each order: reserve stock, notify the warehouse, post to the ledger. On Saturday morning a downstream service they call goes down and stays down until Monday. Every invocation in that window fails, the platform retries each event a few times, and then each one reaches the end of its retry count or maximum event age. On Monday the downstream is fixed. Thousands of events need to be found and processed, without making anything worse. ## Step one: size the loss, not just the destination The **failure destination** is the obvious starting point, but it is rarely the full count. Failed events fall into three groups: 1. **Recorded failures** - events that used up their attempts and were written to the failure destination. These have their payload and error attached. 2. **Silent losses** - events that never reached a destination: a function without one configured, a destination that was itself unavailable, or records that outlived the destination's **retention** before anyone looked. 3. **Partial applications** - events where the handler did part of its work (reserved stock, then failed calling the warehouse) before the error. The way to see all three is to **reconcile against the source of truth**. Take the orders created during the outage window from the order store and compare them with what each downstream actually holds. The gap is the real loss; the destination is a subset of it. Events in the gap that are not in the destination must be rebuilt from the order store. ## Step two: confirm the fix before the bulk replay - Check the downstream's health and its capacity, not just that it answers. - Group the destination records by **error type**. A pile of timeouts is the outage; a handful of validation errors is a separate bug that replay will not fix and should be parked. - Replay **one** event end to end and verify every side effect. ## Step three: redrive through the normal path, at a controlled rate Send each event back the way it originally arrived, by **republishing it to the source** or using the queue's built-in redrive action where one exists, rather than invoking the function directly with a hand-made payload. The normal path applies the same retry count, maximum event age, failure destination and tracing, so a re-failure is caught the same way. Control the rate. Thousands of replayed events on top of Monday's live traffic can push the downstream that just recovered straight back over. Use a replay worker with a rate limit, or route replays through a function with its own per-function concurrency cap, and watch the downstream's latency and error rate as you go. ```pseudocode for record in failure_destination.receive(batch_size): event = record.original_event if already_applied(event): # downstream already has it failure_destination.delete(record) continue if superseded(event, current_state(event.order_id)): park(record, reason = "superseded") # a person decides continue rate_limiter.wait() ok = republish_to_source(event, markers = { replay: true, original_time: event.time }) if ok: failure_destination.delete(record) # if not ok, the record stays for the next pass ``` ## Step four: correctness on replay Replayed events are old events arriving into a world that has moved on. - **Idempotency.** Some events were partly applied; the handler must tolerate a second run. The patterns for that belong to idempotent consumers; the operator's job is to know whether each handler has them before replaying. - **Superseded events.** A Saturday "reserve stock" event for an order cancelled on Sunday must not be applied on Monday. Check the current state of the entity and **park** superseded events for a decision. - **Ordering.** Replays arrive after newer live events. If a handler assumes order, replay per entity in original-time order, or have the handler compare event times with stored state. - **Freshness.** Some events are no longer worth sending at all, such as a "your order is on its way" notification for an order already delivered. - **Markers.** Tag replayed events with a replay flag and the original timestamp so traces, metrics and downstream audits can tell them from live traffic. ## Step five: drain and harden | Check | Done when | |---|---| | Destination drained | Only parked records remain, each with a reason | | Reconciliation re-run | The gap against the order store is zero or explained | | Downstream stable | Error rate and latency back to normal under live plus replay load | Then fix what let the weekend go unnoticed: - An **alarm on arrivals** in every failure destination, routed to the owning team. - **Retention** longer than the longest unattended stretch. - Failure destinations on **every** asynchronous consumer, so the next reconciliation finds no silent losses. - The replay worker kept as a **runbook tool**, not rewritten under pressure next time.
- Why republish a failed event to its source instead of invoking the function directly with the payload?The normal path applies the same retry count, event age, failure destination, filtering and tracing as live traffic, so a replay that fails again is caught and recorded the same way. A direct invocation bypasses those settings, and a hand-built payload can drift from what the source would have sent.
- How do you find events that failed but never reached the failure destination?Reconcile against the source of truth. List the orders created in the outage window from the order store and compare them with what each downstream holds. Anything missing downstream and absent from the destination was dropped silently, by a function without a destination, a destination outage, or expired retention, and is rebuilt from the order store.
- The failure destination always holds every event the outage failed.
- Replay everything at once to clear the backlog before live traffic peaks.
- Invoke the function directly with each payload; the normal path adds nothing.
- Delete records from the destination before the replay run starts.
- Every replayed event should be applied, because replay must reproduce history.