Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why no CausationId? #9

Closed
lfr opened this issue Jan 26, 2019 · 9 comments
Closed

Why no CausationId? #9

lfr opened this issue Jan 26, 2019 · 9 comments

Comments

@lfr
Copy link

lfr commented Jan 26, 2019

Been reading the doc and I see CorrelationId but no CausationId, is this a deliberate decision? If so, why? Note that it's very likely I would know this if I were more experienced in ES.

@Dzoukr
Copy link
Owner

Dzoukr commented Jan 27, 2019

Hi @LFerrao,

no problem at all :) From what I understand the difference between CorrelationId vs CausationId is that CorrelationId lets you to see all related events, where CausationId is the Id of the initial event (that caused new events created).

Since in this library everything is in developer's hands, it is up to you, how you use this field. You can use Id of triggering event as CorrelationId for chained events so initial event Id is the causation one, and chained events can be correlated by that.

I personally do it rather this way:

  1. I have new event to write into store
  2. Generate new Guid as CorrelationId
  3. Use this CorrelationId for any other events that happened as result of first one
  4. Now I have first event + any chained stored under same CorrelationId, so I can see whole conversation.

What do you think about it?

@lfr
Copy link
Author

lfr commented Jan 27, 2019

I agree that it doesn't seem like you're losing data by not storing it.

Regarding my oppinion I'm not sure I feel uncomfortable leaving it here as I literally just started learning about the topic (both ES and F#), but it's my understanding that an event should have 2 IDs in addition to its own (3 total) from what I read from Greg Young. The correlation ID is the original event ID (allowing to get an entire event tree with a single ID since all messages of the tree share the same correlation ID), and the causation ID is just the ID of the previous message.

Granted, with this definition it seems like you could get one with the other, albeit with some extra query gymnastics and I guess extra RSU cost as well.

@Dzoukr
Copy link
Owner

Dzoukr commented Jan 28, 2019

I think you got point here - the correlationId is good for grouping related events, but the tree view is missing here. I will think about it for next release, however need to think about it more from two perspectives:

  • it would be breaking change (or it would have to be optional)
  • there is no function for getting events based on correlationId (yet)

@lfr
Copy link
Author

lfr commented Jan 28, 2019 via email

@Dzoukr
Copy link
Owner

Dzoukr commented Jan 28, 2019

Yes, that would be handy. I'll think about it for new version definitely.

@Dzoukr
Copy link
Owner

Dzoukr commented Feb 12, 2019

FYI, I am about to release version 2 soon (tomorrow or day after tomorrow most likely) with having both CorrelationId & CausationId. Also from v2.0.0 each CosmoStore implementation will be in separate package where CosmoStore is only API definition.

@lfr
Copy link
Author

lfr commented Feb 12, 2019

That's pretty awesome! Unfortunately for me, I had to stick with Postgres for the backing store along with some additional weird requirements like having to rely on FSharpLu's serialization, so I ended up writing my own poor man's store that's clearly never meant to be battle-ready, but I did use the opportunity (if it can be calle that) to familiarize myself with CQRS.

@Dzoukr
Copy link
Owner

Dzoukr commented Feb 12, 2019

No problem, the CosmoStore.Postgres will be probably the next package 😄

@Dzoukr
Copy link
Owner

Dzoukr commented Feb 12, 2019

Aaaaaaaaaaaand it is published and docs updated. Thanks for hints! 🙏

@Dzoukr Dzoukr closed this as completed Feb 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants