Event versioning, deserializing old events

Jun 16, 2010 at 3:59 PM
Edited Jun 16, 2010 at 4:00 PM

I like the way this framework is designed, very nice and easy to read and see what is going on.

The only thing that concerns me is the serialization/de-serialization of events from the event store, currently it seems like the system is aimed at the event remaining the same forever which leads to things like; IDog then IDog2, etc, which to me isn't a very nice [1][2].

For an example, say we currently store a customer's name as forename, surname. Later we decide this doesn't work well so choose to combine them into a single name field the events might look something like:

public class CustomerNameChangedEvent : DomainEvent
{
    public string Forename { get; set; }
    public string Surname { get; set; }
}

After the change it would look like:

public class CustomerNameChangedEvent : DomainEvent
{
    public string Name { get; set; }
}

This will be a problem when loading the old events from the event store. The best solution that I see is you need to be able to de-serialize events to an untyped property bag [3] which can then be manipulated by a series of converters before being handed over to an object de-serializer that can convert the property bag to the actual event.

For this to work each event needs to hold 3 pieces of information, the event type, event version and the serialized data. Event type and version is then used to look up the de-serializer and converters required to construct the event object.

As an optimisation, if the event version is the latest, it would be possible to de-serialize directly to the event object and skip the property bag step.


[1]: http://www.udidahan.com/2007/11/09/podcast-versioning-and-soa-there-is-no-idog2/ 
[2]: http://elegantcode.com/2010/02/09/cqrs-event-versioning/
[3]: http://thinkbeforecoding.com/post/2010/04/25/Event-Sourcing-and-CQRS-Events-Deserialization

 

Jun 18, 2010 at 2:15 PM

To investigate this I've created a small stub project to emulate an application that has been first re-factored into a new name-space, and later had the event altered to allow investigation into how versioning of events can be handled.

The project stub can be found at http://github.com/chilversc/ncqrs-versioning