Deleting all Axon Events for an Aggregate

Hello all! First time posting.

My team is working with Axon 2.4, and Flyway 5-6, and Postgres 9.1. We’re working with a database that has several years of axon aggregates/events stored in it. We have PII in the axon events, and would like to remove the old events(and we’d encrypt any new events for the particular aggregate).

Our first idea was to load the aggregates in a flyway migration, delete them, then issue a ‘create’ command rebuilding the aggregates from the corresponding view. I was not able to get axon beans to finish loading when the flyway migration was invoked during application startup - leading to exceptions being thrown when I tried to send events on the command gateway.

My next idea was to write some sort of post construct that would accomplish a similar goal, but I figured one of you might have dealt with a similar issue. What’s the best approach for deleting an aggregates event history?

We are using spring 1.5, and java 8.

Hi Leif,

I am sure you are aware Axon 2.4 can be considered “pretty old”.
About two weeks ago we’ve release 4.2; so firstly a quick suggestion to upgrade to latter versions of the framework to benefit from the new features it brings.

A part from this, I would also like to point out that typically you’d never remove events from an Event Store. Ever.
What events give you is “the power of not now”, meaning that you can use your valuable business events to hydrate new types and versions of (Query) Models.
You could even think of starting a Machine Learning exercise to extract new forms of information from your Event Store.

This however is obviously an hypothetical bounds to an Event Store.
Nothing is withholding you from removing “facts” from your history.

As you are on Axon 2.4 with Flyway, you are likely using a regular RDBMS solution to store your events in.
To drop events for a given Aggregate, you should simply do a query for all rows corresponding to a given Aggregate Identifier and Aggregate Type combination and drop them.

In quick conclusion, I’d state the following:

  • Update your Axon version
  • Reconsider removing events in favor of archiving them for latter use
  • If removing is the only way, simply query an Aggregate’s events by searching them based on AggregateId and AggregateType.

Hope this helps you out Leif!

Cheers,
Steven