1. pgx-outbox
FOSDEM lightning talk
1 Feb 2025
Nikolay Kuznetsov
@nikolayk812
1
2. About me
Senior software engineer
Zalando Helsinki
Pre-owned project
C → Java → Kotlin → Go
2
4. Transactional outbox pattern
4
6. implements
Message
Writer (Postgres)
Reader
Forwarder
Publisher (SNS)
6
7. Outbox message
type Message struct {
ID int64 // generated by Postgres
Broker string `validate:"required"`
Topic string `validate:"required"`
Metadata map[string]string // optional
Payload []byte `validate:"required,json"`
}
7
8. Outbox writer
type Writer interface {
// Tx is empty interface to support both pgx.Tx and *sql.Tx
Write(ctx, tx Tx, message Message) (int64, error)
// pgx transaction only to invoke SendBatch and Prepare methods
WriteBatch(ctx, tx pgx.Tx, messages []Message) ([]int64, error)
}
8
10. WAL Reader support
Write ahead log (WAL), aka
Change data capture (CDC), aka
Postgres logical replication
Work in progress (WIP)
using jackc/pglogrepl
10
11. Thank you!
github.com/nikolayk812/pgx-outbox
11