Transactions in an Event Sourced system

Transactions in an Event Sourced system

In an event sourced system how do we do transactions? This is an interesting problem.

The first thing to note is that I am talking about business transactions, not database transactions. (The main difference is that in a database transaction the transaction is atomic, and cannot be seen by any process outside of the transaction whereas a business transaction can be observed whilst in progress).

If you recall that in an event sourced system any entity that can be uniquely identified and has a life cycle can be represented as a stream of events.

Well, a business transaction can be uniquely identified and has a life cycle. This means that it, too, can be represented by a stream of events and the status of the transaction (in progress, failed, succeeded) can be derived by running a projection over those events.

The business transaction can issue commands which, in turn, can append events to the event streams of other business entities and this will update the state of them returned by any projection that runs over them.

The success or otherwise of the command is then written back to the event stream of the transaction, along with any results.

What happens if a command fails? Well that depends - what do you (the business) want to happen?

It can be retried (appropriate for a transient error) or it can be rolled back. Because the entire history of the transaction is stored in the event stream of the transaction then compensating actions can be issued to undo the work already done to return the system to the state it was in before the transaction.

More importantly the event stream of the transaction can be interrogated after the fact to see if there is anything to be learned from its failure and this can form the basis of business process changes - you can even replay failed transactions into a test system to see if they now succeed.

要查看或添加评论,请登录

Duncan Jones的更多文章

  • Taming the Concurrency Crocodile

    Taming the Concurrency Crocodile

    What is the problem? At the most basic level every business process being executed on a computer program can be…

  • Event Sourcing and CQRS on Azure serverless functions - Part 3

    Event Sourcing and CQRS on Azure serverless functions - Part 3

    This article is part of #ServerlessSeptember. You'll find other helpful articles, detailed tutorials, and videos in…

  • Event Sourcing and CQRS on Azure serverless functions - Part 2

    Event Sourcing and CQRS on Azure serverless functions - Part 2

    This article is part of #ServerlessSeptember. You'll find other helpful articles, detailed tutorials, and videos in…

  • Event Sourcing and CQRS on Azure serverless functions - Part 1

    Event Sourcing and CQRS on Azure serverless functions - Part 1

    How Azure Tables, Durable Functions and Event Grid can be used to build a serverless system This article is part of…

  • Notifications or Queries for intra-domain state communication

    Notifications or Queries for intra-domain state communication

    Different strategies for getting data between domains (or microservices) Background When systems are partitioned into…

  • Ecologically inspired application architectures

    Ecologically inspired application architectures

    There have been a lot of explorations seeking to put together architectural patterns that are appropriate for the very…

  • A question of "state"

    A question of "state"

    At the lowest level you have things like a car ignition switch which has a well defined and temporally unambiguous…

  • Event Sourcing and set based functions

    Event Sourcing and set based functions

    In an event sourcing based system each entity has its own event stream and the way to get the properties of that entity…

  • Persistent workflows on transient "serverless" functions

    Persistent workflows on transient "serverless" functions

    How we can use Azure "Serverless" functions, CQRS and event sourcing to put together a persistent workflow using…

  • Storing derived values in events

    Storing derived values in events

    One of the almost instinctive rules that developers who come from a database background is Codd's rule that you should…

    3 条评论

社区洞察

其他会员也浏览了