Implement LISTEN/NOTIFY for Postgres backend reactive task polling#458
Draft
Implement LISTEN/NOTIFY for Postgres backend reactive task polling#458
Conversation
- Add database migration with triggers for workflow and activity tasks - Implement notification listener with LISTEN/NOTIFY support - Add WithNotifications option to enable reactive polling - Integrate listener with GetWorkflowTask and GetActivityTask - Add comprehensive tests for notification functionality - Fix race conditions with proper synchronization Co-authored-by: cschleiden <2201819+cschleiden@users.noreply.github.com>
- Create postgres-notify sample demonstrating the feature - Add comprehensive README for the sample - Update Postgres backend README with LISTEN/NOTIFY documentation - Demonstrate 9x performance improvement with notifications enabled Co-authored-by: cschleiden <2201819+cschleiden@users.noreply.github.com>
- Define constants for listener reconnect intervals and ping interval - Add comments explaining dual driver imports (pgx for SQL, pq for LISTEN/NOTIFY) - Add comment in trigger explaining SELECT is efficient due to unique index - Improve code maintainability with named constants Co-authored-by: cschleiden <2201819+cschleiden@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Investigate use of LISTEN/NOTIFY in Postgres queues
Implement LISTEN/NOTIFY for Postgres backend reactive task polling
Nov 2, 2025
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.
Workers currently poll Postgres at fixed intervals to check for new tasks. This adds latency and generates unnecessary database queries.
Changes
Database layer
pending_eventsandactivitiestables that firepg_notify()on insertworkflow_tasksandactivity_taskschannels with queue name as payload(instance_id, execution_id)for efficient queue lookupNotification listener (
notify.go)pq.Listenerconnections for workflow and activity channelsBackend integration
GetWorkflowTaskandGetActivityTaskcheck for immediate work, then block on notification channelConfiguration
WithNotifications(bool)option, disabled by defaultUsage
Performance
Testing shows ~9x latency reduction:
Sample application in
samples/postgres-notifydemonstrates the feature.Original prompt
LISTEN/NOTIFYfor Postgres queues #455💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.