vendredi 27 septembre 2019

Design of an auditable system which doesn't require complex diffing on save

We're currently trying to design a simple module for our system in order to make it auditable, but we're not sure on what the best strategy is. We want to try and nail it as early as possible because after the application goes live, migrating all the data to a different strategy could be a kerkuffle.

Strategy 1 – Our current choice

The system we are currently experimenting with consists in creating a new record every time an update is made and when querying, simply get the ones with the latest created_on timestamp. In the case that we have parent-child relationship and the child is to be updated, we would just update the child, not the parent. When querying those, we would apply the same strategy for every dependant relationship.

Strategy 2 – not so fond of it

Another strategy we have thought of would be to have two columns in each table, a valid_from and a valid_to timestamps. Every time we update a record, we would populate the valid_to to the previously valid record, and leave the current one with an empty value. We would follow a similar fetching strategy as the previous case.

To wrap up, I want to highlight that the main reason why we don't stick with strategy 1 is because in order to save the data, it requires us to go through a fairly complex diffing process which we're not fond of. Every time the frontend calls our API with a new payload we fetch the latest aggregate (parent + children + grandchildren, etc), do a full diff and identify what to update.

So my question to you folks is, have you used any other auditing strategies your proud of and would like to share?

Aucun commentaire:

Enregistrer un commentaire