Skip to main content

Posts

Showing posts with the label CQRS

Handling Event Versioning in Event Sourcing: Implementing Upcasting

  The "Immutability Tax" is the price we pay for the benefits of Event Sourcing. You have a pristine history of everything that happened in your system, stored as immutable facts. But business requirements change. A classic scenario: You have millions of  UserRegistered  events stored over three years. Originally, you captured a single  name  field. Today, the business requires distinct  firstName  and  lastName  fields for marketing personalization. In a CRUD system, you would write a SQL migration script to split the column. In Event Sourcing, you cannot change the past. The events in your store are immutable. If you deploy code that expects  firstName  but the event store feeds it a JSON blob containing only  name , your deserializer will throw an exception, or your Aggregate will receive  undefined  values and crash the system during replay. Rewriting the event store (modification in place) violates the core tenet...