Sales,invoice,shipping services example

This example is based on Udi Dahan's blog post SOA, EDA, and CEP a winning combo (2008)

There are three business services: Sales, Inventory, and Shipping.

Steps:

  1. Application sends an order to the sales service
  2. Sales service:
    1. validates the order
    2. publishes an OrderTentativelyAccepted event
  3. Inventory service:
    1. consumes the OrderTentativelyAccepted event
    2. checks if it has everything in stock for the order
    3. for items/quantities not in stock, it starts a long running process which watches for inventory changes
    4. when all stock allocated it publishes an InventoryAllocatedToOrder event
  4. Sales service:
    1. consumes the InventoryAllocatedToOrder event
    2. publishes an OrderAccepted event
  5. Inventory service:
    1. consumes the OrderAccepted event
    2. generates the pick list to bring all the stock from the warehouses to the loading docks
    3. publishes the PickListGenerated event
  6. Shipping service:
    1. consumes the PickListGenerated event
    2. starts the yard management necessary to bring the needed kinds of trucks to the docks

Note that in practise it's somewhat more complex than this. Given the inherrent complexity of the business, it's important to use straightforward technical solutions.

EDA using events as messages is not the simplest approach.

In the example above, only the orders received by the Sales service which pass validation cause an OrderTentativelyAccepted event to be raised, to be consumed by the Inventory service.

Rather than use event messages, this can instead be achieved by having the Sales service define a read-only view named OrderTentativelyAccepted which is a derived relvar defined as a restriction on the OrdersReceived events according to whether they pass validation.

    view OrderTentativelyAccepted = OrdersReceived WHERE <validation>

Rather than have the Inventory service consume event messages, it instead has access to the OrderTentativelyAccepted view. The Inventory service declares an insert database trigger on this view to process orders that have been tentatively accepted by the Sales service.

See the recommended approach to implementing long running business processes.