Marten: Turning Postgres into an event and document store

Needs a location


Event sourcing is an approach to data persistence that is safe and flexible at the same time. It safely stores data as a log over all changes ever made. Nothing is lost. At the same time, event sourcing gives us tremendous flexibility to changes the business rules that govern how the data is used. These are some of the reasons that event sourcing has become increasingly popular over the past years.

But even though event sourcing has some great benefits it's not the only good way to store data. Some scenarios call for a simple document store, and some call for a traditional relation model. Enter Postgresql. Postgresql is a fast, rock solid, and ops-friendly database. Just the kind of thing to rely on for mission critical applications. Postgres is also an unusually versatile database that may have its roots in the relational world, but today is equally capable of storing non-relational data.

The Marten ORM leverages Postgres' JSON capabilities to make Postgres look like both an event store and a document database, which means that we get three models in one from Postgres: Relational, document, and event sourcing.

In this talk I will give an introduction to event sourcing in general and event sourcing using Marten in particular. I will expand on that introduction to show how event sourcing tends to introduce a need for "readmodels" and how Marten supports that through its document store capabilities. Along the way there might be an anecdote or two from using Marten and Postgres in the real world and under heavy load.

About the speaker: Christian Horsdal is an independent consultant with 20 years of experience building many kinds of systems from large scale microservice systems to tiny embedded systems and lots of stuff in between. He is a .NET expert, author of the books "Microservices in .NET Core" and "Instant Nancy Web Development", trainer, and an occasional open source contributor.