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:
- No environment config — if the flag has no configuration for this environment, return the default value with
reason: 'not_found' - Disabled — if the flag is disabled in this environment, return
falsefor boolean flags or the default value for other types, withreason: 'disabled' - Evaluate rules — iterate through targeting rules in order. If a rule matches, return its
returnValuewithreason: 'rule_match' - 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'
- Boolean flags return
Example
Given a boolean flag new-checkout that is enabled with two rules:
| # | Attribute | Operator | Value | Return Value |
|---|---|---|---|---|
| 1 | email | contains | @acme.com | true |
| 2 | country | in | ["US", "CA"] | true |
Evaluating with different contexts:
| Context | Result | Reason |
|---|---|---|
{ email: "jane@acme.com" } | true | rule_match (rule 1) |
{ country: "US" } | true | rule_match (rule 2) |
{ country: "JP" } | true | default (enabled boolean) |
| (flag disabled) | false | disabled |
Pages
- Operators — all 10 operators with examples
- Percentage Rollouts — consistent hashing algorithm
- Rule Ordering — first-match-wins semantics