A pipeline that logs Postgres events from Sequin Cloud to a Postgres database. This project demonstrates how to build a robust audit logging system using Sequin's change data capture (CDC) capabilities.
SequinAuditLogger subscribes to database changes from Sequin Cloud and maintains a complete audit trail of modifications to key tables in our database.
Each change is captured with:
- The event ID and action (insert/update/delete)
- Full record state at time of change
- Specific fields that were modified
- Timestamps for when the change occurred
- The pipeline subscribes to a Sequin Consumer Group, which is receiving events from Sequin's prod db
- Each database change is received as a message and transformed into a SequinEvent
- Events are batched by table type and bulk inserted into corresponding audit log tables
Pipeline
(lib/pipeline.ex
) - The main Broadway pipeline that processes eventsSequinEvent
(lib/sequin_event.ex
) - Structures raw CDC messages into normalized events- Log Models - Handle persistence for each type of audit log:
DatabaseLog
AccountLog
UserLog
ConsumerLog
mix.exs
- Project configuration and dependenciespriv/repo/migrations/
- Database schema definitionslib/sequin_audit_logger/
application.ex
- Application supervision treepipeline.ex
- Main event processing pipeline- Various
*_log.ex
files - Audit log models
- Configure environment variables:
config :sequin_audit_logger,
sequin_token: "your_token",
sequin_consumer_group: "audit_logger",
sequin_base_url: "https://api.sequinstream.com"
- Setup the database:
mix ecto.setup
- Start the application:
mix run --no-halt