flipt icon indicating copy to clipboard operation
flipt copied to clipboard

A way to send push notifications to update client-side cache when a flag changes in the backend.

Open umarlateef opened this issue 1 year ago • 2 comments

Problem

There is a possibility that users may set the cache refresh interval too low, which could lead to undesired traffic and load on the server. This can be inefficient and unnecessary, as it increases server load even when no changes have been made. A more efficient approach would be to notify clients when a change in their feature toggle occurs, allowing them to refresh the local cache only when necessary.

Ideal Solution

Implement a system that sends a push notification to clients when there is a change in their feature toggle. Upon receiving this notification, the clients can refresh their local cache accordingly. This approach would reduce server traffic and ensure that the cache is updated only when needed, improving overall performance.

Search

  • [X] I searched for other open and closed issues before opening this

Additional Context

No response

umarlateef avatar Sep 12 '24 16:09 umarlateef

Good idea @umarlateef !

We could implement Server Sent Events (SSE) in Flipt server and expose an endpoint where our client side SDKs can subscribe to these events.

Here's how I'm thinking this could work:

  1. Add a new endpoint like get: /internal/v1/evaluation/snapshot/namespace/{key}/subscribe that allows clients to maintain a sse connection
  2. Make use of our namespace versioned stores that keep track of when anything in a namespace is changed
  3. Push events (the etag or version) to subscribed clients over SSE
  4. Our client SDKs can then refetch the flag state from Flipt server whenever this version changes by fetching with the etag/version they receive over SSE

markphelps avatar Sep 20 '24 19:09 markphelps

@markphelps That will solve the problem, and help us reduce the load on the server.

umarlateef avatar Sep 20 '24 19:09 umarlateef

@umarlateef 👋🏻

This may not be what you're looking for as its not in open source Flipt yet.. but we did just release streaming support to our client side SDKs for Flipt Cloud. https://docs.flipt.io/integration/client#polling-vs-streaming

markphelps avatar Nov 05 '24 14:11 markphelps

Is this solution available only for flipt cloud? Not available for self hosted solutions?

Streppel avatar Feb 14 '25 16:02 Streppel

@Streppel we are working on v2 (self-hosted) which we can add push notifications for. see #3828 . I can add push events as a TODO there

markphelps avatar Feb 14 '25 16:02 markphelps

That's awesome. Thanks for the quick reply.

Streppel avatar Feb 14 '25 16:02 Streppel

Closing this as it will be handled by #4069

markphelps avatar Apr 17 '25 20:04 markphelps