Stateful Model Translation
For more significant model transformations—for example, when the translation mechanism has to aggregate the source data or unify data from multiple sources into a single model—a stateful translation may be required. Let’s discuss each of these use cases in detail.
Aggregating incoming data
Let’s say a bounded context is interested in aggregating incoming requests and pro‐ cessing them in batches for performance optimization. In this case, aggregation may be required both for synchronous and asynchronous requests (see Figure 9-7).
![]() |
Another common use case for aggregation of source data is combining multiple fine- grained messages into a single message containing the unified data, as depicted in Figure 9-8.
![]() |
Figure 9-8. Unifying incoming events
Model transformation that aggregates incoming data cannot be implemented using an API gateway, and thus requires more elaborate, stateful processing. To track the incoming data and process it accordingly, the translation logic requires its own per‐ sistent storage (see Figure 9-9).
![]() |
Figure 9-9. Stateful model transformation
In some use cases, you can avoid implementing a custom solution for a stateful trans‐ lation by using off-the-shelf products; for example, a stream-process platform (Kafka, AWS Kinesis, etc.), or a batching solution (Apache NiFi, AWS Glue, Spark, etc.).
Unifying multiple sources
A bounded context may need to process data aggregates from multiple sources, including other bounded contexts. A typical example for this is the backend-for- frontend pattern,1 in which the user interface has to combine data originating from multiple services.
Another example is a bounded context that must process data from multiple other contexts and implement complex business logic to process all the data. In this case, it can be beneficial to decouple the integration and business logic complexities by front‐ ing the bounded context with an anticorruption layer that aggregates data from all other bounded contexts, as shown in Figure 9-10.
![]() |
1 Richardson, C. (2019). Microservice Patterns: With Examples in Java. New York: Manning Publications.
Figure 9-10. Simplifying the integration model using the anticorruption layer pattern