thePHP.cc Logo Deutsch Contact
mood

Event Sourcing

Event sourcing means deriving state from a stream of unchanging events. While classical data-centric architectures usually store the current state of an application in a relational database, event sourcing understands the stream of events (event ledger) as the canonical source of truth. Events not only allow for a more realistic modelling of the real world (which is also event-driven and event-controlled), but also make it possible to reconstruct at any time how a certain state came about. In a sense, an event ledger is an executable audit log.

Event sourcing has gained a lot of popularity in recent years because, especially in the context of CQRS architectures , it is very well suited for developing lightweight distributed applications that no longer need complex relational database schemas.

Although event sourcing seems to be relatively new in IT, the underlying principles have been used successfully for a long time. A relational database, for example, has a log file (binary log) that records all interactions with the database. If the database tables are corrupted, the database rebuilds their state from the binary log. This is event sourcing in the same way as it is used within version control, for example Git: starting from an initial state of a file, a series of changes in the form of patches are applied to get to the current state of the file.

There is also a very prominent example of event sourcing in the real world, namely accounting. Here, all transactions are recorded in a journal and totals are created over the individual transactions when balancing the accounts. Here, it is even stipulated by law that no entry may ever be changed or deleted, but that an explicit adjustment entry must be made. A journal in accounting is thus an unchangeable append-only data structure just like an event log, from which state can be built.

This building of state is called projection, just as a query against an SQL database creates a projection of the data.

The event sourcing principle can also be found conceptually in a blockchain. This is a cryptographically secured journal (event ledger) of unchangeable events as a decentralised database. If we leave out decentralisation, cryptography, and all the shenanigans surrounding so-called cryptocurrencies, what remains are precisely the principles that are legally regulated as accounting in the real world and have been called event sourcing in IT for several years.

Training Event-Driven Development

Make SOA and microservices a reality in your enterprise by demand-driven design of event-based, distributed systems.

More training
Presentation CQRS and Event Sourcing Explained More presentations
Training Event Sourcing

With event sourcing, changes in the status of an application are stored in an unchangeable event log.

More training
Presentation Introducing CQRS into Legacy Code More presentations
Presentation From Legacy to Event-Driven More presentations