Data source issues and db pools

We are currently using axon framework alongside with spring boog and hikaricp as data source pooling system. We are facing pool exhausting issues from time to time and we have a theory, the scenario is as follows:

  • To update our read models we use the command bus to send UpdateReadModelEntityCommand.
  • As the command bus starts a transaction using the primary transaction manager (the write one) it acquires a connection from the write pool
  • On the handler, we open an inner transaction using a connection from the read pool, thus blocking the outer one.

This seems to exhaust the pools under some conditions. The question is: should we stop using the command bus to update our read models? Is appropiate to have two buses( one for write and one for read? What can be the rigth approach for projecting the read model? Use commands or just use plain services?

Thanks in advance

The CommandBus should be used to dispatch commands to components that perform your business validation. This means you either have a singleton with the @CommandHandler annotated functions in it which perform some validation, or the CommandModel has these annotations itself directly.

As an outcome of business validation, you would publish an event. Publishing the event typically means storing it in the EventStore. Any other Read Model adjustments are typically not do en by command handlers at all.

The components which update your Projections/Read Models/Query Models would handle the events, typically in a separate thread. It is there where they would use up a connection to update your models.

It is recommended to segregate the Event Store database solution from the Query Model database solution. Thus, you would have distinct connection pools for the Command side and Query side of your application. The former validates the business logic and publishes an event, whereas the latter will update your query models. Having the ability to change what storage solution is used for any of your Query Models is beneficial anyhow, as it provides more flexibility.

Hope this sheds some light on the situation @Alberto_Portilla!