How it works...

This recipe builds on recipes that we have already covered. We submit an order domain object using database-first Event Sourcing, and we have a query function to retrieve the current status of the order. The listener function is the most interesting part of this recipe. It listens for the reservation-violation events and performs a compensating action. In this case, the compensation is simply to change the status to cancelled. Compensating actions can be arbitrarily complex and are specific to a given service. For example, a service may need to reverse a complex calculation, while accounting for intermediate changes and triggering cascading changes as well. The audit trail provided by Event Sourcing and a micro event store ...

Get JavaScript Cloud Native Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.