I’m trying out projections and have several questions regarding their proper usage:
-
What’s the recommended size of a projection state (roughly range up to <100Kb/<1Mb…).
-
Somewhere on the mailing list there was a thread (https://groups.google.com/forum/?fromgroups=#!searchin/event-store/millions/event-store/w98t-E8roFI/Cvpugv82Jq0J) asking about the viability of millions of projections. Considering a domain of banking and a projection which shows aggregated customer data for each customer, would I be creating a separate projection instance for each customer dynamically, e.g.
fromStream(‘customer-1’).when(…) queried as projections/customer-1/state, where the projection itself is somehow (?) created on the fly when a new CustomerCreated event is registered.
or should I use partitions:
fromAll().partitionBy(function(e) { return e.body.customerId }).when(…) queried as projections/customer/state?partition=1
- Related to the previous question, having the following events
- CustomerCreated { customerId }
- AccountOpened { accountId, holders: [set of customerId] }
What would be the simplest way to create a CustomerAccounts projection? Is it
fromCategory(‘account’).when({AccountOpened: function(s, e) {
for (var holder in e.body.holders) {
emit(‘customer-’ + holder, ‘CustomerAccountOpened’, { customerId: holder, accountId: e.body.accountId });
}
})
fromCategory(‘customer’).partitionBy(function(e) {
return e.customerId
}).when({CustomerCreated: function(s, e) {
s.id = e.body.customerId
},
CustomerAccountOpened: function(s, e) {
s.accounts.push(e.accountId)
})
The problem with the above is that every event which doesn’t contain a customerId needs to be translated with an additional projection. If there are lots of such events it’s probably simpler to hold the projection in a document store and project events by hands instead of creating eventstore projections which only emit integrating events. Am I missing anything here?
Thanks.