SDKs Overview
Flagsmith ships with SDKs for a bunch of different programming languages. We also have a REST API that you can use if you want to consume the API directly.
Our SDKs are split into two different groups. These SDKs have different methods of operation due to the differences in their operating environment:
- Client-side (e.g. browser-based Javascript).
- Server-side (e.g. Java or Python).
Environment Keys come in two different types: Client-side and Server-side keys. Make sure you use the correct key depending on the SDK you are using.
Client-side SDKS
Client-side SDKs run in web browsers or on mobile devices. These runtimes execute within untrusted environments. Anyone using the Javascript SDK in a web browser, for example, can find the Client-side SDK, create a new Identity, look at their flags and potentially write Traits to the Identity.
Client-side SDKs are also limited to the types of data that they have access to.
Client-side Environment keys are designed to be shared publicly, for example in your HTML/JS code that is sent to a web browser.
Client-side SDKs hit our Edge API directly to retrieve their flags.
Read more about our Client-side SDKs for your language/platform:
Server-side SDKs
Server-side SDKs run within trusted environments - typically the server infrastructure that you have control over. Because of this, you should not share your Server-side Environment keys publicly; they should be treated as secret.
The Server-side SDKs can operate in 2 different modes:
- Remote Evaluation
- Local Evaluation
It's important to understand which mode is right for your use case, and what the pros and cons of each one are. This is detailed below.
Remote Evaluation
In this mode, every time the SDK needs to get Flags, it will make a request to the Flagsmith API to get the Flags for the particular request.
Remote Evaluation is the default mode; initialise the SDK and you will be running in Remote Evaluation mode.
This is the same way that the Client-side SDKs work.
Local Evaluation
In this mode, all flag values are calculated locally, on your server. The Flagsmith SDK includes an implementation of the Flag Engine, and the engine runs within your server environment within the Flagsmith SDK.
You have to configure the SDK to run in Local Evaluation mode. See the SDK configuration options for details on how to do that in your particular language.
When the SDK is initialised in Local Evaluation mode, it grabs the entire set of details about the Environment from the Flagsmith API. For a given Environment, this includes:
- Flags and flag values
- Segments, segment rules, and segment overrides
- Identity overrides
This full complement of Environment data enables the Flagsmith SDK to run the Flag Engine locally and natively within your server infrastructure.
When using identity overrides in local evaluation:
- Keep overrides count under 1500-2000, depending on flag value size.
- Make sure your environment settings enable it.
- Provide a full set of traits when requesting identity flags.
The SDK has to request all of the data about an Environment in order to run. Because some of this data could be sensitive (for example, your Segment Rules), the SDK requires a specific Server-side Environment Key.
The benefits to doing this are mainly one of latency and performance. Your server-side code does not need to hit the Flagsmith API each time a user requests their flags - the flags can be computed locally. Hence it does not need to block and wait for a response back from the Flagsmith API.
In order to keep their Environment data up-to-date, SDKs running in Local Evaluation mode will poll the Flagsmith API regularly and update their local Environment data with any changes from the Flagsmith API. By default the SDK will poll the Flagsmith every 60 seconds; this rate is configurable within each SDK.
It's important to understand the pros and cons for running Local Evaluation.
All our Client-side SDKs run in Remote Evaluation mode only; they cannot run in Local Evaluation mode. The reason for this is down to data sensitivity. Because some of this data could be sensitive (for example, your Segment Rules), we only allow Client-side SDKs to run in Remote Evaluation mode.
Because Clients are almost always operating remotely from your server infrastructure, there is little benefit to them running in Local Evaluation mode.
Networking Model
When are network requests made, and when do you need to consider network latency? It depends on your evaluation mode, and whether you are using Client-side or Server-side SDKs!