Event Sourcing: why using a message broker is a bad idea

Diogo Machado
6 min readApr 2, 2021
In Bali a bath in Pura Tirta Empul is a Public Event

I’ve seen many implementations of Event Sourcing that use a message broker to publish events to the read models. I’ve used that pattern and contributed to ES “frameworks” that implement that pattern. I think It is a bad idea. I’ll explain why:

1) Writing to the event store AND publishing events to a broker needs to be atomic. In most cases a distributed transaction using two phase commits is not an option. We need to create some mechanism to deal with faulty connections between publisher and broker:

To reliably/atomically update the event store and publish events to the broker, we can use the Transactional Outbox Pattern:

https://microservices.io/patterns/data/transactional-outbox.html

The outbox pattern uses a message relay process to publishes the events inserted…

--

--

Diogo Machado
Diogo Machado

Written by Diogo Machado

Software architect/developer. Developing software on the shoulders of giants.

Responses (9)