Suggested approach for idempotent and consistent eventing #50
Replies: 2 comments 6 replies
-
We have a closed issue related tot this: #15 |
Beta Was this translation helpful? Give feedback.
-
Thanks @ayuksekkaya , this is a great question. A few things to cover first:
|
Beta Was this translation helpful? Give feedback.
-
I have some question on how we can make sure that eventing is consistent and reliable. This is what I observed currently:
In Saastack, domain events are handled by sending the event to a service bus (such as Azure service bus), at which point a function is triggered and the worker is activated. This call eventually reaches
DomainEventConsumerService
which then notifies all subscribers of the event and the subscribers can react to it.We are publishing domain events, after the entity has been persisted successfully in the given data store.
We don't seem to be distinguishing between an error on persistence vs an error on publishing events. What I mean by that is that for example in
EndUserApplication
we callvar saved = await _endUserRepository.SaveAsync(unregisteredUser, true, cancellationToken);
which in turn callsvar saved = await _users.SaveAsync(user, cancellationToken);
which in turn callsvar published = await this.SaveAndPublishChangesAsync(aggregate, OnEventStreamChanged, (root, changedEvents, token) => _eventStore.AddEventsAsync(_entityName, root.Id.Value, changedEvents, token), cancellationToken);
.So in this flow we can error out anywhere and cancel the operation, but if the error happens after we persist the aggregate and before we can publish the events, say azure service bus is down, then we don't do anything differently it seems? I couldn't see any recovery steps for this because we are returning the error but the error is not treated differently depending on if it came from publish changes vs persistence changes.
My questions:
Is the implementation of an outbox like pattern left for the consumers? If so, what would be a good way of doing this? Something like hangfire? In that case, would hangfire read and then publish to the service bus? What is the suggested approach for it?
in
DomainEventConsumerService
we have this logic here:The comment says that we are doing a retry loop, but I couldn't find where the retry is happening. Is it at the service bus level? And in order to fix the
but events that were previously successful, will be replayed again next time around!
comment, do we need to handle that individually in each subscriber and make sure that they are idempotent?Beta Was this translation helpful? Give feedback.
All reactions