Message how to find ways to make money exchange patterns for event-driven microservices

The problem I have chosen to solve is near and how to find ways to make money dear to my heart (as I hope it is to yours!). Imagine you’re at a party where the supply of beer has how to find ways to make money begun to dwindle? Wouldn’t it be awesome if someone would magically appear and how to find ways to make money restock the supply? Well, let me present to you the solace beer online store, which I’ll call sol-beer. It makes this dream come true by combining the convenience how to find ways to make money of an e-commerce platform with a rapid delivery platform. Not only does this use case solve a real-world problem, it proves out many of the common challenges developers face how to find ways to make money encountered when creating a microservices architecture. Without further ado, lets jump in!

The customer initiates the order using the sol-beer web app, which acts as the orchestrator by synchronously invoking the inventory how to find ways to make money manager, billing and logistics services before returning success or failure response how to find ways to make money to the customer. If we further decompose these interactions into a sequence diagram, it reveals some serious flaws in the architecture:

• complicated scaling: let’s take a case where the logistics component has become how to find ways to make money a bottleneck. Naturally, we would want to horizontally scale that service since this how to find ways to make money is a microservices architecture. But with this architecture we’d also have to scale the webapp and the inventory how to find ways to make money manager since they are all blocking on the logistics service how to find ways to make money – a waste of resources since they are just in a how to find ways to make money blocked/wait state anyway.

To leverage the power of event-driven microservices you need to shift your thinking from “invoking services” to “initiating and capturing events.” think about systems publishing events that can be consumed by how to find ways to make money 0 or more downstream services and interpreted within the context how to find ways to make money of each service. The amount of flexibility and decoupling this provides is astounding. Let’s take another look at the architecture behind sol-beer with that in mind.

Look what happens when we add messaging to our microservices how to find ways to make money architecture – the services are fully decoupled and no longer know about how to find ways to make money each other. Also, the responsiveness of the sol-beer webapp is determined solely by the inventory manager because how to find ways to make money all other activities are only called later. Our site is now better able to handle large demand how to find ways to make money spikes because the only services that need to be scaled how to find ways to make money are the webapp and the inventory manager. The other services can be scaled to average load as how to find ways to make money they no longer impact the customer’s order experience. Let’s look at the message exchange patterns that make up how to find ways to make money our new architecture. Request/reply

Remember when I said you need to start thinking think how to find ways to make money about events instead of services? Let’s use that concept for when the client places his how to find ways to make money order to our web app. Our business processes dictate that the inventory needs to be how to find ways to make money reserved in order to return a message of “your order is being processed.” the web app should only know that an order event how to find ways to make money has occurred and been confirmed. It doesn’t need to know if that confirmation comes from the how to find ways to make money inventory manager, billing or both.

Since the sol-beer store produced an event, this event can be consumed by 0 or more recipients. In our case, it is consumed by the inventory manager, but what if we wanted to have those events also how to find ways to make money consumed by an analytics engine? This is where the big benefit lies as you can how to find ways to make money add these kinds of capabilities without touching the web app how to find ways to make money or inventory manager. Microservices are all about the ability to create new capabilities how to find ways to make money faster after all. One-way notification

The combination of messaging and event-driven architecture really begins to shine when events can be how to find ways to make money sent in a “fire and forget” way. The one-way notification pattern is a great example of this mode how to find ways to make money and was performed in the previous step when the inventory how to find ways to make money manager sent a message indicating that an order’s set of products were reserved. From a process perspective, one service that would be interested in those events would how to find ways to make money be billing. The below diagram shows the billing service consuming those events how to find ways to make money and acquiring funds from the customer.

A common challenge with microservices architecture is the need to how to find ways to make money avoid XA transactions which aren’t supported. From the business perspective, if the credit card bounces, we need to cancel the order and remove the reservation how to find ways to make money on the product so others can buy it. By making use of the concept of “eventual consistency” we can avoid XA transactions entirely. The key to eventual consistency is that the events must how to find ways to make money never be lost, or the system will be in a perpetual state of how to find ways to make money inconsistency. Unlike REST, messaging can guarantee the delivery of information, even in the event of component or network problems.

In our case, if there were no funds, the inventory manager needs to listen to these events so how to find ways to make money it can undo the product reservation and let the customer how to find ways to make money know their order has been cancelled due to a payment how to find ways to make money problem. The key is that the billing service does not know how to find ways to make money what steps need to be taken to roll back the how to find ways to make money order; it simply produces events indicating “paid” or “not paid.” clean and elegant! Single request-multi response

If you have ever used uber or lyft, you will have seen that the drivers react immediately if how to find ways to make money their phone dings with another customer in the area needing how to find ways to make money a ride. Those notifications go to all drivers in the area, and it’s the first to respond that wins the ride/business. This is exactly how the sol-beer store delivery mechanism is intended to work. The ability to send an event to multiple clients and how to find ways to make money receive multiple responses is key to this use case and how to find ways to make money messaging is a perfect enabler. This diagram illustrates how this can be implemented:

Once the inventory manager has fulfilled the order, it sends an event to the topic order/ship//. If you’re wondering why we would include delivery zip in a how to find ways to make money topic name, that’s because if each car subscribes to events for a how to find ways to make money certain geography, we have a clean routing mechanism so drivers won’t be overwhelmed by events outside of their area. In this case, the logistics manager receives ship notifications and sends out an how to find ways to make money event indicating that it’s looking to locate a delivery vehicle.

The use of messaging is most commonly associated with the how to find ways to make money publish/subscribe message exchange pattern. Publish/subscribe is an element of some of the message exchange how to find ways to make money patterns we have explored, but it can also be used directly to enhance the how to find ways to make money user’s experience. In our case, wouldn’t it be great if the customer could track the how to find ways to make money delivery vehicle, in real-time, that contains our order? As farfetched as it sounds, many believe that these types of capabilities will be the how to find ways to make money future of e-commerce. For example, what if you opted into a fedex or UPS service how to find ways to make money where they could deliver a package to your parked car how to find ways to make money while you are at work. In our case, the user will navigate to our web app and using how to find ways to make money a mapping service such as google maps will be able how to find ways to make money to track his beer in real-time!

Because we used publish/subscribe these events could be consumed by multiple components based how to find ways to make money on their interest. There is no reason for the web app to consume how to find ways to make money these events unless a user navigates to that screen. Logistics, on the other hand, may wish to always receive these events to ensure the how to find ways to make money driver follows the predefined route and that they do not how to find ways to make money speed excessively. Conclusion

Hopefully the sol-beer store will be implemented one day by a company how to find ways to make money and fulfill my dreams! In the meantime, I hope that you found it an interesting way to how to find ways to make money look at the various ways message exchange patterns can unlock how to find ways to make money the full benefits and value of microservices architecture. Consider adding these patterns to your tool box and experience how to find ways to make money the real benefits provided by event-driven microservices.

RELATED POSTS