This project comes from a question in the Booster's Discord channel. This code takes eventual consistence into account, taking advantage of Booster's default sharding capabilities to build batches of items on the fly without external transactional counters (which would limit the throughput significantly). It is intended only as a proof-of-concept. It hasn't been tested and should only be used at your own risk.
To solve this problem we do the following things:
- The
CreateItem
command registersEventCreated
events. - The
EventCreated
events are reduced and accumulated asItem
instances in theItemBuffer
"singleton entity". - The
EventCreated
events also trigger theUpdateBatch
event handler. - The
UpdateBatch
event handler checks the current state of theItemBuffer
singleton entity. If there's a completed batch, it register aBatchCreated
and aCloseBuffer
events. - The
BatchCreated
event creates a newBatch
entity including all the items buffered to that point, which is then projected to theBatchReadModel
and becomes readable via API. - The
CloseBuffer
event "resets" the buffer, deleting the completed batch and increase the batch counter.
Improvements and suggestions are more than welcome!