Opinion on file & memory based event sourcing system

Thanks for the fantastic thread. A week ago I stumbled upon the event sourcing concept and I’m learning quite a bit thanks to libraries like Fable and EventStore. But obviously I probably still not get the nuances of where, when and how to use this pattern correctly.

What I don’t necessarily like with the approach is that my logic is somehow also bound to event history; if something changes in the way data is being stored I now need to either:

  • Keep the old and new data-structures as they were stored and just add the necessary application logic to handle multiple representations.
  • Migrate stored data and reducers as necessary to keep the system tidy.

The Fable example from @benwilson512 gave me a cue:

¿Would storing the event along its transformation be too crazy of an idea?
Let’s say these are the events I want to persist (this is just general elixir, no framework or library attached):

%Event{
  id: "123-abc",
  event_type: "Inserted",
  handler: :erlang.term_to_binary(fn x -> x end),
  number: 1
}

%Event{
  id: "123-abc",
  type: "Incremented",
  handler: :erlang.term_to_binary(fn x -> x + 1 end),
  number: 2
}

We could then retrieve the desired events and apply the stored transformations to any data as a starting point. Taking it a little further:

%Event{
  id: "1a2-b3c",
  type: "Incremented",
  handlers: %{
    up: :erlang.term_to_binary(fn x -> x + 1 end),
    down: :erlang.term_to_binary(fn x -> x - 1 end)
  }
  number: 108
}

We could store handlers for both transforming data further or doing a rollback (the Sage - Sagas project docs gave me this idea). This would let us “advance” or “rollback” data in any state to another point in time.

Aside from security or possible changes on how terms are stored… Would something like this be at odds with EventSourcing? Is there a library that already does this? I’m pretty sure there’s a lot I’m missing :anguished: