Home / Companies / Pydantic / Blog / Post Details
Content Deep Dive

Why we ditched database triggers for audit logs

Blog post from Pydantic

Post Details
Company
Date Published
Author
-
Word Count
1,590
Language
English
Hacker News Points
-
Summary

Audit logging, initially implemented using PostgreSQL triggers in Logfire's observability platform, faced challenges such as performance issues during data migrations, limited context, and difficulties in testing and debugging. The original system relied on database triggers to ensure automatic logging of every SQL operation, providing consistency by recording actions within the same transaction. However, this method required disabling triggers during bulk operations, leading to complications and "audit log spam." To address these issues, Logfire transitioned to application-level audit logging with Redis, adopting an asynchronous producer-consumer pattern. This new approach improved context handling, expanded audit coverage to non-database events, and eliminated the need for complex migration handling, though it introduced trade-offs like eventual consistency and dependency on Redis. The transition was executed incrementally, reinforcing the importance of adaptable and testable audit logging as business logic within the application.