This article is reproduced from [how to decouple]:https://codedecoupled.com/php…
In the event traceability architecture, obtaining the current state of the application through the event flow may cause performance problems. The projector generates an independent view to save the current state of the application by listening to events. We can think of it as a materialized view in a database or a cache.
The following are several projector use cases summarized from our practical experience.
Actual use case
Users have high requirements for the response speed of the page. We can use projector to generate query models that serve users.
It is worth mentioning that the projector can use a data persistence method different from the event flow. For example, the event flow is originally stored in mysql, and the projector can use elassearch persistence query model:
Let’s take a look at a simple case. Use the projector to generate an order query model:
Support business realization
When other customers need to get the current status of the application in time, but cannot transfer it through simple events, we can use projector to generate a repository similar to buffering. This repository will provide timely application status for implementing business logic.
Let’s take a look at a simple case. Using the projector to generate a vehicle orderable Repository:
It is worth noting that this kind of use case tends to the synchronous processing scheme, because its timeliness is generally large.
The projector is a simple and powerful pattern. The responsibility of the projector is single and focused, and it is easy to write unit tests.
This article is reproduced from [how to decouple]:https://codedecoupled.com/php…If you are also interested in TDD, DDD and concise code, please follow the official account [how to decouple] to explore the way of software development.