Datomic and EventStore are both databases that store data as a series of changes, but they approach that change log with different mindsets. I’d like to explore the tradeoffs between these two mindsets.
Datomic stores data as incremental changes, but the developer primarily interacts with the data much like a relational database. There is a schema which defines entities (much like tables) and relationships between them. The stored data increments are usually computed from updates to these entities.
Here’s a simple schema for a shopping order.
Entities are updated similar to an
UPDATE in SQL.
If I save again, Datomic will take care of saving the delta in data and updating the current view of the order.
I can then query this data pretty much however I’d expect to query a relational database.
Datomic has a nice getting started tutorial if you want to dig deeper.
EventStore takes a rather different approach than Datomic. EventStore expects developers to primarily interact with the incremental changes themselves, not some canonical view of current entity state.
EventStore has no schema. There is no overall specification of what the data looks like or how entities relate to each other. Instead it has streams of events. A stream often represents an entity (like the example Order), and the events are semantic changes to the entity over time.
Consider this shopping order example.
The developer defines semantic reasons an Order might change.
When a change occurs, events are appended to that entity’s stream.
These events can then be replayed to create different views of the data, like if we want to compute the final shipping manifest (goods in the box, where it’s going, etc).
The playback is really just a function that maps each event into the desired view, potentially overwritting information from previous events.
Unlike Datomic, there is not one canonical schema for the current state of an entity (in this case an order). The series of semantic events is treated as the primary view of the data and any “current state” views are treated as disposable computations from the events. EventStore provides various subscription and projection approaches for maintaining these computed views of an event stream.
I should highlight that different events might change the same data, but communicate different reasons for change. In the example above,
ItemReturned might both effect how we tabulate item quantities.
Because events communicate why data changed, different usecases can interpret the events differently. For example, the logic for recommending products might interpret
ItemReturned quantities differently than the logic for managing inventory.
The interpretation of events can also change over time since we know the intent of each event. Today the sales report might deduct returned items from the total items sold, but later decide to include them as sold items and account for returns separately. No data is lost, it’s just reinterpreted.
It’s also possible to support advanced decisions based on the order of events. Decisions based on event order don’t lose context over time, unlike decisions based on a set of state flags.
Both Datomic and EventStore use increments of data as the primary source of truth. The key difference is how they view the increments of data.
Datomic treats these deltas as (usually) anonymous artifacts of updating entities. The developer primarily interacts with the current view of data within a defined schema.
EventStore takes the inverse assumption. There is no primary “current state” view for entities. The developer primarily interacts with the increments of change themselves. The data increments (or events) should communicate the meaning behind changes. Any “current state” is computed from the events. It’s expected that there may be many different views computed from the same events and none of them get special treatment.
Tradeoffs Between Mindsets
The upside of Datomic’s approach is the familiar feel. It can deliver the capabilities we generally expect from a relational database (i.e. querying a bunch of entities based on fields) while delivering substantial improvements in data safety and observability.
The downside of Datomic’s approach is that the data updates are stored without context. We don’t know the intended meaning of the change, which limits how the changes can be reinterpreted over time.
EventStore is the reverse of this tradeoff. EventStore does not have the familiar feel of a relational database. It can take some trial and error to use it correctly, and EventStore probably won’t be the right tool for all capabilities we expect of a relational database. Some queries might require computing a view of the data and persisting it to a data store more suited to that kind of query.
Disclaimer: I have limited production experience with EventStore itself. Rather, I worked with had a homebrew system with the same philosophy as EventStore (it was written before EventStore grew in prominence).
Semantic Events Deliver Whole-Business Value
While EventStore’s approach is more disruptive, it also holds tremendous business value.
My experience at a recent job suggested that storing changes as semantic events and not just anonymous deltas was the primary value to the business as a whole. Events logs could be exposed to customer service representatives to better diagnose customer issues. The data team could leverage the series of events for an in-depth analysis of shopping trends or hangups in customer experience. All the technical benefits of better observability and data safety are there too, plus developers were less tied to one read model of the data. The benefit extended across the whole business.
Let me put it this way. The business team would probably have thrown a fit and intervened if the tech team ever tried to move away from storing semantic events. I think it’s rare for a whole business to be so invested in a development paradigm. That general buy-in indicates that persistent semantic events deliver unique value.
I do think it’d be possible to attach semantic descriptors to changes in Datomic (the transaction meta is very flexible), but it’s not an expectation like it is in EventStore. Such broad value is worth making a default.
Both Datomic and EventStore are awesome database technologies. They both store data as a series of changes, and both provide significant benefits to data safety, observability, auditing, and more.
However, the two databases treat the series of changes differently. Each approach has it’s benefits, but I think EventStore’s emphasis on semantically named increments of change holds tremendous value for the whole business. Recording the intent of changes over time preserves a new dimension of understanding about the data, and that depth is useful far beyond technical development.