Take this small example of a Sale
SaleStartedEvent { startedDate : whatever }
LineEvent { id : 1}
LineEvent { id : 1}
LineEvent { id : 1}
LineEvent { id : 1}
LineEvent { id : 1}
SaleCompleted { completedDate : whatever }
We want to make it easier for consumers of SaleCompleted to get information about the Sale which completed (number of items, voids, promotions etc)
Here are the options I think that are available, and wouldn’t mind hearing other people’s views
Option 1 - Projections
Each sale has it’s own stream, so we could use a partition for each Sale.
if the event being processed in the projection is SaleCompleted, transform into EnrichedCompletedEvent (we would hold the other parts of the Sale in the state)
Does a partition run in-memory at all times?
Say we have 20 million Sales, would we have 20 million partitions in memory for ever?
Or (fingers crossed) are partitions only held in memory while access, then they drop off at some point.
The partition streams which are built by the projections, would they be truncated eventually, and what would they take up a lot of disk space (remeber we are talking millions of streams)
Option 2 - Enriched Completed event
When we persist SaleCompleted to the EventStore, we just enrich it then.
It’s very simply, and we have all the information we need to add in.
Anyone susbcribing to $et-SaleCompleted gets this nice enriched event.
Downside is if we need to change the shape of this event. Realistically, only the events going forward would
have the changes. It wouldn’t be easy to replay (we might be able to frig something with a projection)
Option 3 - Consumer asks for latest Sale on receipt of Completed event
We send out our slim SaleCompleted to consumers. if they want more information about the sale, they then hit the BC REST endpoint
GET api/sales/:id
Where we rehydrate the Sale, and return the latest, meaning if we make any changes they always get the latest payload.
The downside here is the amount of traffic hitting the Sales BC. Again, we are talking million of sales flowing through the system,
and each time a Sale is completed a further round trip (per consumer) would be required.
The REST endpoint and the EventStore would be taking a beating here.