Seikho / evtstore

Event Sourcing and CQRS with Node.js and TypeScript
https://seikho.github.io/evtstore
62 stars 5 forks source link

confusion around streams, aggregates and ids #8

Closed oskbor closed 2 years ago

oskbor commented 2 years ago

Hi! Just found this nice little library that I'm now trying out 👍 I started out with looking and toying with your sample code and tried to modify it so that a userId is passed around as well. I'm a bit confused on what the aggregate should be. In my mind I would like to have a stream and aggregate per user (and perhaps also a stream for all users). If I want to build an aggregate per user; do I need a new domain for each user in this case? I'm new to event sourcing, so forgive me if the question is unclear or vague.

br Oskar

Seikho commented 2 years ago

Hi! You can find a small working example using an older version of this library at https://github.com/Seikho/social-network/tree/dev/srv/domain

In this case the userId would be your UserDomain.aggregateId. The aggregateId could be something like a username, email, or a uuid. The events created for the UserDomain would most likely be in the user stream. The streams come into use when we begin creating populators. A User populator would consume all user events in time ascending order. It does this by querying using the stream. I hope this helps.

oskbor commented 2 years ago

Thanks! I figured it out with your help. I was confused since the aggregate id is never touched/seen when writing commands, events and aggregates. 👍