Data Replication, Bounded Contexts, & Protocols
In this lesson, we'll study data replication, bounded contexts, and protocols.
We'll cover the following
Data replication and bounded context #
Asynchronous communication becomes more complicated if data is required to execute a request.
For example, in the catalog, the order process, and the invoice data about products and customers has to be available.
Each of the systems stores a part of the information about these business objects.
- The catalog must display the products, so it has pictures and descriptions of the products.
- For invoices, prices and tax rates are important.
This corresponds to the definition of bounded contexts.
Each bounded context has its own domain model. That means that all data for the bounded context is represented in its domain model. Therefore, the data specific for the bounded context should be stored in the bounded context in its own database schema.
Other bounded contexts should not access that data directly, which would compromise encapsulation. Instead, the data should be accessed only by the logic in the bounded context and its interface.
Although it would be possible to have a system that contains all information about, for example, a product, this would not make a lot of sense. The model of the system would be very complicated.Also, it means that the domain model would be split across one system for an order process and another system for the product data. That would lead to a very tight coupling.
A third system, such as registration for customer data or listing for product data, must accept all the data and transfer the needed parts of the data to the respective systems. This can also be done asynchronously.
The other bounded contexts then store the information about products and customers in their local databases, making replication a result of events being processed. An event such as “new product added” makes each bounded context add some data to its domain model.
Registration or listing do not need to store the data. After they have sent the data to the other microservices, their job is done.
It is also possible to do an extract-transform-load approach. In that case, a batch would extract the data from one bounded context, transform it into a different format, and load it into the other bounded context. This is useful if a bounded context should be loaded with an initial set of data, or if inconsistencies in the data require a fresh start.
Get hands-on with 1200+ tech skills courses.