Hello,
I’m currently having difficulty getting my head around how to model relationships in event store.
I have two entities in my domain EntityA and EntityB. Within my domain model is an event “Linked”, which can be raised against an instance of EntityA. A JSON representation of this event may look like this:
{
“LinkedEntityBId” : “123456”
}
Essentially I am modelling a one-to-many relationship, whereby one instance of EntityA can be linked to multiple instances of EntityB.
When it comes to querying, I am interested in the following question:
- What instances of EntityA are linked to the instance of EntityB with ID “123456”?
I am aware that I could achieve this using a projection:
fromCategory(‘EntityA’)
.foreachStream()
.when(
{
Linked : function(s,e) { linkTo(‘EntityBLink-’ + e.data.LinkedEntityBId, e); }
}
)
I can then extract information from the stream “EntityBLink-123456” to help answer my question.
This could be exactly what I have to do, but I am bothered because:
- There may be millions of instances of EntityA and EntityB in my domain, and hence millions on streams in each corresponding category.
- Every instance of EntityA is linked to a handful of EntityBs, so my projection will create millions of extra streams - each with maybe a handful of events in them.
- There may be other “relational queries” I want to run - if I follow this pattern I will end up creating millions more streams!
I understand that this may not technically be a problem - as eventstore is designed to handle “millions” of streams - but it seems wrong that my stream count increases linearly with the number queries where I wish to query a relationship.
Should I be bothered?!
Lawrence