Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design patterns to facilitate these behaviours (audit trail behaviour and undo)

I am working on a system that needs to exhibit these behaviours:

  1. Audit Trail
  2. Undo / Revert to a particular version (such an action will itself be audit logged)

I have seen a slightly similar question here, but it deals with only part of what I'm trying to do. Further more, I want to capture the entire life cycle of an object (i.e. CRUD).

The way I intend to implement this is as follows:

  1. Have a ChangeManager class based on the observer pattern
  2. Derive my objects from a base object that "wraps up" changes in a command pattern
  3. Notify the ChangeManager with the command object on any of the CRUD events

Note: A 'change' Command will consist of:

  • an (ordered) collection of 2-tuples detailing the field change (prev, new)
  • id of user that made the change
  • timestamp of the change

This is just "off of the top of my head" - and there may be holes in the approach I am thinking of taking - I would appreciate some help from people who have implemented this sort of behaviour before, and also general advise, pros and cons on the approach I have outlined above - or maybe a better/alternative approach. A snippet or two to point me in the right direction will also be greatly appreciated!.

I will be using C# as the implementation language.

like image 660
oompahloompah Avatar asked Aug 03 '11 12:08

oompahloompah


People also ask

What are the four different types of audit trails?

Different types of internal audits include compliance, operational, financial and information technology audits.

What is audit trail in system analysis and design?

An audit trail is a series of records of computer events, about an operating system, an application, or user activities. A computer system may have several audit trails, each devoted to a particular type of activity.

What is a audit trail process?

An audit trail is a step-by-step record by which accounting, trade details, or other financial data can be traced to their source. Audit trails are used to verify and track many types of transactions, including accounting transactions and trades in brokerage accounts.


1 Answers

This is a rather complicated topic. There are a number of formal approaches.

From my perspective, I'd consider using "Event Sourcing". See here for further information:

http://martinfowler.com/eaaDev/EventSourcing.html

That will take care of populating a changelog and maintaining current state and gives you the ability to replay events to undo changes. There are entirely event driven architectures based around this such as CQRS:

http://martinfowler.com/bliki/CQRS.html

Another alternative is the command pattern, which allows undo but does not consume all the requirements above such as audit tracking. An example of the command pattern with undo is here:

http://mattberther.com/2004/09/16/using-the-command-pattern-for-undo-functionality

Hope this is helpful.

Edit: provide CQRS reference.

like image 164
Deleted Avatar answered Oct 03 '22 17:10

Deleted