Thursday, May 12, 2022

Pattern: Audit logging

Problem

How to understand the behavior of users and the application and troubleshoot problems?

Forces

It is useful to know what actions a user has recently performed: customer support, compliance, security, etc.

Solution

Each user’s actions are recorded by audit logging. Typically, audit logs are used to provide customer support, ensure compliance, and detect suspicious activity. 

An audit log entry records the identity of the user, the action they performed, and the business object involved. The audit log is usually stored in a database table.

Audit logging can be implemented in a few different ways:

  1. Add audit logging code to the business logic — Each service method can create an audit log entry and save it to the database.
  2. Aspect-oriented programming (AOP) — You can define advice that intercepts every service method call and persists an audit log entry using an AOP framework, like Spring AOP.
  3. Utilize event sourcing — Event sourcing by default provides an audit log for creating and updating operations.

By definition, observability patterns are not about logs, metrics, or traces, but about being data-driven during debugging and using the feedback to iterate on and improve the product.

Resulting Context


This pattern has the following benefits:

  • Provides a record of user actions


This pattern has the following drawbacks:

  • The auditing code is intertwined with the business logic, which makes the business logic more complicated

You may also like

Kubernetes Microservices
Python AI/ML
Spring Framework Spring Boot
Core Java Java Coding Question
Maven AWS