ThreeDotsLabs / wild-workouts-go-ddd-example

Go DDD example application. Complete project to show how to apply DDD, Clean Architecture, and CQRS by practical refactoring.
https://threedots.tech
MIT License
5.14k stars 472 forks source link

Potentially inconsistent state #14

Closed steven-eckhoff closed 3 years ago

steven-eckhoff commented 3 years ago

Thanks for the project and articles I have been learning a lot from them.

I am studying your transactions in the firestore adapter in trainings. In particular, the call to UpdateTraining from the CancelTrainingHandler seems like it could leave the state of your system inconsistent if the userService command passes, but the command to the trainerService does not. The way it looks to me is that the user would get their balance back and the training would still be scheduled. This would lead to the trainer showing up to a cancelled training or the user getting a free one.

Am I missing something?

m110 commented 3 years ago

Hey @steven-eckhoff, it's great to hear the project was helpful. :)

You are absolutely right, and I'm glad you spotted this. This has been already discussed in the comments section on our blog, so I'll just link Robert's response: http://disq.us/p/2d0c44i

This is one of many subtle issues we introduced in the project on purpose, so they can be then refactored later. We'll cover this in one of future posts.

I already described one of the solutions to this in When an SQL database makes a great Pub/Sub, ("Pattern 2: Transactional Events").

We probably will use another approach in Wild Workouts, though. Thanks for raising this! :)

steven-eckhoff commented 3 years ago

Thanks for the links. I will give them a read.