This article reprinted from decoupling 】 【 how: https://codedecoupled.com/php…
In an event traceability architecture, where capturing the current state of an application through a stream of events can cause performance problems, a Projector listens for events and generates a separate view of the current state of the application. You can think of it as a materialized view of a database, or a kind of cache.
The following are several Projector use cases drawn from our real-world experience.
Practical use cases
The query model
We can use Projector to generate a query model that serves users who are demanding a quick response time to the page.
It is worth mentioning that Projector can use a different method for persisting data than event streams. For example, event streams are stored in MySQL. Projector can use Elastisearch persisting query model:
Let’s look at a simple example of using Projector to generate an order query model:
Support business implementation
We can use Projector to generate a Repository similar to a buffer when other customers need to obtain the current status of the application in a timely manner but cannot deliver it through simple events. This Repository will provide timely application state for implementing business logic.
Let’s look at a simple example of using Projector to generate a vehicle reservation Repository:
It is worth noting that such use cases tend to favor synchronous processing schemes because they are generally more time-sensitive.
conclusion
Projector is a simple and powerful pattern with a single, focused responsibility that makes it easy to write unit tests.
This article reprinted from decoupling 】 【 how: https://codedecoupled.com/php… If you are also interested in TDD, DDD and clean code, please follow the public account “How to Decouple” to explore the way of software development.