Inventory, Pricing and Product Catalog communication

domain-driven-designevent-sourcing

Imagine that I am creating and Ecommerce application. For sake of simplicity, I will describe only 3 bounded contexts.

  1. Product Catalog: it's responsible for maintain product descriptions, characteristics and so on
  2. Pricing: it's responsible for products pricing
  3. Inventory: it's responsible for inventory management. If a product is in stock or not.

So when a customer just enter the Ecommerce site, I would like to show the products. For that I need to have the price and still needs to know that if we have the product in stock.

So what's is the best way to do that?

  1. First approach is the Product Catalog just make synchronous requests to Inventory and Pricing.
  2. Second approach is to maintain the price information and if the product has in stock on the Product Catalog BC. So every time a price is changed in Pricing Context it will raise and event and the Product Catalog can update this information. The same way for Inventory context.

I prefer the second approach, but it seems that I am replicating information e.g price and stock.

Thoughts?

Best Answer

I would definitely try to avoid Option #1. Synchronous dependencies between services are an anti-pattern and just complicate operations.

Replicating information is not a bad thing in itself, when there is a clear producer and consumers. Although it should be kept low as possible, I would have no problem having data replicated.

The point is, when other services might be down or overloaded, the product page would still work. This is a good thing you probably want for an e-commerce site.

The downside is, that the information on that page could be somewhat out-of-date. That is normally not a problem, since you will see the exact information when you switch from "browsing" to actual checkout, which should be another application with the "master" data.

Of course there is always the third option, to try to re-arrange the service boundaries in a way which does not require that much data to be replicated.

Related Topic