Archival and retention
Archival moves aged events out of the hot Cosmos event store into cheaper warm storage, then deletes them when retention expires. The goal is simple: keep the hot store small and fast, hold a replayable copy in warm Blob storage for one year, and delete it afterward — without ever losing or mutating a committed event while it is still within retention.
Status: designed, not implemented. No archive-and-delete workflow is deployed today, so live events remain in Cosmos indefinitely and replay reads live streams. This page is the target design and the step-by-step workflow to reach it.
Retention model
| Tier | Store | Window | Access | Purpose |
|---|---|---|---|---|
| Hot | Cosmos DB event store | 6 months | Command path, Change Feed, point reads | Reconstruction, live projections, recent replay |
| Warm | Azure Blob Storage (Cool tier) | 1 year | Online read for replay and audit | Cost-efficient replayable history |
| Deleted | — | After warm expiry | None | Retention end; audited removal |
The warm copy stays online (Cool, not the offline Archive tier) so a tiered replay can read it directly without a rehydration delay — see hot and cold replay. An event’s total lifespan is about 18 months: six months hot, then one year warm, then deletion.
Design pattern: archive, verify, then expire
The core rule is that TTL is a deletion mechanism, not an archive mechanism. A hot event is only ever eligible for deletion after a verified copy exists in warm storage. The workflow is strictly ordered: copy out → verify → mark for TTL → let Cosmos delete.
Why this ordering matters:
- A crash between copy and verify leaves the hot event in place — safe, re-archived on the next pass.
- TTL is never set on an unverified event, so Cosmos can never delete the last copy.
- Archival is idempotent: re-copying a stream segment overwrites an identical object.
Cosmos DB implementation
Time-to-live (TTL) as the deletion mechanism
Cosmos TTL deletes expired items automatically with no RU cost for the deletion itself. ION uses item-level TTL, not a blanket container TTL, so only verified-and-archived events expire:
| Setting | Value | Effect |
|---|---|---|
Container DefaultTimeToLive | -1 (enabled, no default) | TTL is on, but no item expires unless it carries an explicit ttl. |
Event item ttl | unset while hot | The event never expires on its own. |
Event item ttl | seconds, set after verified archival | Cosmos deletes the item once _ts + ttl passes. |
The archiver computes ttl so the item expires at the six-month hot boundary:
ttl = (archivedAt + remaining-hot-window) − _ts, in seconds. Setting ttl is a
normal document update on the aggregate’s own logical partition, so it does not
touch other streams.
Reading events to archive
The archiver consumes the Change Feed through a dedicated lease container, isolated from live projectors and from replay (same isolation model as replay). Change Feed gives committed, per-partition ordered events, which preserves per-stream sequence in the archive.
Deletions driven by TTL do not appear in the standard latest-version Change Feed, so projectors and the archiver never observe a spurious “delete” event when a hot item expires.
Warm Blob archive layout
Archived events are grouped by stream so a replay can fetch exactly the streams it needs. Each object is append-friendly JSON Lines plus a manifest.
| Element | Convention | Reason |
|---|---|---|
| Container | Per event store (incident, investigation, ticket) | Isolates scaling, access, and lifecycle per store. |
| Blob path | {aggregateType}/{tenantId}/{streamId}/{fromSeq}-{toSeq}.jsonl | Keyed by stream for targeted, tenant-scoped replay. |
| Manifest | {...}/{fromSeq}-{toSeq}.manifest.json | Stream id, sequence range, event count, checksum, schema versions. |
| Tier | Cool | Low-cost online read; replayable without rehydration. |
| Immutability | Time-based WORM policy | Enforces event immutability in the archive. |
| Encryption / access | Managed identity, private endpoint | Same posture as the hot store; no keys or public access. |
Each archived record keeps the full stored-event fields — stream id, sequence, event type, schema version, tenant scope, correlation, causation, and payload — so the archive is self-describing and replayable through the same deterministic readers as the hot store.
Step-by-step archival workflow
- Enable TTL safely. Set the container
DefaultTimeToLive = -1. Confirm no event carries attlyet, so nothing can expire. - Select eligible events. From the archiver’s Change Feed checkpoint, take committed events older than the hot window that are not yet archived.
- Group by stream. Batch events per
streamIdin ascending sequence into a JSON Lines object for a contiguous sequence range. - Write to warm Blob. Upload the
.jsonlobject and its manifest to the Cool tier under the tenant-scoped path, with the WORM policy applied. - Verify the archive (see below). Do not proceed on any failure.
- Stamp TTL in Cosmos. For each verified event, set
ttlso it expires at the six-month boundary. Cosmos deletes the hot copy automatically at expiry. - Advance the checkpoint. Move the archiver lease forward only after the batch is verified and stamped.
- Expire warm copies. A Blob lifecycle-management rule deletes archive objects one year after creation, ending retention.
Verification before TTL
An event is marked for TTL only after the warm copy passes every check:
- Completeness — archived event count equals the source range count; no gaps.
- Order — sequences are contiguous and ascending per stream.
- Readability — objects deserialize through the current schema readers and upcasters.
- Schema coverage — every schema version in the range has a retained reader.
- Tenant scope — the object path and payload tenant match.
- Integrity — the manifest checksum matches the stored object.
If any check fails, the workflow retries or alerts and leaves the hot events in
place with no ttl.
Deletion and offboarding
- Retention expiry. Blob lifecycle management deletes warm objects after the one-year window. This is the normal end of life for an event.
- Customer offboarding and legal deletion. An audited, tenant-scoped deletion workflow removes data across the hot store, the warm archive, and projections through the REST or messaging deletion interface — independent of the retention clock. This is the one sanctioned path that removes events before retention expiry.
Rules
- MUST verify a warm copy exists and is readable before setting any hot-event
ttl. - MUST use item-level
ttl, never a blanket container TTL that could delete unarchived events. - MUST keep the warm archive online (Cool), tenant-scoped, immutable, and replayable through standard readers.
- MUST run the archiver on a dedicated Change Feed lease, isolated from live projectors and replay.
- MUST retain a schema reader for every version present in warm retention.
- MUST-NOT treat TTL as archival, or delete the last copy of an in-retention event.
- MUST-NOT mutate archived events; corrections are new events in the hot store.