Skip to main content

Live updates (WebSockets)

The Go SDK can listen for real-time updates so new definitions are applied quickly.

Enable​

client, err := toggly.NewClient(toggly.Config{
AppKey: "YOUR_APP_KEY",
Environment: "Production",
EnableLiveUpdates: true,
})

How it works​

The SDK connects directly to the definitions worker:

wss://{baseURL}/{appKey}/ws?rev={cachedRevision}

When a cached definitions revision is available, it is sent as the rev query parameter. On connect the worker responds with a sync message. The SDK fetches definitions only when the revision changed or no cached revision exists.

Update messages:

MessageSDK action
sync + unchanged: trueStore revision, no fetch
sync without unchangedFetch if revision differs or no cache
flags-updatedFetch if etag differs (debounced)
signing-key-updatedForce JWKS + definitions refresh

Legacy plain-text update messages are still handled for backward compatibility.

Polling with live updates​

Install toggly-go v0.13.2 or newer for the polling behavior below:

go get github.com/ops-ai/Toggly.FeatureManagement/[email protected]

Live updates accelerate freshness; they do not replace the background RefreshInterval loop when background refresh is enabled.

Scheduled polling continues while the WebSocket is connected but idle (for example when the worker only sends ping messages). Connecting the socket does not suppress RefreshInterval polls.

After a successful WebSocket-triggered definitions refresh (for example from flags-updated, a sync without unchanged, or signing-key-updated), the SDK skips scheduled polls until the 20-minute fallback window elapses. That throttling avoids redundant HTTP traffic after an invalidation-driven refresh; an idle connected socket does not enter this skip window.

When the WebSocket is disconnected, scheduled polling still provides eventual consistency on your configured RefreshInterval.

See WebSocket sync (client-side) for the full protocol shared across SDKs.