Creating a State Machine Saga With MassTransit (Orchestrated Saga)

  Рет қаралды 13,778

Milan Jovanović

Milan Jovanović

Күн бұрын

Пікірлер: 72
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
Get the source code for this video here → the-dotnet-weekly.ck.page/masstransit-saga Want to master Clean Architecture? Go here: bit.ly/3PupkOJ Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt
@dcernach
@dcernach 5 ай бұрын
The most clear crystal video I've seem about MassTransit Sagas. This video must referenced on masstransit documentation. Great video as well. Please, bring us a video about the MassTransit Courier Service, it is great for distributed transactions with compensation routines!
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
I think it would've been even better if I had used separate services for each handler. But I felt that would overcomplicate the matter and distract the user from the actual Saga pattern. I'm glad that you enjoyed this one :) P.S. Thanks for the video suggestion!
@aakashpoojary3968
@aakashpoojary3968 4 ай бұрын
@@MilanJovanovicTech It would had been far better, if handlers would had been split in to 3 different services. It somewhat simulates the real world applicatoin, just my thoughts.
@baranacikgoz
@baranacikgoz 5 ай бұрын
Great video. This concept feels like "do I really need this? Can't I create an entity and update it with its methods instead?" But I think if you make another video about implementing a complex flow with traditional ways and saga pattern in the same video and show differences, people will have an "ahaa" moment
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
That's a great suggestion for a future video!
@stephendgreen1502
@stephendgreen1502 5 ай бұрын
The best topic you have covered, in my opinion. Very much appreciated.
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
Now I need to move these handlers into separate services, and add distributed tracing on top.
@stephendgreen1502
@stephendgreen1502 5 ай бұрын
@@MilanJovanovicTech And hire some code-skilled support engineers to deal with data lossiness.
@stephendgreen1502
@stephendgreen1502 5 ай бұрын
@@MilanJovanovicTech There are two big weaknesses with sagas. One is the expertise required to write and maintain them well. The other is that they can never plug all the data leaks: There are always edge cases where data gets lost. The workflows are partly non-deterministic because they are weakened by issues such as latency, plus the workflows tend in some cases to never complete such as with timeouts.
@PhatBoyG
@PhatBoyG 5 ай бұрын
@@stephendgreen1502 if you end up with "data leaks" in your system, it's a result of poor programming, not message loss. There are many companies using extensive sagas with MassTransit that have no lost transactions, and they're doing 400,000 an hour in real-time. So, your experience may vary, but blaming the technology/pattern is misguided.
@drhdev
@drhdev 5 ай бұрын
I would definitely pay for a MassTransit course. Chris's videos are great, but would love some more real examples of Routing Slips (Choreography) and State Machines (Orchestrators). State/Status/Processing steps are one of my biggest struggles. Would love to know more using examples like Invoices/Reserving Inventory/Billing Customer/Shipping Items/etc. Also would be helpful if you explained how to correlate using an integer as an Id.
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
Noted! Maybe I can do a longer YT video first, and see how that goes.
@TuanNguyen-ed9rb
@TuanNguyen-ed9rb 4 ай бұрын
I find Chris' videos are hard to follow for beginner
@ryoman76
@ryoman76 5 ай бұрын
Great! Milan Now I am waiting for a video where you explain a video on how to handle an undo/rollback operation
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
Here's the conceptual approach: kzbin.info/www/bejne/fIG5q5isoZuFn5o
@dy0mber847
@dy0mber847 5 ай бұрын
Thanks for valuable content, Milan.
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
Most welcome!
@rconn5641
@rconn5641 5 ай бұрын
Awesome content. I appreciate the effort you put into your videos.
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
Glad you enjoy it! Thanks :)
@Helza99
@Helza99 5 ай бұрын
I don’t know what it is, but for some reason this feels “off”. Just can’t put my finger on it. You have the regular publish/subscribe handlers which all just accept a command and send out a new one, but then you have one central state machine which accepts those and then sends the new publish command. I guess it feels off because it is all an 1-on-1 for the state and commands. You’re pretty much just resending the commands because of that. I guess this becomes a lot more useful with more complex/involved flows and it’s easier to track and continue flows in this way. I guess you made it too simple to follow along 😊
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
I have to make these example simple so that they're easy to demonstrate. Think of an order processing flow online. You have a few steps: - Placing an order - Reserver items on stock - Making the payment for the oder - Shipping the order to the customer This is difficult to implement as one long-lived transaction. Which is why we can introduce a saga (state machine) to manage the individual steps. Moreover, these steps can be handled by different physical services which makes it even harder to track. So a central orchestrator that can tell you the current state of the order processing flow is a unique advantage.
@allen9504
@allen9504 3 ай бұрын
Isn't saga about compensating? Why is a step fails and you need to roll back?
@apatock
@apatock Ай бұрын
Hi Milan, first of all - I like your tutorials very much. There are many of them which helps me out. I have a question: does the saga continues if let's say the process getting stopped between the Welcome and the FollowUp state? If so, does this work automatically or have one to send a message to trigger continuation?
@MilanJovanovicTech
@MilanJovanovicTech Ай бұрын
Yes, if you use a saga persistence mechanism that isn't in-memory. The saga stores the current state, so it can pick up where you left of.
@rakeshkumarreddymudda
@rakeshkumarreddymudda 5 ай бұрын
🫡🫡🫡Hatsoff to you and efforts with quality content that you create.
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
Most welcome! :)
@salihcan1991
@salihcan1991 5 ай бұрын
Thanks Milan. It's very useful video.
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
Glad it was helpful!
@KolpaPlak
@KolpaPlak 5 ай бұрын
super good explanation and nice video edit. perfect
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
Thank a lot!
@carlosportillo6915
@carlosportillo6915 5 ай бұрын
Great video, thanks for sharing
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
You bet!
@tzurdo1
@tzurdo1 5 ай бұрын
Great video, as always :)
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
Thank you! Cheers!
@qua11q7
@qua11q7 5 ай бұрын
Awesome tutorial. I have one question. At 14:34, we see that you landed in the last step, which is OnboardingCompletedHandler. In this step, the Consume method hasn't finished yet. When we take a look at the saga state in DB at 14:41, it is at the Final state, which I assume that the saga has finished. But we haven't still complete the Consume method in the last step. What would happen if the last OnboardingCompletedHandler throws an error? Will the saga state be still Final, how can we detect such issues where the saga seems complete but actually the last step erred. Thank you.
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
"What would happen if the last OnboardingCompletedHandler throws an error? Will the saga state be still Final, how can we detect such issues where the saga seems complete but actually the last step erred" - Yes in this case the Saga would transition to the final state. We can add another step, where we wait for a message while in the Onboarding state. - During(Onboarding, ...) I'll have to do a separate video on error handling, but essentially MassTransit allows you to handle faults whenever you publish a message.
@idgafa
@idgafa 5 ай бұрын
It would be great if you cover also how to rollback if some state we cannot move forward? Is there some builtin functionality also in MassTransit?
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
I did, albeit not with MassTransit: kzbin.info/www/bejne/fIG5q5isoZuFn5o
@s1kky
@s1kky 5 ай бұрын
What a legend!
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
Much appreciated!
@drhdev
@drhdev 5 ай бұрын
I would love if you would go in depth on this topic more. Not very many well made MT vids online.
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
Can do!
@ryoman76
@ryoman76 5 ай бұрын
Hello Milan, I have a question if I need to build a saga between two microservices from A (with its database) to B (with its database) the saga in a clean architecture where should I write it? In microservice A or B? Thanks
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
Which one should control the flow?
@ryoman76
@ryoman76 5 ай бұрын
@@MilanJovanovicTech Microservice A
@novaploca2080
@novaploca2080 5 ай бұрын
I literally been watching tutorials about this last week
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
Cool. Mind sharing a few that you watched? I'd love to see it
@malikbrahimi7504
@malikbrahimi7504 5 күн бұрын
This is what I'm looking for with a POC I want to develop that allows users to define jobs in which one "consumer" is ran after the previous consumer's condition has been met. The only problem is that I need something that is dynamic since the user would be defining these states via UI, is that possible?
@MilanJovanovicTech
@MilanJovanovicTech 5 күн бұрын
Looks like some sort of dynamic saga generator?
@malikbrahimi7504
@malikbrahimi7504 4 күн бұрын
@@MilanJovanovicTech Basically want to create an application where users can define data flows via UI that will allow them to specify logic gates on incoming stream data. I did more digging into it and it could probably be defined with sagas but I think Apache Flink is probably a better choice
@smnb6652
@smnb6652 5 күн бұрын
EDIT: Nvm, forgot the AddConsumers call in the setup. ---- Do you need to start the bus or have a hosted service running or something? If I try this, I don't hit the breakpoint after using bus.Publish, however there are no errors or anything in my logging. Just nothingness.
@MilanJovanovicTech
@MilanJovanovicTech 5 күн бұрын
Glad you have it sorted 😁
@eduardoandrescastilloperer4810
@eduardoandrescastilloperer4810 4 ай бұрын
Why did you declare your commands as records but not your events?
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Easier serialization
@sunzhang-d9v
@sunzhang-d9v 5 ай бұрын
I don't know much about the roles of RabbitMq and Postegresql
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
Research
@emanuelrodriguez3155
@emanuelrodriguez3155 5 ай бұрын
what happens when we face an error during the steps?
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
We have a few options, mainly we want to retry processing the step so we can complete the saga. However, if we can't continue, we can publish a "failure" message and consider how we can reverse the effects of previous steps. Like implementing an "undo" operation.
@roberteru25
@roberteru25 5 ай бұрын
To a compensation
@emanuelrodriguez3155
@emanuelrodriguez3155 5 ай бұрын
@@MilanJovanovicTech would be really interesting a video on how to handle an undo/rollback operation
@dcernach
@dcernach 5 ай бұрын
@@emanuelrodriguez3155 Tottaly agree, in masstransit it is called courier service to handle these cases...
@AndrewCao-iw5by
@AndrewCao-iw5by 2 ай бұрын
I applaud for the effort made for the vide but there are too many topics to explain in a short vide. it is not detailed enough for begineers.
@MilanJovanovicTech
@MilanJovanovicTech 2 ай бұрын
This isn't really a beginner-friendly topic
@geepy5708
@geepy5708 5 ай бұрын
Your videos are getting more complicated 😢
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
The topic is complicated...
@torrvic1156
@torrvic1156 4 ай бұрын
This is a very complicated stuff. Do you think that it is a good idea to use Redis to store SAGAs instead of Ef database Milan?
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Maybe, if Sagas are short-lived. You can always switch it with a SQL DB
The Beginner's Guide to Clean Architecture
13:19
Milan Jovanović
Рет қаралды 28 М.
Saga Pattern | Distributed Transactions | Microservices
17:18
小丑家的感情危机!#小丑#天使#家庭
00:15
家庭搞笑日记
Рет қаралды 34 МЛН
НИКИТА ПОДСТАВИЛ ДЖОНИ 😡
01:00
HOOOTDOGS
Рет қаралды 2,7 МЛН
Build Clean Messaging in .NET with MassTransit
21:44
Nick Chapsas
Рет қаралды 100 М.
Saga Pattern For Microservice Architecture With Rebus And RabbitMQ
18:18
Milan Jovanović
Рет қаралды 28 М.
This Is What MassTransit Does to Your Message Broker | RabbitMQ
14:21
Milan Jovanović
Рет қаралды 10 М.
The AI-Powered VS Code Killer? Checking Out Cursor and AI Coding
26:33
Milan Jovanović
Рет қаралды 20 М.
The New Option and Result Types of C#
15:05
Nick Chapsas
Рет қаралды 74 М.
Microservices with Databases can be challenging...
20:52
Software Developer Diaries
Рет қаралды 69 М.
Microservices are Technical Debt
31:59
NeetCodeIO
Рет қаралды 548 М.
Swagger is Gone in .NET 9! Replace It With This.
9:34
Nick Chapsas
Рет қаралды 53 М.
MassTransit - The New Transactional Outbox
27:40
Chris Patterson
Рет қаралды 13 М.
When Booleans Are Not Enough... State Machines?
21:50
Next Day Video
Рет қаралды 25 М.