Event store
Azure Cosmos DB for NoSQL is the V3 event-store technology (ADR-0007). It provides single-partition transactional batches, optimistic concurrency, session consistency, Change Feed, autoscale throughput, zone redundancy, continuous backup, and point-in-time restore. Each event-sourced domain uses a dedicated Cosmos account so scaling, access, cost, failure, and recovery stay isolated.
Required capabilities
| Capability | Cosmos implementation |
|---|---|
| Sequential durable write | Transactional batch within one logical partition. |
| Atomic write | All events in a command commit together or none do. |
| Domain aggregate read | Query by stream id, ordered by sequence ascending. |
| Idempotent write | Unique key on stream type + stream id + sequence. |
| Optimistic concurrency | Expected Sequence on append; a conflict fails the batch. |
| Consistency | Session consistency — read-your-writes within a writer session. |
| Subscriptions | Change Feed (outbox), no two-phase commit. |
| Metadata | Event schema carries correlation, causation, actor, and tenant. |
Stream model and partitioning
The logical stream identity is the aggregate, and the partition key is the stream id — one logical partition per aggregate instance:
Partition key / stream id : IonSecurityIncident-{incidentId}
Category : IonSecurityIncident
This co-locates one aggregate’s entire history in a single logical partition, which is exactly what a transactional append and a point stream-read need. The design target is one tenant-scoped partition per aggregate stream. A raw incident stream (~20 events × ~2 KB) is well under the 20 GB logical-partition ceiling.
Rejected alternatives and why:
| Alternative | Why not |
|---|---|
| Tenant-only key | A busy tenant creates a hot partition and unrelated aggregates contend. |
| Aggregate id without tenant scope | Weakens tenant isolation and deletion reasoning. |
| Time-based partitioning | Splits one aggregate’s history across partitions; breaks command-path reconstruction. |
| Shared container with a discriminator | Couples indexing, throughput, retention, and access across unrelated stores. |
If a single aggregate ever grew too large, the correct response is to revisit the aggregate boundary, not to silently shard its stream.
Transactional append
An append runs as a transactional batch on the aggregate’s logical partition:
begin transactional batch (partition = IonSecurityIncident-{incidentId})
read all events for the stream
reconstruct current state by folding the events
run command logic against current state → produce new event(s)
append new event(s) with the next Sequence and the unique key
commit
The unique key (stream type + stream id + sequence) makes a retried append idempotent, and the expected sequence provides optimistic concurrency. On conflict the command handler reloads and re-decides.
Documents, indexing, and snapshots
An event document holds the CloudEvents-compatible fact plus stream identity, sequence, schema version, tenant scope, correlation, causation, and actor metadata. Index only the fields needed for stream loading, supported operational lookup, and Change Feed — analytical scans belong in projections.
Snapshots are designed but not implemented. The reference guidance is that snapshots are unnecessary below ~100 events per aggregate, which is the normal ION case, so aggregates currently fold the full stream. The snapshot design — building from Change Feed, the snapshot document, and using it for state generation — is on the snapshots page.
Change Feed and projections
Change Feed is the outbox for committed events. Independent processors maintain local operational projections or publish versioned integration events to the shared Service Bus namespace. Lease and checkpoint storage are operational state, not domain authority; reprocessing can produce duplicates, so consumers deduplicate on event id or stream sequence.
Most operational and reporting projections use Azure SQL Database. PostgreSQL serves selected AI and Temporal services only. Neither replaces Cosmos as the authoritative store.
Retention
The intended policy is six months hot plus one year cold:
- Change Feed exports eligible events to a tenant-scoped Blob archive.
- The workflow verifies completeness, order, schema metadata, and readability.
- Cosmos TTL removes the verified hot copy after six months.
- The Blob copy stays replayable for one year of cold retention.
- Offboarding and legal deletion use an audited, tenant-scoped workflow across hot events, archives, and projections.
TTL is a deletion mechanism, not an archive mechanism, and may only be enabled as part of the verified workflow. This workflow is not deployed yet, so TTL stays off and live events remain in Cosmos indefinitely (see the section overview). The full pattern, Cosmos TTL mechanics, Blob layout, and step-by-step workflow are on the archival and retention page.
Security and residency
- Managed-identity data-plane access only; connection strings and keys are rejected.
- Private network access only; public access is removed.
- All data resides in Azure Switzerland North / West.
- Customer data is tenant-segregated and deletable via a REST or messaging interface on offboarding.
Recovery boundary
Cosmos event stores use zone redundancy and continuous backup in Switzerland North, which covers node and availability-zone failure. There is no deployed Swiss West event-store replica, so a full-region failure does not currently meet the event-store RPO-0 / 30-minute-RTO objectives. The multi-region designs in ADR-0018 are intended behavior, not the present topology. See replay and recovery.