Figure out how to actually leverage an empty events table for performance improvements #1867
Replies: 8 comments 10 replies
-
I though about this a bit more. We can actually make changes to the events today. They just need to be backwards-compatible. We can achieve that by introducing new events and mapping the old events to new ones. For that, it would probably be wise to introduce a dedicated When we can remove support for these old events is actually a completely different problem and does not need to be solved straight away. The only downside of that is some legacy mapping code that will be around for a while. Once we have shipped a few releases with the mapping code in it, we can always make a judgement call on when we think it is safe or acceptable to remove it. To not break any users at that point, all their CFDs will have to be closed. |
Beta Was this translation helpful? Give feedback.
-
I like this proposal. I think we should aim for this. If we cannot achieve to map old CFDs into the new model I think we should go for a breaking version that forces users to close all positions before an upgrade. We would have to define details for the upgrade process though. |
Beta Was this translation helpful? Give feedback.
-
I find it a bit hard to reason about a generic upgrade solution without knowing what we want to change. The proposed solution of mapping old events onto new events sounds to be the least invasive one with the best user experience :) |
Beta Was this translation helpful? Give feedback.
-
What do we want to optimizeWe want to lower the storage/db size and want to reduce the time to load CFDs from the DB. Why is the DB so bigWe store every event. The biggest events are A rollover happens ideally 1/h meaning for a single CFD we have ~ Our rollover protocol foresees that a user should never publish an old state, i.e. if a rollover was completed, a user should not publish an old state. For punishment we need a few things from passed rollovers:
We don't need:
What can we do?With #1779 landed we move closed CFDs into their own table and delete all events. This frees storage and speeds up loading time. However, this does not optimize open positions. A single position being open for a year will have ~ SnapshotsSnapshots have been discussed various times: they allow us to store a snapshot at a specific point of time and hence optimize loading - we don't need to load the whole history of events but can start from the snapshot. The question is, how often do we snapshot:
Our goal is to scale big, it may take some time, but eventually we will get there. The only way out is to do rollovers less often but this will only push the inevitable a bit away. That being said, is this a sign that we should drop ES hard rules on immutability? |
Beta Was this translation helpful? Give feedback.
-
A reasonably straight-forward way of ditching event sourcing could be to retain the idea of making changes to the model by means of emitting events from commands but apply them to a persistent aggregate and only save that one to the DB. Every other component in the system would then have to initialise its model from that persistent aggregate. In other words, instead of just saving closed CFDs in a separate table, save an aggregate for all CFDs, regardless of their state. This would allow us to retain most of the program's architecture that relies on events being emitted from the model's commands which IMO would otherwise be a gigantic piece of work. The major changes would be:
It is somewhat obvious but I am gonna point it out anyway: Any solution that ditches event sourcing will result in a "super" model on the db layer that needs to serve every requirement (monitor, projection, model, auto-rollover etc) because we will no longer be able to selectively take information from the events. We can still retain a "two-layer" approach where To retain an audit-trail, we can still save the name of the event in a table the same we do it for closed CFDs. |
Beta Was this translation helpful? Give feedback.
-
As I've expressed in the past, I'm very skeptical about giving up on event sourcing at this stage. We have definitely identified some pain points with the way we are using it (primarily the fact that we store a gigantic blob every hour and cannot/don't delete the old blobs). I suggest we try to mitigate them, even it means that our take on event sourcing is not as "pure" as it could be. Looking at the code I've noticed that every time we apply the gigantic events ( The obvious solution might be to set these Another idea that I think does not go against event sourcing principles could be to:
Basically, my observation is that the DLC doesn't need to follow event sourcing rules, so we can store it separately and do whatever we want to it. |
Beta Was this translation helpful? Give feedback.
-
To start a meta-discussion:
Both of these paths are doable, will yield positive results in terms of performance but also have downsides: Sticking with ES:
Moving to relational model:
|
Beta Was this translation helpful? Give feedback.
-
My 2 cents: |
Beta Was this translation helpful? Give feedback.
-
Once #1651 is landed, the
events
table will be empty if a node has 0 open CFDs.In that state, a software upgrade that changes the structure of the events is safe. We can leverage this to make backwards-incompatible changes to the layout of our events either for reasons of performance improvements or otherwise.
The tricky part that we need to solve is: How do we get the users application into this state?
Some ideas (with varying degree of user experience):
Beta Was this translation helpful? Give feedback.
All reactions