We are developing one application and we are creating audit trails for each and every systems as well as a user action. We have some business logic in services and for which we are looking back to audit trails to find out which user has done which action.

Is it good practice to put service business logic based on audit trail?

  • It depends on what you mean by good practice. Having business logic in an audit trail should make it straight forward to see where it went wrong. However, it also could be a security risk depending on how exposed the audit trail is. – Robbie Dee Apr 13 '18 at 9:43
  • Can you confirm that the audit trail is sufficiently protected from tampering and unauthorized access ? – Christophe Apr 13 '18 at 10:11
  • 5
    Don't re-purpose audit trail for business decisions. An audit trail might be a general purpose transaction dumping ground. Collect user actions/stats in same system to make business decisions. – S.D. Apr 13 '18 at 10:22
  • @S.D. if you pack this into an answer, I'll upvote, because this is the whole story. Separation of concerns: audit trail is only there to write history (for a successful system there could be so many actions to audit that the trail is archived on some remote, inaccessible, system at regular intervals) and business logic must take care of data needed ! – Christophe Apr 13 '18 at 20:57


The problem is the audit trail should never change once written. So lets say I have some business logic

"Show the buy button if the customer has not bought previously"

And when the customer buys we add an Audit record.

We implement the business logic by checking that customers audit record and display the button accordingly.

Now, lets say an order goes wrong in some way. The audit trail has a buy written to it, but something went wrong somewhere and the customer is saying they didn't buy the item.

Maybe your suspicion is that they did in fact buy the item, but at this stage you just want to accept the possible loss and to get a happy customer. You are happy that your business logic is correct AND happy that the audit trail is correct AND that this case is so rare that a new process is not needed.

The temptation here is to do a data fix for the customer. Manually erasing their buy record so that the button reappears, and in normal circumstances you might do just that.

But! because your logic is driven from the audit trail this would mean you have to change that audit trail. Which you really, really don't want to do and perhaps legally can't do.

| improve this answer | |

It depends (but I guess for most real-world situations the answer is no, you risk to run into trouble).

A general-purpose audit trail may collect data which, depending on the details, might be affected by laws of data security and privacy of the jurisdiction where your application will be used. If those laws will force you to keep the data only accessible for privileged personal, or if those laws will force you to anonymize that data, or if they force you to delete them after a certain period of you might run into trouble if it is also used for controlling other business logic.

Another thing to consider is if the audit data is stored in a form which can be directly used for your business, or if it is stored as something like a weakly structured log file. The latter is likely when the audit trail was originally not meant to be used for business logic. If that is the case, you will have to parse the log file and reconstruct things like the user name from it. Such an approach can easily lead to a brittle and overcomplicated solution.

So if none of those reasons don't apply to your system, and you are confident they won't apply within a reasonable time period, then you may take that route.

Otherwise, it is probably simpler and more maintainable to build a "business-specific" trail which stores exactly the information you need to control your business logic, in exactly the form you are going to use it, with the access rights and life time your system requires.

| improve this answer | |
  • Depending on the jurisdiction and the subject matter, you could be forced to write such logs to provide transparency and combat fraud (e.g. SOX or GMP compliance) – Christophe Apr 13 '18 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.