Materialized Views¶
When reading data, we will soon realize that we need to merge results from multiple Backend Services responses in order to generate a coherent response for our Application Services/BFF.
We mentioned before that the API Gateway has the functionality to perform API Composition. However, it needs to be used with caution, since it generates coupling between Services. But we still need the data! Then let's couple the data itself :).
In order to increase reliability, and in order to decrease latency we can create Materialized Views. This is a term taken from the Command Query Responsibility Segregation (CQRS) pattern, which is basically what we are doing here: we are separating writes from reads.
We can create a service which has its own database (we may consider a NoSQL database for this?) whose only purpose is to keep it updated with the data from the services that are needed to compose what the Frontend needs.
This is quite useful for analytics, searching, indexing etc.
Something important to keep in mind is that these kind of services should be able to be recreated from the source of truths. It's data is really just a mirror.