Switchflag
Evaluation

Evaluation Engine

How the Switchflag evaluation engine resolves flag values using targeting rules, percentage rollouts, and default values.

The evaluation engine runs client-side (in the SDK) after fetching the flag configuration from the API. There's no server round-trip per evaluation — the logic runs locally.

Evaluation flow

When you call getFlag(key, context), the engine follows this decision tree:

  1. No environment config — if the flag has no configuration for this environment, return the default value with reason: 'not_found'
  2. Disabled — if the flag is disabled in this environment, return false for boolean flags or the default value for other types, with reason: 'disabled'
  3. Evaluate rules — iterate through targeting rules in order. If a rule matches, return its returnValue with reason: 'rule_match'
  4. Default — if no rules matched and the flag is enabled:
    • Boolean flags return true (enabled = on)
    • Other types return the flag's defaultValue
    • Reason is 'default'

Example

Given a boolean flag new-checkout that is enabled with two rules:

#AttributeOperatorValueReturn Value
1emailcontains@acme.comtrue
2countryin["US", "CA"]true

Evaluating with different contexts:

ContextResultReason
{ email: "jane@acme.com" }truerule_match (rule 1)
{ country: "US" }truerule_match (rule 2)
{ country: "JP" }truedefault (enabled boolean)
(flag disabled)falsedisabled

Pages