Given event store with fields:
Which contains events based on:
public class OrderLineAdded
{
int Id;
short Quantity;
}
... and then has further events added with an updated structure:
public class OrderLineAdded
{
int ProductId; // field name has changed
int Quantity; // field datatype has changed
}
When this historical data is retrieved (for analysis, etc), how do you reconstruct binary payload into meaningful data?
Note: the code above is not an example of a good event/event store implementation. I just want to know how this scenario should be handled.
Rinat Abdullin outlines some domain event versioning strategies in his CQRS bliki that you might find useful to read.
https://abdullin.com/post/event-sourcing-versioning/
He suggests two possible approaches:
public interface IUpgradeDomainEvents
{
IEnumerable<IDomainEvent> Upgrade(IDomainEvent e, string id);
}
The only method I've seen to handle backwards compatibility is to version each change to your event. Some people create new versions in a different namespace, so that the namespace reflects the version/feature information:
namespace Foo.ProjectA.Release1
{
public interface ISomeEvent {...}
}
namespace Foo.ProjectA.Release3
{
public interface ISomeEvent {...}
}
Alternatively, create a new version of the class with the version/feature info in the class name:
namespace Foo.ProjectA
{
public interface ISomeEvent {...}
public interface ISomeEvent_MoreRefinedVersion {...}
}
Personally, I prefer the former approach, unless the new version adds more specific semantic meaning to the event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With