JDBC Event Store

I have no need for JPA other than for the JPA Event Store and it feels like a bit of overhead for me. As in extra dependencies and configuration files and things to keep in mind. Are there any reasons for using JPA other than that it makes things easier and it comes well integrated in Spring? I’m thinking the event store is simple in both the schema and what queries it does.

So are there any quick pros and cons of an event store that is closer to the SQL?

Hi Per,

I've been thinking about a "plain JDBC" Event Store as well. Just didn't allocate the time/raised priority enough yet.
JPA was the first implementation, as. The bar to use it is very low. Many applications use JPA anyway. But performance could be a lot better with plain SQL.
I remember someone on this list has created his own implementation a while ago. I'd have to search around and find who it was (if you read this, please come forward :slight_smile: ). It might be a good starting point to integrate into Axon.



Ok, so I wasn't totally wrong then. I was thinking of using MyBatis for this. I guess that voids my "no extra dependencies" part, but it does remove some of the hassles of pure plain SQL while still being your own SQL, the way you want to write it.

Any thoughts on that?


In the end, anything will do as an event store, as long as it is capable of providing consistency guarantees on a per-aggregate basis. So it's not so much the ORM technology used, but the actual database implementation type behind it.



So, given an SQL event store, the important part is to handle data base transactions and commit all events generated from an action (in the order they are given), or none of them. Right?

Correct. The easiest way to guarantee ordering is to use the sequence number of the event as part of a unique key constraint, together with the aggregate identifier (and optionally the aggregate type).

When returning events from the event store, make sure to order by the sequence number.



Hi y’all,

I have two cents to share, as an Axon user of the first hour!

You will find attached a quick and dirty (only took a couple of hours…) MyBatis implementation of the EventStore interface, that we used in production with version 0.4 of Axon :slight_smile:
(now we’re using latest Axon version and the built-in JPA implementation as we shifted from MyBatis to Hibernate)

We were using a separate table “AGGREGATE” along with the table “EVENT_STORE” (see eventStore.sql) but I do not think it was really relevant/useful to have that kind of normalized storage and to have a dedicated table for aggregates identifiers/type/last version number, as we did not leverage it (only one table is enough).

Hope that helps (at least to see that it is very easy to create its own event store).


eventStore.sql (674 Bytes)

RelationnalDbEventStore.java (4.45 KB)

RelationnalDbEventStoreMapper.java (1.36 KB)