← Back to Projects
Business Services

Audit Log Service

A platform-wide audit trail published from 12 microservices

Built from scratch · designed the platform-wide event contract · Oct 2024 — Aug 2025
Go go-zero gRPC Kafka MySQL/GORM pprof

Overview

Every admin write on the platform emits an audit event. I designed the event contract and the gRPC metadata it relies on, rewrote the shared publisher, wrote the diff utility, and built the consuming service and its query API.

Key Highlights

01

Kafka event contract carrying operator, IP, request path, module/action and trace IDs, plus before/after snapshots

02

Shared publisher now called from 12 microservices; a JSON diff utility stores only changed fields with readable labels

03

Consumer enriches each event with operator and target details through parallel gRPC calls

04

Tenant-scoped query API that hides platform-admin actions from tenants

05

Found a production memory leak with pprof: a value-copied RPC client opened a new gRPC connection per message

Key Implementations

1

Audit as a platform contract

A topic, a message schema and gRPC metadata keys that every service uses the same way, so an audit event can always name who did what, from where, and under which trace.

Why: An audit trail is only useful if every team records it consistently; a shared contract and publisher make that the default.

Result: Published from 12 services.

2

Memory-leak investigation

Memory grew steadily under load. I exposed pprof, read the heap profile, and found that the RPC client wrapper was passed by value, so its lazily created connection was never cached. The fix was pointer receivers, eager client initialisation and dropping large snapshot fields from the hot path.

Why: A temporary periodic GC hid the symptom; profiling found the cause.