Projection with foreachStream() on large categories

26 views
Skip to first unread message

Roland Nasr

unread,
May 3, 2020, 2:38:51 PM5/3/20
to Event Store
I’m looking in to using the foreachStream() method in my custom projection and from what I can gather from the documentation is that this should manage an individual state object per stream. I plan to run this on a category which has over 10 million streams in it and I want to track some data that is in the first event of every stream in state so that it can be used in the subsequent event handlers. Is my assumption correct? If so, how well does this scale and will this run continuously while keeping track of all state going forward?

Here is  a basic example where I want to partition my stream of TransactionConfirmed events by UserId, but the UserId is in the TransactionCreated event. (I understand that we could have included the UserId to the Confirmed event to make this simpler)

fromCategory("transactions")
   
.foreachStream()
   
.when({
       
TransactionCreated: function(state, event) {
            state
.userId = event.data.userId;
           
return state;
       
},
       
TransactionConfirmed: function(state, event) {
           
var streamId = "UserTransactions-" + state.userId;
            linkTo
(streamId, event);
           
return state;
       
}
   
});

Reply all
Reply to author
Forward
0 new messages