Productionize v1: outbox-backed atomic LISTEN/NOTIFY - #1
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Versionstamped at1.0.0.github.com/fastforgeinc/pgxevents; Go toolchain bumped to 1.25.Design highlights
NOTIFYis capped at 8000 bytes; the trigger writes a row snapshot intopgxevents_outbox(UNLOGGED) andpg_notifycarries only the outbox UUID. Atomic with the mutation transaction; payload reflects state at commit, not at delivery.MigrationsRequiredmode expects the canonical SQL (exported asInstallSQL()andTableTriggerSQL(table)) to be installed via the consumer's own migrations; library validates againstpg_catalogand a version-stampedCOMMENT ON FUNCTION, fails fast on mismatch with copy-paste SQL in the error.WithRuntimeInstall(true)installs at startup for dev/test.WithCleanupTTL. No external cron, nopg_crondependency, no leader election — all listener pods participate and the advisory lock elects one per tick.Health() <-chan errorlets consumers drain their downstream streams on listener failure and reconcile via fresh snapshots on reconnect. Reconnect uses exponential backoff with jitter.ListenTyped[T](listener, table)returns events with*Tpopulated from the snapshot — no fetcher callback. Decode errors are logged + counted asdecode_errorand skipped.Test plan
go vet ./...andgo vet -tags=integration ./...cleango test -race ./...— unit tests pass (action, options, backoff, jitter, overflow policy, decode)go test -tags=integration -race -count=1 -timeout=10m ./...— 8 integration tests against real Postgres pass (~13s)gofmt -l .— no diffsIntegration coverage:
WithRuntimeInstall(true)bootstraps DDL end-to-end on a fresh database.OverflowDisconnectcloses the subscription when its buffer fills.