JpaEventStorageEngine and EmbeddedEventStore

Hi. Can someone explain a bit more to me? I’m not using Axon Server or any message queue, just two separate instances of the application with round-robin traffic routing. I have a JpaEventStorageEngine and also an EmbeddedEventStore. If I understood correctly, it is not a good idea to use the EmbeddedEventStore because each application has its own EmbeddedEventStore. What are the options?

@Bean
    public JpaEventStorageEngine eventStorageEngine(Serializer serializer, DataSource dataSource, EntityManager entityManager) {
        return JpaEventStorageEngine.builder()
                .serializer(serializer)
                .dataSource(dataSource)
                .entityManagerProvider(entityManager::getEntityManagerFactory)
                .build();
    }

    @Bean
    public EventStore eventStore(JpaEventStorageEngine storageEngine) {
        return new EmbeddedEventStore.Builder().storageEngine(storageEngine).build();
    }

You might run into concurrency issues, where both instances want to update the same aggregate (by applying events to the same aggregate). If you use Axon Server, command messages for the same aggregate will always be routed to the same application instance (as long as the instances running are stable).

For event streaming, some optimizations prevent doing calls to the database to see if there are new events. With multiple instances, these don’t work, so you either get a lot of calls to the database once the event stream is called up, or you get higher latency for new events.

Axon Server will work better, but it depends on your requirements if the downsides of not using Axon Server are acceptable.

1 Like