Query, Command & Event Replay - how to

I needed help from the forum on filling some gaps in my understanding of Axon as i’m relatively new with this. My working setup is as follows

  • 2 separate Spring Boot microservices running in Cloudfoundry for Command & Query
  • Using Kafka as event bus.
  • Currently using Mongo as event store but plan to swtich over to JPA.

Here are the questions that i need help with

  1. Does the Query microservice need to have a connection to the Event Store (one used by command) so that the Tracking Processor knows how/which events to replay? In my current setup the only way i was able to get event sourcing/replay working is by adding a tracking event processor on the Command Side and having it republish the event but this result in duplicate events being added to the event store each time I replay.
    i.e 1 event store on command which the query connects to and 1 token store on the query side.

  2. What is the mechanism in Axon to rehydrate the state of my aggregates when my command side restarts using the Event Store?


Hi Pankesh,

  1. as of Axon 3, the Event Bus is the Event Store. You can additionally use mechanisms like Kafka to transport events between services. If you have your tracking processor read from the Event Store, which is default, then they would need the same connection as the command components have. If you (only) use Kafka to transmit events between services, then you don’t. Replaying doesn’t mean redelivering the the event store. It just means resetting a tracking processor to the beginning of a stream. There currently is an issue in the KafkaMessageSource that prevents replays from (always) being executed successfully. This is currently being worked on.

  2. Axon doesn’t keep state of aggregates, by default. It will read all events for an aggregate each time that aggregate is loaded. You can optimize this using a Cache and/or snapshotting.

Hope this helps.


Thanks for confirming and clarifying my understanding. I was able to get most of this working here https://github.com/pankesh/cqrs-microservice-sampler/commit/ee005dca33174b3ff29101e1d8cd757eeb71dcbb along with the Snapshotting, tracking & sagas.

Agreed about not having to replay the events if we are using Kafka. I’ll wait for the KafkaMessageSource fix. We might need it eventually. For now most of my usecases i can put the command & query together in the same microservice.