Skip to content

Repo-level transaction ID for aggregate loading #9

@bruth

Description

@bruth

This is mostly a question whether it is in scope and/or if you have thought about this use case.

The API supports loading an aggregate at a particular version of itself, but If I wanted to get the state of two aggregates at some point in time, my understanding is that there is no way of doing this since the version is local to the aggregate. Since Repository.Save takes multiple events which may span multiple aggregates, they are being transactionally saved together (at least conceptually) and thus could/should represent an atomic change in state in the repo.

If there was a repo-level transaction id generated (monotonically increasing) on each call and added to each record, then an aggregate can be loaded relative to the transaction id which means the state of all aggregates in the repo could be loaded with respect to some point in time. At that point you could get a copy of the repo "as of" some transaction (or time).

// Initialize.
r := eventsource.New(...)

// Perform 10 calls to r.Save() so tx = 10 by the end

// Get the repo as-of transaction 5.
r5 := r.Asof(5)

bobAt5 := r5.Load(ctx, "bob")
bob := r.Load(ctx, "bob")

A timestamp could be associated with each transaction id so Asof could be a real time.Time rather than the transaction id or AsofT for txid and Asof for time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions