How to handle duplicate events when replaying event store?

If two aggregates are listening to the same event; then the event will be stored in an event store twice, once for each aggregate.

class ItemLoaded implements Event {
    LocationId location;
    VehicleId vehicle;
    Amount amount;
    Date loadDate;
}

class Location implements Aggregate {
    Amount itemAmount;

    void updateFrom(ItemLoaded event) {
        this.itemAmount.subtract(event.amount);
    }
}


class Vehicle implements Aggregate {
    Amount itemAmount;

    void updateFrom(ItemLoaded event) {
        this.itemAmount.add(event.amount);
    }
}

For instance there will be entries of the ItemLoaded event in the store once for Location and once for Vehicle, in the above case.

This much is expected, as can be seen from the two toy examples below, which you might have already seen if you’ve been reading about event sourcing:

In one example:

_current = new Dictionary<Guid, List<EventDescriptor>>();

In another example:

CREATE TABLE EventWrappers(
EventId uniqueidentifier NOT NULL,
StreamId nvarchar(50) COLLATE Latin1_General_CI_AS NOT NULL,
Sequence bigint NOT NULL,
TimeStamp datetime NOT NULL,
EventType nvarchar(100) COLLATE Latin1_General_CI_AS NOT NULL,
Body nvarchar](max) COLLATE Latin1_General_CI_AS NOT NULL,

Production systems aren’t probably that different. In axon framework event are stored in a table like below, if you choose JPA or JDBC implementation of event store :

create table DomainEventEntry (
    -- .....
    primary key (aggregateIdentifier, sequenceNumber, type)
);

type field above is a string used to differentiate different aggregate types.

Given that events apparently maybe persisted multiple times, if I want to recreate a view from scratch, or add a new view model, how would I replay the events.

If we return to the above example, consider a view model like this:

class ItemsLoadedByYearProjection {
    @Subscribe
    void update(ItemLoaded event) {
        ItemsLoadedByYear row = getRowForYear(event.loadDate.year);
        row.itemAmount.add(itemAmount);
    }
}

class ItemsLoadedByYear {
    int year;
    Amount itemAmount;
}

Not only will the amounts will be counted twice now, if I replay the events naively; if I add a new aggregate in the future, some events will be counted twice, where others will be counted three times.

How do I prevent a projection/denormalizer from double counting the events that was saved to the event store multiple times?

1

If two aggregates are listening to the same event; then the event will be stored in an event store twice, once for each aggregate.

I would spell that differently. If two aggregates are listening to the same event, then representations of that event will appear in the history of each.

They won’t be storing the same event, and the event that they store won’t be the event that they are reacting to.

The aggregates will be storing events describing the changes to their own state, not the changes to state elsewhere in the domain that they are reacting to.

When you get that right, recreating the aggregates is easy – each aggregate loads its own history. There’s no “double counting” to worry about, because each event in the history represents a change to an aggregate, so they are all different things.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

How to handle duplicate events when replaying event store?

If two aggregates are listening to the same event; then the event will be stored in an event store twice, once for each aggregate.

class ItemLoaded implements Event {
    LocationId location;
    VehicleId vehicle;
    Amount amount;
    Date loadDate;
}

class Location implements Aggregate {
    Amount itemAmount;

    void updateFrom(ItemLoaded event) {
        this.itemAmount.subtract(event.amount);
    }
}


class Vehicle implements Aggregate {
    Amount itemAmount;

    void updateFrom(ItemLoaded event) {
        this.itemAmount.add(event.amount);
    }
}

For instance there will be entries of the ItemLoaded event in the store once for Location and once for Vehicle, in the above case.

This much is expected, as can be seen from the two toy examples below, which you might have already seen if you’ve been reading about event sourcing:

In one example:

_current = new Dictionary<Guid, List<EventDescriptor>>();

In another example:

CREATE TABLE EventWrappers(
EventId uniqueidentifier NOT NULL,
StreamId nvarchar(50) COLLATE Latin1_General_CI_AS NOT NULL,
Sequence bigint NOT NULL,
TimeStamp datetime NOT NULL,
EventType nvarchar(100) COLLATE Latin1_General_CI_AS NOT NULL,
Body nvarchar](max) COLLATE Latin1_General_CI_AS NOT NULL,

Production systems aren’t probably that different. In axon framework event are stored in a table like below, if you choose JPA or JDBC implementation of event store :

create table DomainEventEntry (
    -- .....
    primary key (aggregateIdentifier, sequenceNumber, type)
);

type field above is a string used to differentiate different aggregate types.

Given that events apparently maybe persisted multiple times, if I want to recreate a view from scratch, or add a new view model, how would I replay the events.

If we return to the above example, consider a view model like this:

class ItemsLoadedByYearProjection {
    @Subscribe
    void update(ItemLoaded event) {
        ItemsLoadedByYear row = getRowForYear(event.loadDate.year);
        row.itemAmount.add(itemAmount);
    }
}

class ItemsLoadedByYear {
    int year;
    Amount itemAmount;
}

Not only will the amounts will be counted twice now, if I replay the events naively; if I add a new aggregate in the future, some events will be counted twice, where others will be counted three times.

How do I prevent a projection/denormalizer from double counting the events that was saved to the event store multiple times?

1

If two aggregates are listening to the same event; then the event will be stored in an event store twice, once for each aggregate.

I would spell that differently. If two aggregates are listening to the same event, then representations of that event will appear in the history of each.

They won’t be storing the same event, and the event that they store won’t be the event that they are reacting to.

The aggregates will be storing events describing the changes to their own state, not the changes to state elsewhere in the domain that they are reacting to.

When you get that right, recreating the aggregates is easy – each aggregate loads its own history. There’s no “double counting” to worry about, because each event in the history represents a change to an aggregate, so they are all different things.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật