4

We are using NEventStore (the artist formerly known as Jonathan Oliver's EventStore) to store our CQRS events. I would like to know if it is necessary to create a new version of an Event if we wish to add a new property to the Event.

I understand that we should not rename an existing property as that will create a problem when reading the events from EventStore. But, if we are only adding new properties will it create any issues?

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
Sachin
  • 127
  • 9
  • 1
    Btw, if you want the freedom to be able to change the names of events, and properties on the events, you can look into serialization using Protobuf. There's an implementation of it for .NET. We're using this on our project with NEventStore. Before you save the EventMessage, you can set its Body to a byte array, which is your application specific event serialized with Protobuf. Same goes for deserialization, when you're reading the event back out. – jacderida Jul 18 '13 at 15:48

1 Answers1

6

Depends on how you are serializing the messages. In other words, the best way to phrase this (/ search for an existing answer) is to identify how you are serializing the messages and then find out how that mechanism deals with the issue.

Assuming it's JSON with JSON.NET and simple POCOs, then the answer is that adding a property is handled pretty cleanly - in the absence of any customizations (which is very doable), new fields come in withe default(T), i.e. null or 0 for each relevant value.

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
  • 1
    I second this answer, this is the approach I have taken using Oliver's EventStore/JSON.NET and it works well. The only thing I would add is that you need to ensure that any handlers of the event take account of the null properties in the old events. – danielfishr Jul 18 '13 at 14:06
  • Ruben, It looks like Jonathan Olivers EventStore is handling new properties the way you assumed. I tried adding new properties to events and it worked fine. The value of the property is null for old events, which ofcourse I have to handle in the event handlers (as Daniel mentions). But I want to be 100% sure it is like that, and will remain so in future too. Does someone know how EventStore implements serialization? – Sachin Jul 19 '13 at 04:38
  • @Sachin the bottom line is that NEventStore handles stuff exactly as you configure it, so... how did you configure it (as I say, my guess is you cut and pasted stuff and ended up with JSON using NewtonSoft JSON.Net so you need to ask the question of it -- it has pretty good docs). I personally would suck it and see in a test -- you'll need to sort out your testing story anyway so go do! – Ruben Bartelink Jul 19 '13 at 08:57
  • Yes, I will explore it. Thank you Ruben. – Sachin Jul 22 '13 at 05:29