Looks overcomplicated to me. Why just save an event in queue (async) or trigger (sync), and if it fails, rollback the transaction?
I wrote such event manager in one single class (about 100 lines) and use it in huge ERP systems with microservices. Some events are sync, some of them async depending on situation.
And why "right order"? You produce only one event "PaymentCompleted". After it processed in warehouse you produce another event "ReadyToLoadItems" and so on. I think you have something wrong with your design if order matters to you.
IMHO: Complicated processes have less chance to succeed and moreover survive over longer period of time.
Thank you for your comment. The example I gave in the article was very simplified just to illustrate the intent. in reality many Wix services work together in a highly distributed fashion in order to achieve a successful ecom flow. it's a global platform with a billion visitors each month.
Wix services don't usually implement the saga pattern (with transaction aborting) but go for best-effort retry mechanism (see more in this post in pattern #4)
The "right order" thing is indeed very important sometimes. Imagine a manufacturer where production is in the sequence of the line. All parts need to be ordered in sequence (== in "right order"). If not, you'll either struggle to resequence ahead of assembling the part or assemble in wrong sequence.
So in some scenarios, "right order" is on of the most important things of the business applications.
You don't use order but event dependency instead. You trigger the second event after the first one is successful. In case of order how do you know that the first one was successful? Order adds complexity. I never use such approach.
If you can provide with such example where my theory, I use in production for years, fails.
9
u/FairKing Aug 15 '22 edited Aug 15 '22
Looks overcomplicated to me. Why just save an event in queue (async) or trigger (sync), and if it fails, rollback the transaction?
I wrote such event manager in one single class (about 100 lines) and use it in huge ERP systems with microservices. Some events are sync, some of them async depending on situation.
And why "right order"? You produce only one event "PaymentCompleted". After it processed in warehouse you produce another event "ReadyToLoadItems" and so on. I think you have something wrong with your design if order matters to you.
IMHO: Complicated processes have less chance to succeed and moreover survive over longer period of time.