Module Integration
Understand how synchronous communication among components operates in our modular monolith application.
We'll cover the following
All interactions between the modules are entirely synchronous and communicate via gRPC. With a distributed system such as our modular monolith application, there are two reasons that bounded contexts will need to integrate:
They need data that exists in another bounded context.
They need another bounded context to perform an action.
Using external data
When a bounded context needs data belonging to another bounded context, it has three options:
Share the database where the data is stored.
Push the data from the owner to all interested components.
Pull the data from the owner when it is needed.
The first option should be avoided in most situations, especially if changes are being made from more than one location. Rules surrounding invariants may not be implemented correctly or at all in every location.
When we push data out, we send it to a list of known interested components. This is a maintenance nightmare. The larger the number of components, the harder it will be to keep these lists correct.
Pulling data avoids having to deal with maintaining a list, but the trade-off is that there will be more calls and a greater load put on the component that owns the data. Caching the data can help, but that inevitably leads to issues with invalidating stale cache data.
Tip: Given the options, pulling data is the better choice in most cases. The local component can be written to be ready for failures with retry logic, circuit breakers, and other mechanisms.
Adding items to a basket
An AddItem
request contains a product identifier and a value for the quantity of items to add. To complete the request, the Shopping Baskets module will need additional information for both the product being added and the store it is sold from. This information is pulled from the Store Management module the moment it is needed. The following logs show the calls made during an AddItem
request:
Get hands-on with 1400+ tech skills courses.