Event Sourcing as Replacement for CRUD

2016-10-03

Jitesh Doshi

Event Sourcing as Replacement for CRUD

Introduction to Event Sourcing as an alternative to traditional CRUD data storage for applications requiring historical accuracy.

Most developers are familiar with CRUD (create-read-update-delete) model of data storage in business applications. It is a simple model that has served us well so far. But the problem with CRUD is that it allows users to modify history (change past). That might be okay for some applications (a discussion board, say), but not for all, such as financial accounting.

In CRUD, the database simply stores that transaction amounts as they stand now. But in Event Sourcing (ES), the database is a journal of transaction entries with a timestamp that can be sequenced up to any “as-of” time to reflect the situation as it was at that time.

For example, one of SpinSpire’s financial clients has an application that currently uses CRUD model for accounting financial transactions. The problem is that the application allows users to go back and adjust financial transactions that have already happened, reconciled and reported to the relevant authorities. In effect, you’re changing the past.

The right way would be if the database had two entries - one entered originally, and another one entered later that adds the adjustment amount. And both the entries have separate timestamps. So if you queried the database with an “as-of” time, you’ll get one answer before the second entry, and a different answer after it.

Resources: