feat: add NOTIFY payload parsing, overflow detection, and per-subscriber throttling#1106
Merged
pyramation merged 1 commit intomainfrom May 10, 2026
Merged
Conversation
…ber throttling - Parse TG_OP:id1,id2,... and INVALIDATE payloads from emit_change trigger - Add rowId and overflow fields to GraphQL subscription payload type - Add EventThrottle class for per-subscriber, per-table rate limiting - Default overflow threshold: 50 events/second/table (configurable) - When threshold exceeded, send single INVALIDATE instead of individual events - Fix full collection mode: use parsed row ID instead of passing null to resource.get() - Update tests to cover payload parsing, throttling, and new payload fields (35 tests)
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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
Updates the
graphile-realtime-subscriptionsplugin to parse the new NOTIFY payload format (TG_OP:id1,id2,...orINVALIDATE) from the emit_change trigger (introduced in constructive-db PR #1094), and adds two layers of overflow protection.Key changes:
parseNotifyPayload()— parsesINSERT:uuid1,uuid2orINVALIDATEinto a structured{ event, rowIds, overflow }objectEventThrottle— per-table event rate limiter using a 1-second window; returnsdeliver/overflow/dropto control event deliveryrowId: UUIDandoverflow: Boolean!added to the generatedXxxSubscriptionPayloadGraphQL typenulltoresource.get(), the plugin now extracts the first row ID from the parsed payload when noidargument is provided (single-record mode still takes precedence viasubscribedId)overflowThresholdoption oncreateRealtimeSubscriptionsPlugin()(default:DEFAULT_OVERFLOW_THRESHOLD = 50)Review & Testing Checklist for Human
EventThrottleinstance is created once per table insidebuildPlans()(schema build time). This means all subscribers to the same table share the same throttle counter. The doc comment says "per-subscriber, per-table" but the implementation is per-table-globally. Verify this is acceptable or if a per-connection throttle is needed.resource.get({ id: null }): When the throttle drops an event ($parsedisnull) or for INVALIDATE/DELETE with no row IDs,$rowIdresolves tonullandresource.get({ id: null })is called. Confirm Grafast/PostGraphile returnsnullgracefully here rather than throwing.lambdabehavior: The plugin useslambda()extensively for payload transformation. The unit tests mocklambdaas a synchronous function call. Verify the actual Grafastlambdastep handlesnullreturn values (for dropped events) correctly in a real pipeline—particularly that the subscription doesn't hang or error.EventThrottleuses a fixed tumbling window (resets every 1000ms), not a true sliding window. At window boundaries, up to 2× threshold events could pass within a 1-second span. Decide if this is acceptable.Recommended test plan: Deploy both this PR and constructive-db #1094 together, then:
@realtimetable via GraphQL and verifyINSERT:uuidpayloads produce{ event: "INSERT", rowId: "...", overflow: false }{ event: "INVALIDATE", overflow: true }instead of 50+ individual eventsNotes
parseNotifyPayloadandEventThrottleare exported fromplugin.tsfor direct unit testingLink to Devin session: https://app.devin.ai/sessions/19485cf5cc58416a9f86068563d512f5
Requested by: @pyramation