LostInComputer
LostInComputer

Reputation: 15420

Event sourcing - How to recover missed events

Lets say that I have two aggregates deployed in two separate services. Aggregate 2 listens to the events of aggregate 1.

When I stop aggregate service 2 for a long time, how do I recovery all the missed events?

  1. Retrieve all missed events from aggregate 1 event store?
  2. What if aggregate 1 already accumulated a lot of events. Is aggregate 2 allowed to use aggregate 1's snapshot?

Upvotes: 2

Views: 707

Answers (2)

James Nugent
James Nugent

Reputation: 816

Retrieve all missed events from aggregate 1 event store?

Yes, this would be the general approach. At an infrastructure level, you can remember the last seen sequence number, and then request that events since then are pushed to you.

What if aggregate 1 already accumulated a lot of events. Is aggregate 2 allowed to use aggregate 1's snapshot?

The answer here is probably not - if the two are able to share a snapshot, it may be worth reconsidering whether or not the aggregate boundaries are correct in the first place. However, it really depends on the nature of the feed from aggregate 1. I'd generally avoid this unless you actually run in to problems where it becomes necessary.

Upvotes: 1

Giacomo Tesio
Giacomo Tesio

Reputation: 7210

1) Retrieve all missed events from aggregate 1 event store?

Yes.

2) What if aggregate 1 already accumulated a lot of events. Is aggregate 2 allowed to use aggregate 1's snapshot?

Yes.

However, in an heavily disconnected context that priviledges partition tolerance over consistency, you have to arrange compensating actions for all events handled by the aggregate 2. Indeed you can encounter situations where events that have been handled by aggregate 2 would have not been possible if it had recieved properly the events from the aggregate 1.

Upvotes: 1

Related Questions