Switchflag
Evaluation

Rule Ordering

How targeting rules are evaluated in order with first-match-wins semantics.

First match wins

Rules are evaluated in the order they appear. The first rule that matches determines the result — subsequent rules are skipped.

Rule 1: email contains "@acme.com"  → return true
Rule 2: country in ["US", "CA"]     → return true
Rule 3: percent at 10               → return true
(no match)                           → return default value

If a user matches Rule 1 and Rule 2, only Rule 1's return value is used.

Why order matters

Consider two rules on a boolean flag:

#RuleReturn Value
1percent at 50true
2email contains @acme.comtrue

With this ordering, internal users (@acme.com) are subject to the 50% rollout — they may or may not see the feature.

Swap the order:

#RuleReturn Value
1email contains @acme.comtrue
2percent at 50true

Now internal users always see the feature (Rule 1 matches first), and everyone else is in the 50% rollout.

Best practices

  1. Put specific rules before broad rules — target known users/groups first, then use percentage rollouts for everyone else
  2. Put deny rules early — if you want to exclude certain users, place those rules first with a false return value
  3. Use percentage rules last — they're typically the catch-all for gradual rollouts

Example: staged rollout with internal access

#AttributeOperatorValueReturn Value
1emailendsWith@yourcompany.comtrue
2countrynotIn["US", "CA"]false
3percent25true

This gives:

  1. All internal users see the feature
  2. Users outside US/CA are excluded
  3. 25% of remaining US/CA users see the feature