As simple as... the Inventory bounded context

Subscribe to my newsletter and never miss my upcoming articles

Last weekend I went to the dynamIT conference that took place in Kraków. In his presentation, Andrzej Krzywda was speaking about DDD as Low-Code. He distilled 11 bounded contexts that are common in the different business applications. One of them is the Inventory bounded context which I have implemented in the Rails Event Store e-commerce module. There are few things to keep in mind about the Inventory.

  • Not all products need to keep track of their inventory level. Consider electronic products like ebooks. The sellers usually don't want to limit purchases for that kind of goods. But sometimes they do. I personally distinguish between empty stock and undefined stock as this is a pretty flexible solution. If the stock status is undefined, then we consider the goods to be available.

  • Warehouse operations do not have an atomic nature. This is why we should provide a reservation concept. The goods can be reserved and still remain in the warehouse. The actual availability is the difference between the stock level and the reservation count.

  • Reservation can be often mapped one-to-one to the Order, but remember we stay in the Inventory bounded context and it has its own ubiquitous language. Separation of these contexts may pay off in the future. I can imagine the part of the stock being reserved for giving away for promotional purposes.

  • When it comes to real things it is crucial to have a reliable audit log. The business must have an insight into the history of warehouse events. That is what you get for free with event sourcing - a full history of how the stock level has been changing over time and why.

Having these things in mind your Inventory bounded context can be as simple as 5 commands and 2 aggregates.

Zrzut ekranu 2021-08-31 o 21.30.14.png

 
Share this