Flagsmith / flagsmith

Open Source Feature Flagging and Remote Config Service. Host on-prem or use our hosted version at https://flagsmith.com/
https://flagsmith.com/
BSD 3-Clause "New" or "Revised" License
4.59k stars 346 forks source link

Offline mode in server side SDKs #2024

Open matthewelwell opened 1 year ago

matthewelwell commented 1 year ago

Each of the Flagsmith server side SDKs should offer a way to have them function in 'offline mode'. By providing a JSON document of flags / an environment, the SDK should behave exactly as it does in local evaluation mode, however, using the static JSON document that should be bundled in the SDK itself.

This will need to be implemented in all of our serverside SDKs.

To implement:

matthewelwell commented 1 year ago

This logic has been implemented already in the client side JS SDK but here we're specifying that we only want to add it to the server side SDKs.

The question, I guess, is whether we want to implement this in more SDKs than server side SDKs. Would this functionality be useful for e.g. Kotlin, Swift, Flutter?

Related issue #1655

matthewelwell commented 11 months ago

Once question here is whether, for server side SDKs, they should be able to handle segmentation as well in offline mode. I would argue that they should be able to. This would mean that this change could simply be that the environment document should be able to be read from the file system, rather than only from the API.

Thoughts @khvn26 @gagantrivedi @dabeeeenster ?

dabeeeenster commented 11 months ago

Yep this seems like a simple approach that would work

matthewelwell commented 11 months ago

2 implementation approaches here:

https://github.com/Flagsmith/flagsmith-python-client/pull/50 https://github.com/Flagsmith/flagsmith-python-client/pull/51

I think the single client class is slightly neater, but does technically break certain software engineering rules about only having a single purpose. A lot of the arguments passed to the constructor become redundant when using offline mode.

There is perhaps an argument to say, however, that the offline handler shouldn't be restricted to 'offline mode' and that it should be possible to use it instead of the default handler. In which case, the single client class is certainly the correct approach.

dabeeeenster commented 11 months ago

How about making api_url optional and configuring the file path in the handler instance, and adding an option to fall back to offline not just when api_url is None but e.g. in case of network errors?

matthewelwell commented 11 months ago

Python reference implementation is here: https://github.com/Flagsmith/flagsmith-python-client/pull/50

matthewelwell commented 3 months ago

@novakzaballa @gagantrivedi @zachaysan can you add the docs for the SDKs that you worked on for this. Reference PR for the docs is here.

zachaysan commented 2 months ago

@matthewelwell Added the ruby ones in this PR: https://github.com/Flagsmith/flagsmith/pull/3677