Aggregating with the Reduce pattern
In the previous example of the Cadence pattern, we aggregated the total number of users by accessing the different Distel hotels in the CampaignGrain
class. This will work for scenarios where the system has a small number of grains. It will start to fail with an increase in the number of grains. Moreover, there will be a performance penalty as the grains across the silos start to communicate with a single aggregate grain present in one of the silos.
We overcome this challenge by implementing the Reduce pattern, which introduces a StatelessWorker
grain that collects results from each of the silos. This StatelessWorker
grain then sends the number to the singleton aggregate grain, which may be in a different silo, on a regular basis.
The Reduce pattern has three participants:
- Source Grain or Value Grain: This is the source of the value to which aggregation is applied.
- Subtotal or Intermediatory Grain: This is a stateless worker grain...