There are more people doing that. I’ve uploaded some sample code here: https://github.com/AxonIQ/giftcard-demo-series If you look into the giftcard-multiconfig-monolith sample, you’ll find 3 configuration examples (which you can switch by changing profile): everything on a H2 database (that’s the most basic case that many people start with), 2 separate Postgres databases, and a combination of Postgres and AxonDB (more on that below). I haven’t used sagas, but setting up a separate db for sagas for simply be repeating the case of splitting of the events database.
The code to wire up two separate Postgres databases may seem a bit complex. It’s worth noting that for 90% or so, this is unrelated to Axon. When using JPA-based persistence, Spring Boot does a lot of work for you in terms of beans it instantiates by default. Once you go from one to two databases, you have to do all that work manually, twice: the DataSource, the TransactionManager, the EntityManagerFactory, the EntityManager etc. In this example, I’m also using Flyway to manage the database schema.
When setting up 2 of all of these in Spring, it’s necessary that Spring knows which instance to inject in which cases. This is achieved by marking one instance of each bean type as @Primary, and marking other ones with some @Qualifier. In this case, I’m using @Qualifier(“events”) for everything that has to do with storing events and snapshots. My tracking tokens and projection records go into the @Primary stack.
Once you have everything set up on the JPA level, it’s a simple matter of instantiating Axon’s TokenStore to use the @Primary stack, and Axon’s EventStore to the @Qualifier(“events”) stack.
Now, since you’re already considering to store your events in a separate database system, you might want to checkout AxonDB. This system is highly optimized for storing events for event-sourcing. It provides superior performance to an RDMBS in this role, pushes updates to tracking processors actively, and has a great query tool for ad-hoc queries referencing event payloads. For this reason, I’ve also included a profile that combines Postgres with AxonDB.
Hope this is useful,