Event sourcing without regular reconstitutions

Let me start with an explanation of our bespoke setup (we use spring boot 3.x):

We have an aggregate in a backend service. The aggregate receives commands via a websocket connected to a web app frontend. We have mechanisms in place to ensure that an aggregate only receives commands from a single websocket at a time.

The advantages of this setup: 1) We get low latency by using the websocket
2) If the websocket is disconnected, e.g., due to a container crash, the
frontend can connect to another backend instance where the aggregate is
reconstituted.

When the frontend reconnects, the aggregate is reconstituted from a list of
events we’ve stored in a standard postgres database. Further commands are
directed to this reconstituted instance. In this manner, reconstitution is done
once per websocket and not for each command.

Currently, we use an in-house implementation. I’m wondering if we
could use the Axon framework instead. My idea is that we could do some hybrid between the Event sourcing repository and an ‘in-memory’ repository.

Sketch:

  • All domain events on the aggregate will be stored in the event store.
  • On the creation of the aggregate, we store it in the ‘in-memory’ repository.
  • On reconstitution, we let the event sourcing repository reconstitute the aggregate and store it in the ‘in-memory’ repository.
  • When we receive commands, we fetch the aggregate from the ‘in-memory’ repository.
  • We will not need the Axon server component.

Of course, there’s also a need to introduce command handlers and so on, but my main headache is how to do the reconstitutions, when I don’t want to do them for each and every command.

I’ll be grateful for advice on this approach. I’m in doubt whether I need special aggregate factories, so please include pointers for this if applicable.

/grydholt

OK, so I just realised that CachingEventSourcingRepository exists :slight_smile: It seems to do what I want - with a configurable caching strategy. If you feel that I’m going down the wrong route with this, please let me know.

/grydholt