Prompt
How do I troubleshoot failed event replays after a schema change?
Latest observation
When event replays fail after a schema change, the issue is usually that historical events no longer deserialize cleanly into your new model. A good way to troubleshoot it is to check compatibility, serialization behavior, and replay scope.
1) Identify the exact failure
Start by finding:
- the exception type
- the event type being replayed
- the timestamp/version of the event stream
- the field or type causing the failure
Common errors include:
- missing required fields
- renamed fields not mapped
- enum/value changes
- type changes (
int→long, object shape changes, etc.) - deserialization issues due to version mismatch
2) Compare old vs new schema
Check whether the schema change was:
- backward compatible: new code can read old events
- forward compatible: old code can read new events
- breaking: field removed/renamed/type changed without migration
Typical breaking changes:
- removing a field that replay logic still expects
- renaming a property without aliasing/backward mapping
- changing a field from optional to required
- changing nested object structure
- changing enum names/values
3) Inspect the raw historical event payload
Look at the actual stored event data, not just your current model:
- Is the old field still present?
- Is the format different from what the new code expects?
- Is there malformed data from earlier versions?
- Are there nulls where the new schema expects values?
If possible, replay one event manually in a test environment to isolate the failing record.
4) Check serializer/deserializer settings
Many replay issues come from serializer configuration rather than the domain model itself:
- strict missing-member handling
- case sensitivity
- property naming policy
- versioning annotations
- default value handling
- type discriminators for polymorphic events
If using JSON, check for:
- renamed properties
- constructor binding issues
- null handling
- enum string vs numeric representation
5) Add versioning or migration support
If the schema changed intentionally, you may need one of these approaches:
A. Keep events backward compatible
Make new code tolerant of old events:
- make new fields optional
- provide defaults
- preserve old property names via aliases
- avoid removing fields immediately
B. Introduce event upcasting
Transform old event payloads into the new shape during replay.
C. Migrate stored events
Run a one-time migration to rewrite old events into the new schema.
D. Use versioned event contracts
Store an explicit schema/event version and branch deserialization logic accordingly.
6) Verify replay code handles old states
Sometimes the event is valid, but your replay/projection logic assumes a newer state shape:
- aggregate state may not initialize correctly
- projections may assume a field exists
- handlers may not handle legacy event variants
7) Replay in smaller batches
If the replay is large:
- replay per aggregate or partition
- process events in chunks
- log the last successful event before failure
This helps pinpoint which event version breaks the replay.
8) Add tests for historical compatibility
Create regression tests using:
- archived event samples from before the schema change
- fixture payloads from production
- deserialization tests for old and new versions
This prevents future schema changes from breaking replay.
9) Use observability
Add logging around:
- event type
- event version
- payload schema version
- deserialization exceptions
- replay offset/position
This makes it easier to see whether the issue is isolated or widespread.
10) Common fixes by symptom
- Missing field → make it optional or supply a default
- Renamed field → add backward-compatible mapping
- Type mismatch → implement conversion logic or upcasting
- Enum failures → allow unknown values or map old names
- Polymorphism errors → ensure type discriminator compatibility
- Handler failures → make replay logic tolerant of legacy state
If you want, I can also give you a step-by-step replay troubleshooting checklist or a language-specific example for systems like Kafka, EventStore, Axon, .NET, or Java.