Event Driven Architecture Examples
What are some examples that event driven architecture would help with?
Travel
Imagine all of the dependencies on an airline flight. Your rental car company could register to be notified that your flight is running late so that they can give the car reserved for you to someone else and reserve a later car for you. Your hotel could register for notification so that if your flight is canceled, the hotel cancels your reservation that night. Your travel agency could register so that if your flight is late or canceled, it can rebook your flight or connecting flight, make you a hotel reservation in your connecting city, maybe even notify the host of the meeting you're supposed to attend that you're going to be late.
In all these cases, the airline doesn't have to know any of these details. It just has to announce the flight delay or cancellation as an event. The event will be announced to everything which says it's interested in that flight, which may be no one, or may be several agents for each passenger on the flight. The event consumer decides how to react, in as simple or complex a manner as it wants to.
This can be used to enable a more complex system to more dynamically adjust. A delayed fight means that the plane's subsequent flights will be delayed, its airport gate and ground crew are now available but another needs to be reserved for later, the flight crews will be delayed for their connections and may overrun their work limits for the day. New planes and/or crews may need to be allocated. Some connecting flights may need to be delayed while others that can't be delayed can have seats released to standby passengers.
Imagine trying to code one central rescheduler with a whole bunch of if-statements to figure out how to dynamically adjust everything. What a mess! But with events, everything is notified concurrently. Each consumer can make its own decisions on how to adjust, which is a much simpler solution to implement.
Financial
Imagine the financial industry. You can schedule to buy or sell a security at a certain price, or a certain time, or when an analyst changes their recommendation. When a bond or CD matures, an agent (person or computer) can be notified to decide how to reinvest the funds.
Without events, how would you implement this? You could have lots of portfolios polling for lots of prices/times/recommendations. They'd usually find that no thresholds have been passed. And if the polling interval were too long, they might find that a threshold was passed a long time ago and that now the price is much worse. Alternatively, a central stop-loss manager could query for all portfolios with a security and a limit on that security. Again, this approach would be wasteful and not timely.
As with travel, financial events simplify implementation. If you want to sell a stock if it falls below a certain price, your portfolio object can register for a SELL event (or maybe just a PRICE event) when that stock hits that price. When it receives the event, it sells the stock. For the system that tracks stock prices, it doesn't have to know why subscribers want these announcements; it just has to send the announcement when the event occurs. The consumers decide how to react; they may even decide to do nothing.
Insurance
A mortgage company wants to make sure you have homeowner's insurance, so they could register for notification if your policy is canceled. They could also register for notification when a renewal is due and confirmation when the renewal is complete.
Similarly, your Department of Motor Vehicles
wants to know that you and your car are insured, and would want notification if your policy expires. For that matter, the DMV would also want notification from the Department of Revenue when you pay or if you fail to pay taxes on you car, if your car's registration and license plate
expire, and when you get (or fail to get) your emissions inspection certificate renewed.