Search code examples
cqrsevent-sourcingeventstoredb

Should I use one projection per entity or category?


I am coding a new application usign CQRS+ES architecture with Event Store DB. In my app, I have the following streams:

  • user-1
  • user-2
  • user-3
  • ...

Each stream contains all events regarding a given user.

I am now creating a projection called user-account, which consists in basic data regarding my user's account (like first name, email, and others)

What is the optimal way to design that projection?

I should have a single projection for each user, creating projections called:

  • user-account-1
  • user-account-2
  • user-account-3
  • ...

Or a single projection for all user-accounts? Being it a key-value pair record (that may store millions of keys in the future)


Solution

  • You can go with one stream per user. Projections are like dimensions. A user can exist in different "dimensions" (CDC naming) and have a different shape in each.

    Read https://www.eventstore.com/blog/the-cost-of-creating-a-stream