Pure Event Sourcing With Axon

Hi,

I’ve been using axon for a few weeks now and I have come across a problem I’m trying to solve( not necessarily axon-related only)

I have an aggregate(Agent) who does sales and I’m projecting that to a table that contains only their Id and balance. The balance is part of the agent aggregate.

  1. Let’s say I have about 2000 concurrent transactions going on, trying to update the same table(using MySQL), and the updated balance is sent to the UI. From what I’ve read, MySQL does table level locking on updates (MyISAM engine) . Will the database support such volume of updates or are there any strategies you propose to prevent failures?

  2. I thought of implementing pure Event Sourcing such that each time a sale is made, the UI is updated directly, and when a query is made the aggregate state is rebuilt from the snapshot table and event store. I basically want the UI to display each agent’s balance, and I believe I can get that from my event store directly. I know complex queries is an issue with Event Sourcing but how could I achieve this using Axon for such a scenario?

Since you asked for other strategies: Are there particular reasons you need to use the MyISAM engine? MyISAM has significant issues with data integrity and crash recovery. Even leaving aside the update locking behavior, I’d be really hesitant to use it in a production transaction processing system without a specific reason.

The InnoDB engine uses row-level locking instead of table-level locking, which should scale a lot better unless all of your 2000 concurrent transactions are updating the same row, in which case MySQL is probably not going to be the right tool for the job regardless of engine.

That said, though, 2000 concurrent transactions might be fine even with MyISAM depending on how long transactions take, assuming by “transaction” you mean a business transaction that involves a bunch of steps that might take varying amounts of time. What’s the request rate (transactions per unit of time)? How much does the number of concurrent transactions vary over time? Is 2000 the expected steady state or an outlier case you’d expect to almost never reach?

-Steve

Hi Steve thanks for replying,

Since you asked for other strategies: Are there particular reasons you need to use the MyISAM engine? MyISAM has significant issues with data integrity and crash recovery. Even leaving aside the update locking behavior, I’d be really hesitant to use it in a production transaction processing system without a specific reason.

Checked it out and innoDB engine is being used

The InnoDB engine uses row-level locking instead of table-level locking, which should scale a lot better unless all of your 2000 concurrent transactions are updating the same row, in which case MySQL is probably not going to be the right tool for the job regardless of engine.

Each transaction updates a single row in multiple tables.

That said, though, 2000 concurrent transactions might be fine even with MyISAM depending on how long transactions take, assuming by “transaction” you mean a business transaction that involves a bunch of steps that might take varying amounts of time. What’s the request rate (transactions per unit of time)? How much does the number of concurrent transactions vary over time? Is 2000 the expected steady state or an outlier case you’d expect to almost never reach?

I don’t have those statistics for the whole database, but for this particular case, last time we checked it was about 600 transactions per minute

We would like to avoid the idea of updates altogether , that’s why I’m asking for an Event Sourcing approach to the problem.

Hi Harvey,

I’m guessing your first point has been answered to Steven to some extent, right?

Regarding point 2, I get the idea you’d like to use the aggregates state as a query result as well because of the following you describe: ‘…when a query is made the aggregate state is rebuilt from the snapshot table and event store’
In Axon usually you only recreate the aggregate state based on snapshots/events when you load in the aggregate to handle commands.
What I think you’d like to do, is to query an aggregate directly, am I correct?

I’d say it can be done (I’ve create a simple QueryBus similar to the CommandBus some time ago), but it’s not yet serviced in the Axon Framework.

If I interpreted you wrong, please tell me so.

Cheers,

Steven

Hi Harvey,

I’m guessing your first point has been answered to Steven to some extent, right?

Yes.

Regarding point 2, I get the idea you’d like to use the aggregates state as a query result as well because of the following you describe: ‘…when a query is made the aggregate state is rebuilt from the snapshot table and event store’
In Axon usually you only recreate the aggregate state based on snapshots/events when you load in the aggregate to handle commands.
What I think you’d like to do, is to query an aggregate directly, am I correct?

Yes that’s what I would like to do (Though the docs says this smells bad design :slight_smile: ). The problem stems from the rate of table updates anyway. I elaborate on that in this question. If there is a way to solve transaction failures from timeouts using CQRS, I think that will be all I need.