feat(invalidation): replace Postgres LISTEN/NOTIFY with GCP Pub/Sub#211
Open
steventohme wants to merge 2 commits into
Open
feat(invalidation): replace Postgres LISTEN/NOTIFY with GCP Pub/Sub#211steventohme wants to merge 2 commits into
steventohme wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 44cc1af. Configure here.
Removes the long-lived Postgres connection held per replica for cache
invalidation (LISTEN router_installation_invalidate) and replaces it
with GCP Pub/Sub.
- Delete internal/postgres/invalidation.go (PgxInvalidationNotifier,
InvalidationListener using WaitForNotification)
- Add internal/pubsub/invalidation.go with InvalidationNotifier
(publishes installationID to a Pub/Sub topic) and
InvalidationListener (subscribes via Receive)
- Wire up in main.go from three new env vars:
PUBSUB_PROJECT_ID
PUBSUB_TOPIC_ROUTER_INVALIDATION
PUBSUB_SUBSCRIPTION_ROUTER_INVALIDATION
- Add cloud.google.com/go/pubsub/v2 dependency
The Postgres LISTEN approach held one persistent idle connection per
replica, showing up as long-running transactions and burning connection
pool slots unnecessarily. The 5-min cache TTL remains as the safety net
for missed invalidations.
44cc1af to
5b73c1b
Compare
- Each replica creates its own subscription (<prefix>-<uuid>) via SubscriptionAdminClient at boot and deletes it on shutdown. The env var PUBSUB_SUBSCRIPTION_ROUTER_INVALIDATION is now a prefix. A shared subscription would load-balance, defeating cross-fleet broadcast. - Set ExpirationPolicy (24h TTL) so subscriptions leaked by crashed replicas are reclaimed automatically. - Add InvalidationNotifier.Stop() and defer it in main so pending publishes are flushed and background goroutines clean up on shutdown. Addresses Cursor Bugbot review on #211.
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
LISTEN router_installation_invalidate) — showed up as long-running transactions and burned connection pool slots unnecessarilyinternal/pubsub/invalidation.gowithInvalidationNotifier(publishes installationID) andInvalidationListener(subscribes viaReceive) backed bycloud.google.com/go/pubsub/v2internal/postgres/invalidation.go(PgxInvalidationNotifier+InvalidationListenerusingWaitForNotification)main.gofrom three new required env vars:PUBSUB_PROJECT_ID,PUBSUB_TOPIC_ROUTER_INVALIDATION,PUBSUB_SUBSCRIPTION_ROUTER_INVALIDATIONNew env vars required
PUBSUB_PROJECT_IDworkweave-prod-01PUBSUB_TOPIC_ROUTER_INVALIDATIONrouter-installation-invalidatePUBSUB_SUBSCRIPTION_ROUTER_INVALIDATIONrouter-installation-invalidate-subFor local dev / selfhosted: set
PUBSUB_EMULATOR_HOST=localhost:8085to route to the Pub/Sub emulator (same as Weave'sdistr/pubsub-emulatorsetup).Test plan
🤖 Generated with Claude Code