Search code examples
databasedesign-patternsauditing

Insert-only data pattern


I'm writing a specification for a system that requires a full data audit history.

I've worked with a few nice auditing patterns before, but I'm leaning towards an insert-only pattern for this solution. The idea is that records will never be updated, only inserted and time-stamped.

That way, I will always be able to retrieve the latest version of a record according to my pre-defined grouping and I will also have a perfect history of previous "versions" of that data.

So my question is only: Is there a pattern for this approach? What is it called?


Solution

  • Where you end up if you follow this approach is called "Event sourcing". See https://martinfowler.com/eaaDev/EventSourcing.html , and many google results now that you know the magic words.

    The basic idea is that instead of just recording the current state of things, you record everything that happened to produce the current state. The current state then becomes redundant -- you can regenerate it at will, regenerate any previous state, create new unforseen views from the events, etc.