CQRS - Event versioning approach- Good or Bad?

758 views
Skip to first unread message

Neelanshu Sharma

unread,
May 14, 2013, 12:00:49 PM5/14/13
to ddd...@googlegroups.com
Hi all,

We are at a point in our development cycle (asp.net mvc application), where we need to introduce changes to our existing commands and events (say adding/removing a few properties etc).

Its a message driven CQRS system (no event sourcing)

I have been trying to find a way to introduce commands/events versioning in the system. Is there a recommended pattern one should follow If yes any examples/snippets?

Here is what i have ended up doing 

1. I have versioned my events backwards, such that the latest will always be called the same, while the ones that go obsolete will have a suffix added to it like '_V1', '_V2' etc.

so if i have an event like 

public class OrderSubmittedEvent : IDomainEvent

    {

       public int OrderId { get; private set; }

       public OrderSubmittedEvent(int orderId)


        {

            OrderId = orderId;

        }

   }

and if i have to add a few properties i rename my event above to 

public class OrderSubmittedEvent_V1 : IDomainEvent

    {

        public int OrderId { get; private set; }

        public OrderSubmittedEvent_V1(int orderId)

        {

            OrderId = orderId;

        }

    }

and introduce another event with the same name as my original event but with added properties, like so 

public class OrderSubmittedEvent : IDomainEvent

    {

        public int OrderId { get; private set; }

        public OrderSubmittedEvent(int version = 1, int orderId = 0, string customerName =  

                                   "Joe blogs", string address = "Earth")

        {

            OrderId = orderId;

            CustomerName = customerName;

            Address = address;

            CurrentVersion = version;

        }

       public static int LatestVersion

        {

            get { return 2; }

        }

        public int CurrentVersion { get; set; }

        public string CustomerName { get; set; }

        public string Address { get; set; }

    }

i still have to go ahead and change my code which publishes this event to include values for new properties.

 2. any given point of time when i get all my events from the event store (say, for replaying) they will always be of the same type after deserialization (in this case OrderSubmittedEvent) with new properties which were not part of the old events populated with their default values. 

At the time of replaying my events i make my events go through an IEventUpgrader 

This first verifies if the events is the latest version available. since the type will always be the event type, this check is based on the properties "LatestVersion" and "CurrentVersion"

What does everyone think of this approach?

next (i plan to do)

1. If event is an old version publish an 'UpdateMYEVENT' Event

Any inputs/feedback

thanks

PS : Sorry for the  color red. 


Greg Young

unread,
May 14, 2013, 1:39:13 PM5/14/13
to ddd...@googlegroups.com
Try using weak schema like json. Or mixed schema weak/strong with XML.
--
You received this message because you are subscribed to the Google Groups "DDD/CQRS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dddcqrs+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


--
Le doute n'est pas une condition agréable, mais la certitude est absurde.

Henrik Feldt

unread,
May 14, 2013, 2:07:34 PM5/14/13
to ddd...@googlegroups.com

I think that Avro has a sane approach that also helps understanding when looking only at the event.

Neelanshu Sharma

unread,
May 15, 2013, 4:35:12 AM5/15/13
to ddd...@googlegroups.com
@Henrik - thanks. would you happen to know where i can find it?
To unsubscribe from this group and stop receiving emails from it, send an email to dddcqrs+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Neelanshu Sharma

unread,
May 15, 2013, 4:54:13 AM5/15/13
to ddd...@googlegroups.com
@greg- thanks. in what context should i try to use json? are you ok to elaborate please?
To unsubscribe from this group and stop receiving emails from it, send an email to dddcqrs+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Henrik Feldt

unread,
May 15, 2013, 1:51:59 PM5/15/13
to ddd...@googlegroups.com
Message has been deleted

Ruslan Uralov

unread,
Jun 27, 2013, 11:42:12 AM6/27/13
to ddd...@googlegroups.com
There is also another approach without having versions at all:

- Shutdown application before an upgrade
- Take application snapshot at shutdown time and archive all existing messages
- Convert the snapshot according to your new messages
- Load last converted snapshot at start time

This is the approach taken by LMAX team who also use Event Sourcing, a little more info here

Greg Young

unread,
Jun 27, 2013, 11:56:04 AM6/27/13
to ddd...@googlegroups.com
Assuming you shutdown everyday.
--
You received this message because you are subscribed to the Google Groups "DDD/CQRS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dddcqrs+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Bennie Kloosteman

unread,
Jun 27, 2013, 8:41:59 PM6/27/13
to ddd...@googlegroups.com
Is there a need to change schema versions when adding fields does it add any value , i would normally only change schema if  a field was removed or renamed ( which would need a damn good reason)  ? json and Xml serializers will serialize V1 and V2 into the new V2  message ..

I think this is what Greg meant with "weak schema" a term i havent seen before.

Ruslan Uralov

unread,
Jun 28, 2013, 7:31:54 AM6/28/13
to ddd...@googlegroups.com
Greg, why shutdown everyday? 
I'd say go through this procedure once per upgrade of your messages

Greg Young

unread,
Jun 28, 2013, 7:37:57 AM6/28/13
to ddd...@googlegroups.com
LMAX had a days worth of messages at a time. In which case it works great.

It does not work well when you have 7 years worth (say 20TB)

Kijana Woodard

unread,
Jun 28, 2013, 8:48:07 AM6/28/13
to ddd...@googlegroups.com

Stock markets have the remarkably cooperative property that they shut down each day for twice the amount of time they were open and completely on weekends. This gives you a large window to finish processing and do maintenance/upgrades. :-)

Reply all
Reply to author
Forward
0 new messages