Skip to content

Aggregate snapshot versioning#468

Merged
erikrozendaal merged 15 commits intomasterfrom
snapshot-versions
Jun 3, 2025
Merged

Aggregate snapshot versioning#468
erikrozendaal merged 15 commits intomasterfrom
snapshot-versions

Conversation

@erikrozendaal
Copy link
Copy Markdown
Member

To support changing the internals of an aggregate root without having
to throw away the old snapshots the snapshot version can now be
specified. This is needed to be able to support zero-downtime
deployments, where both old and new code run concurrently using the
same event store, but each may require different snapshots.

Example usage:

enable_snapshots version: 2

The default version is 1.

A hash mapping aggregate types to the supported snapshot version is
passed to every database call that needs it so the snapshot can be
correctly selected. The default implementation queries all descendants
of AggregateRoot for the supported snapshot version. This can be
changed using the aggregate_snapshot_versions configuration setting.

@erikrozendaal erikrozendaal changed the base branch from master to register-types-rake-task May 9, 2025 11:32
Base automatically changed from register-types-rake-task to master May 9, 2025 11:42
To support changing the internals of an aggregate root without having
to throw away the old snapshots the snapshot version can now be
specified. This is needed to be able to support zero-downtime
deployments, where both old and new code run concurrently using the
same event store, but each may require different snapshots.

Example usage:

```
enable_snapshots version: 2
```

The default version is 1.
Pass snapshot version information when retrieving and storing
snapshots from/to the database.

A hash of aggregate types to supported snapshot version is passed on
every call that needs it so the snapshot can be correctly
selected. The default implementation queries all descendants of
AggregateRoot for the supported snapshot version. This can be
configured with the `aggregate_snapshot_versions` setting.
When the snapshot format changes for an aggregate that needs
snapshots, a new row is inserted into the
`aggregates_that_need_snapshots` table with the updated version
number. This will cause the snapshotter to select this aggregate to
create a new snapshot with the new version.
This task should be executed when the new code is fully deployed to
all machines, and the other snapshot versions are no longer required.
@erikrozendaal erikrozendaal marked this pull request as ready for review May 19, 2025 14:58
@erikrozendaal erikrozendaal requested a review from lvonk May 19, 2025 14:58
@erikrozendaal erikrozendaal merged commit 7400d75 into master Jun 3, 2025
5 checks passed
@erikrozendaal erikrozendaal deleted the snapshot-versions branch June 3, 2025 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants