Flagsmith / Flagsmith/flagsmith

Implement SSE for all SDKs

Open
#1,498 1 comment 0 reactions 0 assignees View on GitHub
feature sdk
Dominant language
Python
Stars
6.6k
Forks
567
Avg merge
1d 13h
Merged PRs (30d)
121

Description

## Client Side

- [x] Javascript
- [ ] Swift/iOS (https://github.com/Flagsmith/flagsmith-ios-client/issues/32)
- [x] Kotlin (https://github.com/Flagsmith/flagsmith-kotlin-android-client/issues/18)
- [x] Flutter (https://github.com/Flagsmith/flagsmith-flutter-client/issues/58)

## Server Side

- [ ] Node.js
- [ ] Java
- [ ] .Net
- [x] Python (https://github.com/Flagsmith/flagsmith-python-client/issues/61)
- [ ] PHP
- [x] Ruby (https://github.com/Flagsmith/flagsmith-ruby-client/issues/72)
- [ ] Rust
- [ ] Go (https://github.com/Flagsmith/flagsmith-go-client/issues/144)
- [ ] Elixir
- [ ] Edge Proxy

Note: this is a parent ticket, when working on the implementation in a given SDK, there should be a ticket (referenced here) with relevant acceptance criteria defined.

## Requirements

On initialisation, the client must open an [SSE connection](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events) to `https://realtime.flagsmith.com/sse/environments/{environment key}/stream`.

Whenever a flag changes (or an entity changes which might affect the value of a flag, e.g. a segment) in the Flagsmith Dashboard, an event is sent via the stream. The event will have a type of environment_updated and a body that looks something like {"updated_at": 1689172003.899101} where the value of "updated_at" is an iso timestamp of when the environment was last updated.

Each call to `/flags`, `/identities` and `/environment-document` also includes the X-Environment-Updated-At response header which contains the same value. The clients can use this to initially set the state for this value and then continue to update it by listening to the SSE stream.

The client is expected to maintain a cache of the last time the environment was updated and, when it receives an event on the SSE stream, to determine if the environment was updated more recently and if so, to call the relevant endpoint to retrieve the flags for the environment / identity and update it's local state wherever necessary.

See the JS SDK code [here](https://github.com/Flagsmith/flagsmith-js-client/blob/d85456e9a2c047665a58a782bed921a5a631b138/flagsmith-core.ts#L373) for reference.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.