Client SDK vs server SDK
Context handling differs significantly between client-side and server-side SDKs due to their different operational models.
Context handling comparison
Client-side SDKs
Client-side SDKs handle one active user or session:
- Provide context at initialization and update via
identify() - SDK fetches variations for that specific context and caches them
- When calling
variation(), no need to provide context anymore - Evaluations happen remotely via an evaluation endpoint
Server-side SDKs
Server-side SDKs evaluate for many users:
- No context required at initialization
- SDK downloads all flag rules at startup
- Pass context on every
variation()call:variation(flag, context, fallback) - SDK calculates variations against locally cached rules
Evaluation flow
Server-side evaluation
Application Request → Create Context → Call variation(flag, context, fallback)
↓
SDK evaluates locally using cached rules
↓
Return variation
Client-side evaluation
Page Load → Initialize SDK with context → SDK fetches user's variations
↓
Cache variations locally
↓
Call variation(flag) // No context needed
When to use each
Use server-side SDKs when
- Evaluating flags for multiple different users or entities
- Running backend services or APIs
- Need to keep flag rules private
- Evaluating flags in high-security contexts
Use client-side SDKs when
- Evaluating flags for a single active session
- Running in browsers or mobile apps
- Need real-time flag updates for the current user
- Implementing user-specific feature rollouts
Updating contexts
Client-side context updates
Use identify() to update the context:
const ldclient = LaunchDarkly.initialize(clientId, context);
// User logs in
ldclient.identify({
kind: "user",
key: "user-123",
name: "Jane Doe",
email: "jane@example.com"
});
The SDK will fetch new variations for the updated context.
Server-side context changes
Simply pass a different context to variation():
// Evaluate for user 1
const variation1 = ldclient.variation("flag-key", userContext1, false);
// Evaluate for user 2
const variation2 = ldclient.variation("flag-key", userContext2, false);
No SDK reconfiguration needed.
Performance considerations
Client-side SDKs
- Initial page load includes SDK initialization time
- Subsequent evaluations are instant (served from cache)
identify()calls require network round-trip- Consider bootstrapping to eliminate initialization delay
Server-side SDKs
- Initialization happens once at application startup
- All evaluations are local and extremely fast
- No per-request network overhead
- Consider persistent stores for daemon mode deployments