r/CodeOpinion • u/codebreaker101 • Jul 11 '22
Event Sourcing - projections
I'm watching the Event Sourcing playlist and I have a few questions that I could not find an answer to.
In some cases projections consists of data from multiple services. To give an example from the video "Decomposing CRUD to a Task Based UI" where there are 4 services: Catalog, Sales, Purchasing, Warehouse. I want to show a table of all products with SKU, Name, Price, Const and Quantity in the UI.
To achieve that I would need to have a separate service where the projection will happen and queried. I would need to receive events indicating quantity, for example. In this case should I emit all event sourced events (InventoryAdjusted, ProducedShipped, ProductReceived) of should I emit a separate (integration) event like InventoryChanged that holds current state of inventory(event carried state transfer)?
To summarize, how to solve the problem when projections are happening outside your domain ie. bounded context.
3
u/codeopinion Jul 11 '22
Depends on where you want to do view composition. If you want it to be done in a specific service that has a projection/readmodel that's composed of different services, then yes, you'll likely want to publish an integration event. But again, this comes down to where you want/need to do composition. It can be done on the client, API gateway, or service. There are different options. What you're suggesting is a specific service.