Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling multiple event dependency in event-driven architecture

What would be best practice if you have an event-driven architecture and a service subscribing to events has to wait for multiple event (of the same kind) before proceeding with creating the next event in the chain?

An example would be a book order handling service that has to wait for each book in the order to have been handled by the warehouse before creating the event that the order has been picked so that the shipping service (or something similar) picks up the order and starts preparing for shipping.

like image 885
Patrick Avatar asked Jun 15 '16 08:06

Patrick


People also ask

How do you handle errors in event-driven architecture?

The receiving system will processes the request but return an error result. In event-driven systems, the events that carry requests can simply drop a notification into a messaging queue and move on. That means a separate process will be responsible for detecting the error and handling it as appropriate.

Is event-driven architecture tightly coupled?

Extreme loose coupling and well distributed An event driven architecture is extremely loosely coupled and well distributed.

Can event-driven be synchronous?

All asynchronous systems are event driven, but not all event driven systems are asynchronous. This kind of makes sense, if we define synchronous as keeping things in time order. I have also heard other definitions as client and server working with the same "clock", its systems are in "sync".


2 Answers

Another useful pattern beside the Aggregator that Tom mentioned above is a saga pattern (a mini workflow). I've used it before with messaging library called NServiceBus to handle coordinating multiple messages that are correlated to each other.

the pattern is very useful and fits nicely for long-running processes. even if your correlated messages are different messages, like OrderStarted, OrderLineProcessed, OrderCompleted.

like image 111
Bishoy Avatar answered Oct 18 '22 07:10

Bishoy


You can use the Aggregator pattern, also called Parallel Convoy.

Essentially you need to have some way of identifying messages which need to be aggregated, and when the aggregated set as a whole has been recieved, so that processing can start.

Without going out and buying the book*, the Apache Camel integration platform website has some nice resource on implementing the aggregator pattern. While this is obviously specific to Camel, you can see what kind of things are involved.

* disclaimer, I am not affiliated in any way with Adison Wesley, or any of the authors of the book...

like image 24
tom redfern Avatar answered Oct 18 '22 09:10

tom redfern