Projectors for event consumers – event traceability

Time:2022-6-4

This article is reproduced from [how to decouple]:https://codedecoupled.com/php…

Projectors for event consumers - event traceability

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.

Projectors for event consumers - event traceability

The following are several projector use cases summarized from our practical experience.

Actual use case

Query model

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:

Projectors for event consumers - event traceability

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:

Projectors for event consumers - event traceability

It is worth noting that this kind of use case tends to the synchronous processing scheme, because its timeliness is generally large.

summary

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.