R
R
RSalo2020-02-05 14:37:56
PHP
RSalo, 2020-02-05 14:37:56

Event Sourcing Projection Transactions?

Hello. Tell me, here I have a Ui layer, from where the controller sends a command to the application layer, which creates an event, and then projects it into a normalized database. Faced a problem when a collision occurs when creating two identical users at the same time. In simple words, the first user registers, saves the registration event and maps the record to the normalized database, while at the same time another user tries to register under the same data and manages to skip saving the event before the first user is mapped to the normalized database. As a result, it turns out that we have one normally registered user and two events. One of the events is correct, and the second, which is not valid. The fact is that you can not delete events, and you can only roll the following. If you roll another event for the aggregate that the user has already been created, then this will imply that this event refers specifically to the context of the first user, and not to the second user's contest. How can such a situation be resolved?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
RSalo, 2020-02-05
@RSalo

All solved the problem. You need to make a separate stream for transactional events. All events that may be subject to collisions are initially saved there, if there is no exception when saving to a normalized database, then somehow link this event to the main stream. If there is an exception, then these events will remain in the stream for the transaction, they will not go anywhere, no matter how many invalid events have been created.

�
âš¡ Kotobotov âš¡, 2020-02-05
@angrySCV

events are "facts", unlike teams, they talk about what has already happened (about history).
you need to first create a user, then record an event about the fact that a user with such and such an id has been created.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question