Skip to main content

Client vs Server SDKs

Statsig offers client and server SDKs to enable experimentation and feature management across different parts of your application. This document outlines when you should choose each.

Overview

Client SDKs run in code that executes on end-user devices, like a website, mobile app, video game, or smart TV app. Server SDKs run on your servers (typically in the cloud), like a web server or API server.

Many customers deploy both Server and Client SDKs, letting them gate features on both the client- and server-side for the most control. While this is common, you can get value from Statsig by starting with just one.

Usage

Client and Server SDKs follow a similar pattern of setup and usage in-code:

  1. Initialize: Setup the SDK and download the latest values
  2. Check an experiment/gate: Reference those values to assign an experiment or flag a feature
  3. Logging custom events: log important app metrics to power your analyses
note

After initialization, both Client and Server SDKs evaluate experiments/gates without a network request, and typically in less than 1ms. Checks in the Statsig SDKs are designed to be very efficient.

Conceptual Differences:

  • Data Privacy: The Server SDK is presumed to be a secure, multi-user environment, so Server SDKs have access to the full ruleset describing each experiment and gate. Client SDKs fetch only the value for a single user, avoiding exposing the definition of your configurations.
ServerClient
PrivacyYour servers are presumed to be a secure, multi-user environment, so Server SDKs have access to the definition of all configurations in your projectAll evaluations are precomputed on Statsig servers and sent down to you client applications. Names are obfuscated, but a savvy user may be able to glean information from the raw response
Evaluation PerformanceEvaluations are done real-time, without a network request. Very complex configurations can take longer to compute, but in practice, this is rarely an issue.As all evaluation is precomputed, gate and experiment checks are effectively a dictionary lookup with some computation used for creating and flushing exposure events
Initialization PerformanceThe SDK will make an upfront request for configuration files, then continually poll for any changes to your configurations, updating its internal state when a change is detectedClient SDKs download configurations when you initialize, before which, the SDK may not have usable values. The values aren't updated mid-session unless you explicitly call updateUser. Additional options are available for performant initialization, see Initializing
UsersServer SDKs are designed to run against multiple users, and all SDK methods require a user object for evaluation/loggingClient SDKs are designed to be run with one user at a time. All evaluations are loaded once up front during initialization, and every event logged uses that user object
InfrastructureServer SDKs require you to host your own backend servicesClient SDKs run entirely on the client and utilize Statsig's servers

Usage Differences:

ServerClient
InitializingRequires only a secret key, downloads the entire ruleset and syncs it in the backgroundRequires a client key and a user object. Before/during initialization, the SDK will attempt to fallback to cached values.
Checking an ExperimentRequires a user object which is evaluated locally (without a network request) against a ruleset persisted in memoryDoes not require a user object, uses a dictionary lookup for values fetched during initialize()
User IdentifiersPass any and all useful user identifiersPass any useful identifiers, the SDK also generates a "StableID", Statsig's anonymous ID you can use to experiment on a user per-device
Logging EventsRequires a user objectDoes not require a user object. Note, there is some risk of adblocking log events on client SDKs, which can be minimized by setting up a Custom Proxy
Flushing EventsBatched and flushed by the SDK every 60 secondsBatched and flushed by the SDK every 10 seconds
Updating ConfigurationsPoll Statsig servers for updates every 10 seconds by default (configurable), Streaming possible with some Server SDKs and the Statsig Forward ProxyConfiguration persists until next initialize or updateUser call, recommended to call initialize at the start of each user session

Available SDKs

Client SDKs

Server SDKs

For more detailed information on each SDK, please refer to their respective documentation pages.

Got questions? Join the Statsig engineering and product team on the Statsig Slack channel and ask away!