Replay and reconstruction
Replay re-reads immutable events to rebuild state. It powers aggregate reconstruction, projection repair and rebuild, migration backfill, forensic analysis, and disaster recovery. Replay is a read of committed history — it is never permission to re-run a side effect that already happened.
Every ION replay obeys three rules:
| Pillar | Meaning |
|---|---|
| Scoped | A replay names an exact tenant, aggregate type, stream set, sequence or time range, and schema versions. There is no implicit “replay everything.” |
| Isolated | A replay runs on its own workers, its own Change Feed lease, its own target, and a rate cap. It never shares leases or targets with live projectors. |
| Side-effect-safe | A replay writes only to its declared target. It does not republish reconstructed events to live topics and does not repeat notifications, Sentinel, or ServiceNow writes. |
See the event-replay diagram for the full picture.
Replay modes
| Mode | Input | Output | Side effects |
|---|---|---|---|
| Aggregate reconstruction | One stream, optionally up to a sequence or business time | In-memory domain state | None |
| Projection repair | Change Feed from a checkpoint | Corrected rows in an existing projection | Projection writes only |
| Full projection rebuild | Complete retained history for a scope | A new, isolated projection | Writes to the rebuild target only |
| Migration backfill | Selected historical streams | A newly populated store or projection | Target writes; no domain-event re-emit |
| Integration reprocessing | Selected committed facts | Reconciled external system | Allowed only with destination idempotency and explicit authorization |
| Forensic replay | Immutable event copy | Timeline, diff, or diagnostic state | None |
| Disaster-recovery replay | Restored store + checkpoints | Rebuilt read models | Governed by the recovery runbook |
The replay scope descriptor
A replay is requested with an explicit descriptor. This is the control surface that keeps a replay bounded and auditable.
| Parameter | Example | Controls |
|---|---|---|
tenant | contoso | Blast radius — one tenant by default, never “all” implicitly. |
aggregateType | IonSecurityIncident | Which event store and reader set. |
streamSet | explicit ids, or a filtered id query | Exactly which aggregates. |
fromSequence / toSequence | 0 → end, or a bounded window | How much history per stream. |
fromTime / toTime | business-time or _ts window | Point-in-time replays and audits. |
schemaVersions | v1..v3 | Which readers/upcasters must be present. |
target | isolated projection, cache, or dry-run sink | Where output lands. |
rateCap | e.g. events/s | Protects live-path RU and downstream quotas. |
dryRun | true / false | Report intended writes before any are made. |
idempotencyMode | event id or stream sequence | How the target deduplicates. |
A replay that cannot be expressed in this descriptor is not approved.
Isolation model
Replay runs in a separate lane from live processing. The event store is read-only to the replay; nothing a replay does can slow or corrupt the live command and projection path.
| Concern | Live lane | Replay lane |
|---|---|---|
| Event store | Read + append | Read only |
| Change Feed lease | Live lease container | Separate lease container |
| Workers | Live projectors | Dedicated, rate-capped replay workers |
| Target | Production projection | Isolated rebuild target until cutover |
| Checkpoint | Live checkpoint | Independent replay checkpoint |
How replay reads Cosmos DB
ION replays use the native Cosmos reader that fits the scope.
| Scope | Cosmos mechanism | Notes |
|---|---|---|
| One aggregate | Single-partition query by stream id, ORDER BY sequence ASC | One logical partition holds the whole aggregate. |
| One tenant / many streams | Query the stream-id set, replay each stream in sequence order | Streams are independent and replay in parallel safely. |
| Projection repair / rebuild | Change Feed processor on a dedicated lease container | Isolates progress and parallelism from live projectors. |
| Targeted partition range | Change Feed pull model over a FeedRange | Rebuild a partition subset without scanning the whole store. |
| Point-in-time | fromSequence/toSequence or _ts window filter | Deterministic cut for audit and forensic replays. |
Change Feed exposes committed appends in per-partition order. Because one aggregate maps to one logical partition, per-aggregate ordering is preserved on replay without global ordering.
Deterministic reconstruction
A fold is a pure function of prior state and the next versioned event. It must not read the clock, call another service, generate randomness, or trigger an external action. The replayer:
- validates stream identity and that sequences are strictly increasing with no gap;
- selects the schema reader or upcaster for each event’s type and version;
- folds events in ascending sequence;
- fails loudly on an unknown type or a sequence gap rather than skipping it.
Replayers keep a reader or upcaster for every schema version present in retained history (hot or cold). Introducing TTL or archival does not relax this.
Procedure: projection repair
Use when a projection has drifted or missed events but the projection schema is unchanged.
- Define scope: tenant, aggregate type, stream set, and the checkpoint to repair from.
- Point the repair worker at a dedicated lease so it does not disturb the live projector’s checkpoint.
- Replay from the checkpoint, applying idempotent writes keyed on event id or stream sequence.
- Reconcile: compare aggregate counts and per-stream last-sequence against the event store.
- Advance the live checkpoint only after reconciliation passes.
Procedure: full projection rebuild
Use when a projection’s schema changes or it is corrupted beyond repair.
- Define scope, source streams, schema readers, rate cap, and expected output.
- Create an isolated projection target with the new schema. Do not write into the live projection.
- Replay events in stream order, processing independent streams in parallel within the rate cap.
- Deduplicate on event identity and persist an independent replay checkpoint.
- Validate counts, sequence coverage, domain invariants, tenant isolation, and representative queries.
- Catch up events committed during the bulk replay.
- Switch readers to the new target only after validation, keeping the old target as a rollback path.
- Retire the superseded projection through normal data-lifecycle controls.
A rebuild does not publish reconstructed domain events back to live Service Bus topics; doing so would mix historical facts with new facts and could repeat notifications or external actions.
Procedure: integration reprocessing
Reprocessing to an external system (Sentinel, ServiceNow) is the highest-risk replay because it can produce outbound effects. ION’s backfill guidance is explicit: a blind replay of Sentinel incident events must not re-drive incident status.
- Scope to a tenant and a bounded stream and sequence range.
- Run a
dryRunfirst — produce the exact set of intended external writes and review them. - Require a separate authorization for the live reprocessing operation; it is not covered by a normal projection replay.
- Use the destination idempotency key and reconciliation records so a repeated fact updates rather than duplicates.
- Execute within the rate cap and the provider quota, with dead-lettering for failures.
- Reconcile external state against the event store and record the outcome as new facts — never by rewriting history.
Hot and cold replay
Status: archival not deployed. Live Cosmos history is retained indefinitely today, so replay reads live streams and archive rehydration is not yet required.
Under the intended retention model (six months hot in Cosmos, one year cold in Blob), a replay crossing the tier boundary:
- identifies the required tenant, streams, sequences, and schema versions;
- reads older segments from the verified Blob archive;
- reads the newer segment from Cosmos DB;
- verifies there is no gap or overlap at the boundary;
- feeds both segments through the same deterministic readers.
Blob objects must preserve tenant scope, stream identity, sequence, event identity, and schema metadata; TTL removal is safe only after archive completeness and readability are verified.
Side-effect safety rules
- MUST write only to the declared replay target.
- MUST make projection and integration handlers idempotent on event id or stream sequence.
- MUST
dryRunand separately authorize any replay that can write to Sentinel, ServiceNow, or notifications. - MUST rate-cap replay so it cannot consume live-path RU or provider quota.
- MUST-NOT republish reconstructed events to live topics.
- MUST-NOT re-execute a completed response action because history was re-read.
- MUST-NOT mutate or delete any committed event; corrections are new events.