A
A
Alexey Potapenko2020-01-20 01:22:07
Problem-Based Design
Alexey Potapenko, 2020-01-20 01:22:07

How to implement an operation that changes the state of multiple aggregate roots in a distributed database application?

Changing and saving multiple aggregates in one transaction has its disadvantages, the most unpleasant disadvantage: the aggregates must be on the same server (in the same database), otherwise they cannot be saved in one transaction.
Naturally, I don’t need it now and I’m unlikely to need it in the near future, I just really want to know how to solve such problems correctly.
If I understand correctly, then Domain Events and Process Manager are needed for this.
But, to my great regret and surprise, I did not find a normal implementation example anywhere (perhaps I was looking badly). I was especially surprised and upset that there are no examples of a friend system in a social network.
Maybe someone implemented just such a system where you need to change the state of two users at a time, that is, for example, if user1 sends a friend request to user'y2, then this changes his state and the state of user'a2, who receives a friend request (it receives, but does not accept). And if user2 accepts (confirms) a friend request from user1, then they become friends and this also changes the state of both (contain each other's ID).
Or maybe someone implemented user joining a group where, after joining, the user and the group must know each other's ID. Or, in extreme cases, transferring money from one account to another account.
It is very important that the invariants must never be violated, so that there is not the slightest chance of this.
I mean, if, for example, there are two transactions: #1, in which user1 offers friendship and is saved, and #2, in which user2 receives this offer and is also saved, then you need to make sure that no others are performed between them transactions that may affect the outcome of transaction #2. That is, so that it is sequential and in the correct order. I'm not saying it should be, I'm just guessing. Maybe it doesn't have to be sequential and in the right order, maybe it can be done at the same time. I don't know.
I hope, you understood me.
I really want everything to be visual, so that I can see, look and learn, because I still have a lot to do, and I don’t want to spend time on things that I don’t need right now (although I have already spent a lot).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2020-01-20
@mcakaneo

Jimmy Bogart has a series of blog posts on implementing distributed transactions. You can start with them.
https://jimmybogard.com/life-beyond-transactions-i...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question