Flag Evaluation in Flagsmith

Flag Evaluation in Flagsmith

How one simple question, "should this person see this feature?", gets answered in milliseconds, safely, for millions of users. A plain-English guide to identities, traits, segments, percentage rollouts, and remote versus local evaluation.

Imagine you run a busy restaurant and you want to add a new dessert to the menu. You are not sure people will like it. So you decide to offer it to only a few tables first, watch what happens, and then slowly offer it to everybody. If the dessert turns out to be a disaster, you quietly remove it from the menu without rebuilding the kitchen.

Software teams do exactly this with something called a feature flag. A feature flag is a switch that lives outside your code and decides whether a feature is on or off. Flagsmith is a popular open-source platform that stores these switches and hands them out to your apps. The clever part, and the topic of this guide, is flag evaluation: the process of working out, for one particular user at one particular moment, what the switch should say.

By the end of this article you will know what gets evaluated, in what order, where the work happens, how it stays fast, what can go wrong, and how to design flags that do not hurt you later. Every new word is explained the first time it appears. No code is needed. Just curiosity.

1What a Feature Flag Is and Why It Needs Evaluating

Before we talk about evaluation, we need to be clear about what is being evaluated and why a simple on/off switch is not so simple.

The simplest possible flag

A feature flag is a named setting. It has a name, such as “new-checkout-page”, and a state, which is usually “on” or “off”. Your application asks a question like “is new-checkout-page on?” and then behaves differently depending on the answer. If the answer is yes, the user sees the new checkout page. If the answer is no, the user sees the old one.

The magic is that the answer can change without anybody changing the application. No new version is built. No server is restarted. Someone simply flips the switch in a dashboard, and the next time the app asks, it hears the new answer.

Analogy

Think of a flag like the dimmer switch in a school hall. The wiring in the walls stays exactly the same. Whoever stands at the switch decides how bright the room is. The room does not need to be rebuilt to get a different amount of light.

Why one global answer is not enough

If every user got the same answer all the time, a flag would be a blunt tool. Real teams want finer control. They want to say “turn it on for our own employees first”, or “turn it on for ten percent of users”, or “turn it on only for customers on the premium plan”, or “turn it on for everybody except people in one country where a law is different”.

To honour these wishes, the system has to look at who is asking and what is known about them, and then pick the right answer for that person. That decision process has a name: flag evaluation.

i
Key idea

Flag evaluation is simply “given this user and this flag, what value should they get?” Everything else in this article is about how Flagsmith answers that question correctly, quickly, and safely.

Why this matters in production

Companies that release software many times a day cannot afford to show every new idea to every customer at once. Large engineering organisations such as Facebook, Google, Netflix, and Etsy have publicly described using flag-like systems for gradual rollouts, internal testing, and experiments. The basic benefit is the same everywhere: you separate deploying code from releasing a feature. Code can reach production quietly and be switched on later, for the right people, at the right speed.

That separation only works if evaluation is trustworthy. A wrong answer can show a half-finished feature to every customer, or hide a paid feature from someone who paid for it. So evaluation must be predictable, explainable, and fast.

2Meet Flagsmith and Its Building Blocks

Flagsmith has a small set of ideas. Learn these eight words and the rest of the article will feel natural.

Flagsmith is an open-source feature flag and remote configuration service. You can run it yourself or use the hosted version. It gives you a dashboard where people manage flags, and it gives your applications a way to ask for flag values. Here are the building blocks, from the largest to the smallest.

Top level

Organisation

The company or team account. It holds people, billing, and all the projects. Think of it as the whole school.

Container

Project

One product or application, such as “mobile app” or “web store”. It owns a list of features. Think of it as one classroom.

Stage

Environment

A copy of the project’s settings for one stage of life, such as Development, Staging, or Production. Each environment has its own values and its own keys.

The switch

Feature

The named flag itself, such as “new-checkout-page”. It exists once per project but has a separate state in every environment.

The setting

Feature state

The actual on/off and optional value of a feature inside one environment. This is the default answer before any special rules apply.

The person

Identity

A user, device, or account, identified by a unique text label. It lets Flagsmith give different answers to different people.

The facts

Trait

A fact about an identity, like “plan = premium” or “country = India”. Traits are what rules look at.

The group

Segment

A saved group of identities defined by rules about their traits. For example, “all premium customers in Europe”.

Environments deserve a second look

Beginners often assume a flag is either on or off everywhere. In Flagsmith, a flag has a separate state in each environment. You can have “new-checkout-page” switched on in Development so engineers can test it, off in Staging, and off in Production until the team is ready. Each environment also has its own environment key, a long random text string that your application sends to prove which environment it is asking about. Flipping the Development switch can never accidentally change Production, because they are different rooms with different keys.

Flags carry values, not only on/off

A feature state has two parts. The first is the enabled setting, which is true or false. The second is an optional value, which can be a piece of text, a number, or a true/false setting. This second part is called remote configuration. For example, a flag called “max-upload-size” might be enabled with a value of 25, meaning 25 megabytes. Change the value to 50 in the dashboard and every app that asks next will receive 50. Evaluation returns both parts together.

Analogy

A feature is like a thermostat in a house. The enabled setting is the power button. The value is the temperature you dial in. Each room (environment) has its own thermostat, so changing the garage does not change the bedroom.

3What “Flag Evaluation” Actually Means

Evaluation is a function: inputs go in, one answer per flag comes out. Seeing it that way removes most of the mystery.

The inputs

Flagsmith needs three kinds of input to evaluate a flag.

  • Which environment is asking. This comes from the environment key your application presents.
  • Who is asking. This is the identity, a unique text label such as a user ID. It is optional. If you leave it out, you only get the environment-wide defaults.
  • What is known about them. These are the traits, the small facts such as plan, country, or app version.

The output

For every feature in the environment, the result contains the feature name, whether it is enabled, and its value. Your app usually reads one or two of these flags and ignores the rest. Often the app receives the whole list at once, and then asks local questions such as “is this one enabled?” without making another trip across the network.

The three layers of the answer

Flagsmith builds the answer in layers, and the most specific layer always wins. We will study this in detail in a later chapter, but here is the short version.

1st
Identity override: a rule written for one specific person
2nd
Segment override: a rule written for a group
3rd
Environment default: the answer for everyone else
Analogy

Picture a school rule: “Everybody wears the blue uniform.” That is the environment default. Then there is a group rule: “The football team wears red on match days.” That is a segment override. Finally, a note on file says “Priya wears green because of a school play.” That is an identity override. If Priya is on the football team on match day, the note about Priya wins, because the most personal rule is the most specific.

Evaluation is deterministic

The word deterministic means the same inputs always give the same output. If you evaluate the same user against the same settings twice, you get the same answer both times. This matters a lot for percentage rollouts. A user who is in the “ten percent” group today should not drop out tomorrow just because they refreshed the page. Flagsmith achieves this by turning identities into numbers using a stable calculation, which we will explain in the chapter on percentage rollouts.

!
Common confusion

Evaluating a flag is not the same as changing a flag. People change flags in the dashboard. Applications evaluate flags many thousands of times per second. Evaluation only reads. It never modifies settings.

4Architecture and Core Components

Where does the answer come from, and which pieces of machinery are involved? Here is the whole picture in one diagram.

At a high level, Flagsmith has a place where humans manage flags, a place where data is stored, a place where flag requests are served, and the libraries inside your apps that talk to it. Let us name each part.

flowchart LR
    ADMIN["Team member using the Dashboard"] --> DASH["Flagsmith Dashboard"]
    DASH --> CORE["Core API - manages flags, segments, identities"]
    CORE --> DB[("Primary database")]
    CORE --> AUDIT["Audit log and webhooks"]
    CORE --> EDGE["Flag serving layer - fast read path"]
    APPC["Client app - browser or mobile"] --> CSDK["Client-side SDK"]
    APPS["Backend service"] --> SSDK["Server-side SDK"]
    CSDK -->|"environment key"| EDGE
    SSDK -->|"remote evaluation"| EDGE
    SSDK -->|"server-side key - environment document"| CORE
    SSDK --> LOCAL["Local evaluation engine inside the SDK"]
    EDGE --> CACHE["Cache"]
    CACHE --> DB
FIG 1: The main parts of a Flagsmith setup and how flag requests travel through them.

The pieces explained

Humans

Dashboard

The web page where people create flags, build segments, and flip switches. It talks to the Core API behind the scenes.

Brain

Core API

The service that owns all the data: features, environments, segments, identities, users, permissions. All changes go through it.

Memory

Database

The durable storage for settings. If every server restarted, the database is what remembers the flags.

Fast path

Flag serving layer

The part optimised for answering “what are the flags?” millions of times. The hosted Flagsmith offering uses a separate, edge-optimised serving path for this so reads stay fast and do not compete with dashboard work.

In your app

SDK

A software development kit is a ready-made library you add to your app. It handles keys, requests, caching, and sometimes the evaluation itself.

Optional

Local evaluation engine

A copy of the evaluation logic that lives inside certain server-side SDKs, so decisions can be made without calling the network each time.

Read path versus write path

Engineers like to split a system into a write path and a read path. The write path is what happens when a person changes a flag. It is rare, perhaps a few times a day, and it can afford to be careful and slow. The read path is what happens when an app asks for flags. It happens all the time, perhaps millions of times per minute, and it must be extremely quick. Flagsmith’s design keeps these two paths separate in spirit: changes flow through the Core API into storage, and then are published to a layer built to answer reads.

Analogy

A library has a back office where librarians catalogue new books (the write path) and a front desk where visitors look things up (the read path). You would never ask visitors to wait while a librarian finishes cataloguing. Keeping the two separate keeps the front desk quick.

5The Evaluation Order: Who Wins When Rules Collide

The heart of flag evaluation is a strict order of precedence. Memorise this order and you can predict almost any answer Flagsmith gives.

When Flagsmith evaluates a flag for an identity, it walks through a short list of questions. It stops as soon as one of them gives an answer.

flowchart TD
    START["Request: environment key plus identity plus traits"] --> Q1{"Does this identity have its own override for the feature?"}
    Q1 -->|"Yes"| R1["Return the identity override"]
    Q1 -->|"No"| Q2{"Does the identity match any segment that overrides the feature?"}
    Q2 -->|"Yes"| PICK["Pick the matching segment with the highest priority"]
    PICK --> R2["Return that segment override"]
    Q2 -->|"No"| Q3{"Is the feature multivariate?"}
    Q3 -->|"Yes"| HASH["Hash the identity into a number from 0 to 100"]
    HASH --> R3["Return the matching variation or the control value"]
    Q3 -->|"No"| R4["Return the environment default"]
FIG 2: The order in which Flagsmith decides which answer applies to one identity.
1

Identity override

A person-specific setting created in the dashboard for one identity and one feature. It beats everything else. It is perfect for “let this one customer try it early” or “always keep this tester on the old version”.

2

Segment override

A group-specific setting. Flagsmith checks the identity’s traits against every segment that has an override for this feature. If several match, the one with the highest priority wins.

3

Multivariate allocation

If the feature has several variations with percentages, the identity is placed into one of them in a stable way. If no variation catches the identity, it gets the original control value.

4

Environment default

The base setting for the environment. Everyone who was not caught by something more specific lands here.

How segment priority works

One identity can belong to many segments at once. A person might be in “premium customers”, “Indian users”, and “beta testers” all at the same time. If more than one of those segments overrides the same feature, which one speaks first? Flagsmith lets you order the segment overrides for each feature, and the one at the top of the list wins. In the dashboard you can drag overrides up and down to change this. Only the winner matters. The others are not blended or averaged.

i
Tip

Put your narrowest, most important segments at the top of the order. A segment like “internal staff” should usually sit above a broad segment like “all users in the beta”. Otherwise the broad rule will catch your staff first.

A worked example in words

A streaming service has a flag called “new-player”. The environment default is off. A segment called “beta-testers” has an override turning it on. A segment called “old-smart-tvs” has an override turning it off, because the new player does not run on old televisions. The old-smart-tvs override is placed above beta-testers in priority.

Now consider three people. Asha is a beta tester on a new phone: she matches beta-testers only, so she sees the new player. Ben is a beta tester on an old television: he matches both segments, but old-smart-tvs sits higher, so he sees the old player. Chitra is a regular user on any device: she matches neither, so she gets the environment default, off. Finally, imagine the support team gives Ben an identity override turning the flag on to investigate a bug. Now Ben sees the new player, because identity overrides sit above all segments.

Analogy

Think of airport security lanes. There is a default lane for everyone. There are group lanes such as “crew” or “priority”. And sometimes a staff member walks one particular person through personally. The more personal the arrangement, the more it overrides the general rules.

6Identities and Traits in Depth

Identities and traits are the raw material for every targeted decision. Treat them with care and your rules stay simple.

What is an identity?

An identity is a label that tells Flagsmith “this is the same entity as before”. Most teams use their own user ID. Some use an account ID, a device ID, or an organisation ID. The choice matters because the identity is the unit of consistency. If you use a user ID, every device that user owns will get the same flag answers. If you use a device ID, the same human on a phone and a laptop could see different experiences.

Analogy

An identity is like a library card number. The library does not need your life story to recognise you. It only needs the number, and then it can look up your records and treat you consistently every visit.

What is a trait?

A trait is a named fact about an identity: a key and a value. Examples are “plan” with the value “premium”, “country” with the value “IN”, “app_version” with the value “4.2.0”, or “signup_days” with the value 12. Traits can be text, whole numbers, decimals, or true/false.

Traits can reach Flagsmith in two ways. Your application can send them at the moment it asks for flags, which keeps them fresh. Or they can be stored with the identity in Flagsmith so they are remembered next time. When the hosted service evaluates remotely and traits are sent along with the request, those traits are saved against the identity, so later requests and segment rules can use them. Newer versions also support transient identities and traits, which are used for a single evaluation and not saved. That is handy for sensitive or fast-changing facts you do not want stored.

Anonymous users

What if the person is not logged in? You have two options. You can generate a random identifier for the visitor and keep it in the browser, so the same visitor keeps seeing the same experience on that browser. Or you can skip the identity altogether and ask only for environment-level flags. In that case no segment or percentage logic can be used, because Flagsmith has nobody to look at. The user gets the environment default.

!
Watch out

If you generate a fresh random identifier on every page load, the same person looks like a brand-new stranger each time, and percentage rollouts will flicker. Store the identifier and reuse it.

Choosing good traits

Good traits

  • Stable facts such as plan, region, role, or signup date
  • Facts you already know at request time, so no extra lookups are needed
  • Short, clearly named keys that everybody on the team understands
  • Values that need no personal details, such as a plan name instead of an email address

Risky traits

  • Private data like emails, phone numbers, or health details
  • Values that change every second and flood the system with updates
  • Vague keys such as “type” or “flag1” that nobody can decode later
  • Traits that exist for only some users, which creates surprises when a rule expects them

7Segments and Rules in Depth

A segment turns a vague wish like “our power users in Europe” into a precise, repeatable test that the engine can run in a blink.

How a segment is built

A segment is made of one or more rules. A rule contains one or more conditions. A condition looks at one trait and compares it with a value using an operator. For example: the trait “plan” equals “premium”. Each rule says how its conditions combine:

  • All: every condition in the rule must be true, like saying “and”.
  • Any: at least one condition must be true, like saying “or”.
  • None: no condition may be true, like saying “not any of these”.

When a segment has more than one rule, an identity must satisfy all of the rules to be in the segment. Rules can also be nested inside rules for more complex shapes, though simpler is almost always better.

The operators you can use

Operator familyWhat it checksFriendly example
Equals / does not equalExact match of a traitcountry equals “IN”
Greater / less than (and inclusive versions)Number comparisonssignup_days is less than 30
Contains / does not containPart of a piece of textemail contains “@school.edu”
RegexMatches a text patternapp_version looks like 4.x
InValue is in a listcountry is one of IN, SG, AE
Is set / is not setWhether the trait exists at allbeta_opt_in is set
Percentage splitPlaces a stable share of identities into the segment10 percent of all identities
ModuloNumber remainder checks, useful for shardinguser_number divided by 10 leaves 3
Version comparisonUnderstands version numbers when you mark the value as a versionapp_version is at least 4.2.0
i
Tip

Version numbers are text, and text sorts the wrong way. The text “10.0” comes before “9.0” alphabetically. Use the version-aware comparison for app versions so 10.0 is correctly treated as newer than 9.0.

What happens when a trait is missing?

If a rule looks at a trait the identity does not have, the condition generally does not match, with the “is not set” operator being the natural exception. This is usually what you want, but it can surprise you. If you write “country is not equal to US” and a user has no country trait at all, do not assume they will be included. Always test with real examples that have missing data.

Segments are reusable

A segment is defined once at the project level and can then be used by overrides on many features. Change the segment’s definition and every feature using it changes behaviour together. That is powerful and slightly dangerous: editing “premium customers” to also include trial users affects every feature that targets it. Teams keep segment names descriptive and review changes with the same care they apply to code.

Analogy

A segment is a saved search in an email app, such as “unread messages from my manager”. You define it once, and it automatically collects whatever matches the rule today, even for messages that did not exist yesterday. You do not hand-pick people; you describe them.

8Percentage Rollouts and Multivariate Flags

How do you give a feature to exactly ten percent of people, and make sure the same ten percent stay in tomorrow? The answer is stable hashing.

Two different ideas that sound alike

Flagsmith offers two ways to spread something across a population. They are easy to mix up.

Rollout

Percentage split in a segment

You create a segment that contains a chosen percent of all identities, then attach an override to it. People inside get the new behaviour; the rest do not. It answers “who is in the first wave?”.

Experiment

Multivariate flag

One feature has several possible values, such as a red, green, or blue button, each with its own percentage. It answers “which version does this person see?”.

How the same person gets the same answer

A hash function is a recipe that turns any piece of text into a number in a repeatable way. The same text always gives the same number, but similar-looking texts give wildly different numbers. Flagsmith feeds identifying details of the feature or segment and of the identity into such a recipe and converts the result into a position between 0 and 100. If the position falls inside the allowed range, the identity is in. Because the recipe never changes, the position of a given identity never changes either.

This has a lovely side effect. If you raise a rollout from ten percent to twenty percent, the people who were already inside generally stay inside, and new people are added on top. Nobody who had the feature loses it just because you widened the net.

Analogy

Imagine every student has a lucky number from 0 to 100 written permanently on their school ID. If the teacher says “everyone with a number under 10 goes on the field trip”, the same students go every time. If she changes it to “under 20”, all the earlier students still qualify, and more are added.

Multivariate options

A multivariate feature has a control value, which is the normal environment value, and several variations, each with a percentage. The percentages add up to at most 100. Whatever is left over keeps the control value. If you give variation A 20 percent and variation B 30 percent, then 50 percent of identities stay on the control. Each identity is placed in the same bucket every time they are evaluated, so a visitor does not see the red button on Monday and the blue button on Tuesday.

There is an important limit. Multivariate allocation needs an identity to hash. If you ask for flags without an identity, there is nobody to place into a bucket, so you get the control value.

Why stickiness matters for experiments

If you are measuring whether a new button increases purchases, you must show each person the same version for the whole experiment. Otherwise the numbers become meaningless, because one person could be counted in both groups. Stable hashing gives you that consistency without keeping a giant table of who saw what. Flagsmith itself decides the variation; the measuring of results is usually done by connecting Flagsmith to your analytics tool, which receives information about which variation each user saw.

!
Watch out

Do not change percentages and also edit the segment rules in the middle of an experiment. You will mix groups and ruin the comparison. Decide the setup first, then leave it alone until you have enough data.

9Remote Evaluation Versus Local Evaluation

There are two places where the decision can be made: on Flagsmith’s servers, or inside your own application. This choice shapes speed, cost, and freshness.

Remote evaluation: ask the expert each time

In remote evaluation, your SDK sends the identity and traits to Flagsmith over the internet. Flagsmith’s servers run the rules and send back the finished list of answers. This is the default and the only mode available to client-side SDKs (the ones in browsers and mobile apps). It keeps rules private and your app simple, at the price of one network round trip for each identity you evaluate.

sequenceDiagram
    participant U as User
    participant A as App with SDK
    participant F as Flagsmith serving layer
    participant D as Stored settings
    U->>A: Opens the app
    A->>F: Request flags with environment key, identity, traits
    F->>D: Load environment state, segments, overrides
    D-->>F: Settings
    F->>F: Run the evaluation order
    F-->>A: Flag names, enabled states, values
    A->>A: Keep the answers in memory
    A-->>U: Shows the right experience
FIG 3: Remote evaluation, where Flagsmith’s servers make the decision.

Local evaluation: carry the rulebook with you

In local evaluation, a server-side SDK downloads a complete description of the environment, often called the environment document. It contains all the features, their values, the segments and their rules, multivariate options, and in recent versions the identity overrides. The SDK then makes decisions on its own machine, with no network call per decision. It refreshes the document on a timer, which by default is about once every sixty seconds, so changes arrive shortly after they are made.

flowchart TD
    S["Backend service starts"] --> K["SDK uses server-side key"]
    K --> DL["Download environment document"]
    DL --> MEM["Hold document in memory"]
    MEM --> REQ["Incoming request with identity and traits"]
    REQ --> ENG["Local engine runs the evaluation order"]
    ENG --> OUT["Answer in microseconds, no network call"]
    MEM --> TIMER["Refresh timer about every 60 seconds"]
    TIMER --> DL
FIG 4: Local evaluation, where the SDK holds the rulebook and decides by itself.
Analogy

Remote evaluation is phoning a help desk every time you have a question. Local evaluation is carrying a printed manual in your bag and refreshing it every minute. The manual is faster for each question, but it can be slightly out of date, and it is a bigger thing to carry.

Side-by-side comparison

QuestionRemote evaluationLocal evaluation
Who decides?Flagsmith serversThe SDK inside your service
Key usedClient-side or server-side environment keyServer-side key only
Speed per decisionOne network round tripAlmost instant, in memory
Freshness of changesSeen on the next request, subject to cachingSeen at the next refresh, about a minute by default
Traits stored by Flagsmith?Can be saved with the identityUsed for the decision only, not saved
If Flagsmith is unreachableNeeds fallbacks or cached answersKeeps working with the last known document
Best forBrowsers, mobile apps, simple servicesHigh-traffic backends that evaluate constantly
i
Why not local everywhere?

Local evaluation downloads every rule in the environment, including segments that mention other customers’ traits. That document must never be shipped to a browser or phone, where anyone could read it. This is exactly why only server-side keys unlock it.

10The Life of One Flag Request, Step by Step

Let us follow a single request from the moment a user taps a button to the moment the screen changes, so you can see every hand-off.

1

The app starts and identifies the user

The application knows who is signed in. It prepares an identity label and a few traits such as plan and country.

2

The SDK sends or prepares the request

In remote mode, the SDK sends the environment key, the identity, and the traits to Flagsmith. In local mode, it simply uses the document it already holds.

3

The environment is found

The environment key tells Flagsmith which environment’s settings to use. A wrong or revoked key is rejected here.

4

Identity and segments are matched

The engine looks for identity overrides, then tests the traits against every segment that touches a feature.

5

Winners are chosen

For each feature, the evaluation order from chapter 5 picks one result. Multivariate features run their stable hash.

6

The answer list is returned

The result is a list of features with enabled states and values. It is usually small, often a few kilobytes even for hundreds of flags.

7

The SDK keeps the answers

The SDK stores the result in memory, and often in local storage on a device, so the next question is answered instantly.

8

The app branches

The code asks whether the feature is enabled or reads its value, then shows one experience or the other. Optionally, the SDK records that the flag was used, for analytics.

Why fetching all flags at once is smart

Many beginners expect one network call per flag. In practice the SDK fetches the whole set for the identity in one trip, and later questions are answered from memory. This design means that adding a fiftieth flag to your app does not add a fiftieth network call. It also means all flags you read in one screen are consistent with each other, because they came from the same moment in time.

Analogy

It is like asking a waiter for the full menu once instead of calling the kitchen to ask about each dish separately. You get everything in one trip and then choose from the paper in your hand.

11Client-Side and Server-Side SDKs, and Their Keys

Where your code runs decides which key you may use and which evaluation modes you may choose. Getting this wrong is the most common security slip.

Public

Client-side SDKs

Run in places the user controls: web browsers, phones, desktop apps. They use the client-side environment key, which is safe to be visible because it can only read flags for the identity you ask about, not the full rulebook.

Secret

Server-side SDKs

Run on your own servers where users cannot see the code. They use a secret server-side key, which unlocks extra abilities such as local evaluation and downloading the whole environment document.

Why two kinds of key exist

The client-side key is meant to be embedded in an app that thousands of strangers will download. Anyone can pull it out and read it. So Flagsmith designs it to be low-power: it can ask “what are the flags for this identity?”, and nothing more sensitive. The server-side key is like a staff pass. If it leaks, an outsider could download your entire environment document, including your segment definitions and the names of your experiments. Treat it like a database password.

!
Never do this

Never put a server-side key into a browser bundle, a mobile app, a public repository, or a screenshot. If one ever leaks, create a new key and revoke the old one straight away. You can hold more than one server-side key at a time, which makes rotation smooth.

Who should be allowed to see which flag?

Remember that the flags you send to a browser are visible to the user. If a flag’s name or value hints at a secret plan, such as “launch-competitor-killer-feature”, a curious person can read it in their browser tools. A good habit is to use neutral, boring flag names for anything that reaches the client, and to keep truly confidential switches on the server side only. Also never use a client-side flag as the only protection for something sensitive. A user can alter what their own browser displays, so real access checks must happen on your server.

Trust boundaries in one sentence

Anything running on a device the user owns can be inspected, so it can only be trusted to display things. Anything running on your servers can be trusted to decide and protect things.

12Performance, Caching, and Scalability

A flag check sits in the hot path of your application, so it has to be nearly free. Here is how the whole stack keeps it that way, even at millions of requests per minute.

Why flag reads are easy to scale

Flag evaluation has a very friendly pattern: reads are enormously more common than writes. A flag might be read ten million times a day and changed twice. Systems with this pattern respond well to caching, which means keeping a ready-made copy of an answer close to where it is needed so it need not be rebuilt each time.

The layers of caching

Layer 1

In the SDK

After the first fetch, flags live in memory, and on devices often in storage too. Most “is this on?” questions never leave the app.

Layer 2

In the serving layer

Flagsmith keeps recent environment data ready for fast replies, so it does not hit the main database on every request.

Layer 3

Near the user

The hosted service uses a separate edge-optimised read path so requests are answered from a place that is geographically close and designed for reads.

Layer 4

In the engine

With local evaluation, the whole environment sits in memory inside your service, and a decision costs a tiny amount of computing time rather than a network trip.

The freshness trade-off

Every cache creates a gap between “the truth in the database” and “what the app currently believes”. A shorter refresh interval reduces the gap but increases traffic. A longer interval does the reverse. For most features, a delay of seconds to a minute is perfectly fine. For urgent switches, such as turning off a broken feature, teams want the change to land quickly. That is where polling intervals and, for browsers and apps, real-time updates come in. Flagsmith supports streaming updates to some client SDKs over a one-way connection called server-sent events, so a change in the dashboard can reach open apps without waiting for the next poll. Availability depends on the SDK and plan, so check what your own setup supports.

0
network calls per decision with local evaluation
1
network call to fetch all flags for an identity in remote mode
~60s
default refresh gap for the local evaluation document

Scaling to huge traffic

Picture a service with a hundred instances, each handling a thousand requests per second. If every request called Flagsmith remotely, that would be a hundred thousand flag calls every second. With local evaluation, the same fleet makes a few hundred small refresh calls per minute, each downloading one document. The load on Flagsmith drops by several orders of magnitude, and your request latency no longer includes a hop to a third-party system. Large engineering organisations follow the same idea with their own flag systems: push the rules to the edge of the fleet and decide in memory.

i
Rule of thumb

Browsers and phones: remote evaluation with a client-side key. Busy backend services: local evaluation with a server-side key. Small internal tools: whichever is simpler.

Watch your payload size

A flag response contains every feature in the environment, so hundreds of unused flags make every response larger and every device parse more. Remove dead flags regularly. Smaller payloads mean faster starts, especially on slow mobile networks.

13Reliability: What Happens When Things Break

Any network call can fail. A good flag setup makes sure that a flag problem never becomes a customer-facing outage.

The golden rule: flags must fail safe

Imagine Flagsmith becomes unreachable for a few minutes. What should your app do? It must have a sensible answer ready. For a risky new feature, the safe answer is “off”. For something that should stay visible, like a core menu, the safe answer is “on”. The decision of what is safe has to be made by humans ahead of time, flag by flag.

Tools that protect you

Fallback

Default flag handler

A function you give the SDK that supplies a value whenever a flag cannot be fetched or does not exist. It stops your code from crashing when it asks about a flag the server never heard of.

Memory

Cached flags

The SDK keeps the last good answers and keeps using them if the next fetch fails.

Offline

Offline mode

Some SDKs can read flag data from a local file you provide, so they work with no network at all, for example in tests or isolated environments.

Timeouts

Request timeouts and retries

Short timeouts stop a slow flag call from freezing a page. A small number of retries handles brief glitches without making things worse.

Failure scenarios and what you will see

What goes wrongEffect with remote evaluationEffect with local evaluation
Flagsmith briefly unreachableNew fetches fail; cached answers or defaults are usedLast downloaded document keeps being used
Wrong key configuredRequests rejected; defaults usedDocument never downloads; defaults used until fixed
Flag deleted in dashboardNext fetch no longer lists it; default handler answersDisappears at next refresh; default handler answers
Slow network on mobileStale answers shown until fetch completesNot applicable on devices
Bad rule published by mistakeAffected users see wrong behaviour until fixedSame, within the refresh gap
Analogy

A pilot does not stop flying when the radio goes quiet. There are written procedures for exactly that moment. A flag default is your procedure for “the control tower stopped talking”.

Do not forget human mistakes

The most frequent flag outage is not a server failing but a person flipping the wrong switch in the wrong environment. Flagsmith helps with colour-coded environments, an audit log, permissions, and, in higher plans, change requests that require approval and scheduled changes. Use them for Production.

14Security and Privacy of Evaluation

Flags decide who sees what. That makes them a security-relevant system, and the data you feed into them a privacy matter.

The security checklist

  • Keys: keep server-side keys in a secrets manager, not in code. Rotate them on a schedule and after any suspected leak.
  • Least privilege: give team members only the permissions they need. Not everyone should be able to change Production.
  • Audit trail: every change to a flag is recorded with who, what, and when. Review it after incidents.
  • Transport: all traffic to Flagsmith should use encrypted connections.
  • Server-side enforcement: never rely on a flag in a browser as the only barrier protecting paid or private features.

Privacy: choose your traits wisely

Traits are sent to Flagsmith and, in remote mode, may be stored with the identity. Under privacy laws such as GDPR, personal data needs a clear reason to be stored and a way to be deleted. A safe pattern is to send coarse, non-identifying facts, such as “plan = premium” or “region = EU”, rather than names or emails. Use a pseudonymous identifier, like an internal ID, instead of an email address as the identity. If you must use a sensitive value for one decision, a transient trait lets you use it without saving it.

!
Privacy tip

Ask yourself: “If this trait were printed on a poster in the office, would I be comfortable?” If not, it probably should not be a trait.

Self-hosting versus hosted

Because Flagsmith is open source, organisations with strict data rules can run it inside their own network, so identities and traits never leave their environment. Teams that prefer less work use the hosted version. The evaluation logic is the same either way.

Analogy

A client-side key is like the address printed on the front of a house. Everyone can see it, and it only tells them where to knock. A server-side key is the house key itself, and you keep it in your pocket.

15Monitoring, Analytics, and Debugging

When a user says “I do not see the new feature”, you need a calm, repeatable way to find out why.

What you can observe

Usage

Flag analytics

SDKs can optionally report how often each flag is evaluated. The dashboard shows this over time, which helps you spot flags that nobody uses anymore.

History

Audit log

A timeline of every change, so you can match a weird behaviour to a particular edit.

Inspect

Identity view

In the dashboard you can open an identity and see its traits, the segments it belongs to, and the final flag values it would receive.

Notify

Webhooks and integrations

Flag changes can be announced to chat tools, analytics products, and monitoring systems so the team stays informed.

A calm way to debug “why did this user get that value?”

1

Confirm the environment

Is the app really using the Production key, or an old Staging key from a forgotten setting?

2

Check the identity

Was the right identifier sent? A typo or an extra space creates a different person.

3

Inspect the traits

Did the app send the trait the rule needs, and with the exact spelling and type? A number sent as text will not compare as a number.

4

Look for overrides

Is there an identity override? Then check segment order. Often a higher-priority segment is quietly winning.

5

Mind the freshness gap

If the change was just made, the SDK may still hold a cached copy. Wait for the refresh or restart the test.

i
Tip

Log the flag values that influenced a request alongside your normal logs, for example “new-checkout-page: on”. When a bug report arrives, you can immediately see which version the user experienced.

Watch the health of the flag system itself

Track how long flag fetches take, how often they fail, and how often your app falls back to defaults. A rising fallback rate is an early warning that something is off, long before users complain.

16Design Patterns That Work

Flags are used in a few well-known shapes. Pick the right shape and the flag does its job cleanly and then goes away.

Release

Release flag

Hides unfinished work while code is deployed, then reveals it when ready. Short-lived. Remove it after the rollout.

Rollout

Progressive rollout

Staff first, then a small percentage, then a bigger share, then everyone. Watch error rates at each step.

Safety

Kill switch

A flag whose only job is to turn a risky or expensive feature off instantly during an incident. Long-lived on purpose.

Test

Experiment flag

A multivariate flag used to compare versions with real users. Ends when a winner is chosen.

Business

Entitlement flag

Unlocks features for a plan or customer group, such as premium. Long-lived, and often tied to billing data.

Config

Remote configuration

Uses flag values as settings, like page size or timeouts, so they can be tuned without a release.

A safe rollout recipe

Start with the flag off everywhere. Add an override for an internal staff segment and test in Production with real data. Next, add a small percentage segment, perhaps one percent, and watch your monitoring. Step up gradually: five, twenty-five, fifty, one hundred. At any sign of trouble, set the default back to off. When the feature has been fully on for a comfortable period, delete the flag and the old code path.

Analogy

A progressive rollout is like testing the water in a swimming pool with your toe, then your foot, then your leg, before you jump in. Each step tells you something, and you can always pull back.

Anti-patterns to avoid

ANTI-PATTERN 01Avoid
The problem

Flags are added and never removed. After two years, nobody knows which of four hundred flags still matter.

Why it hurts

Every old flag leaves two code paths to maintain and test. Bugs hide in rarely used combinations, and payloads grow.

Better approach

Give every temporary flag an owner and a planned removal date. Review stale flags on a regular schedule and delete the dead code together with the flag.

ANTI-PATTERN 02Avoid
The problem

Flags depend on other flags. Flag A only works if flag B is on and flag C is off.

Why it hurts

The number of combinations grows quickly, and it becomes nearly impossible to know what a user actually sees.

Better approach

Keep each flag independent. If two things must change together, put them behind one flag, or use one multivariate flag with named variations.

ANTI-PATTERN 03Avoid
The problem

Evaluating flags deep inside tight loops or in many scattered places in the code.

Why it hurts

Code becomes hard to read, hard to remove later, and may do wasted work.

Better approach

Evaluate once near the entry point of a request, pass the decision down, and keep each flag check in as few places as possible.

17Best Practices and Common Mistakes

These habits come from teams who have lived with feature flags for years. Follow them and you skip a lot of pain.

Habits worth building

  • Name flags clearly. Use names that describe the feature, not the ticket number. “new-checkout-page” beats “flag-4417”.
  • Write a description. One sentence on why the flag exists and who owns it.
  • Use tags. Label flags by team or purpose so you can filter and clean up easily.
  • Choose defaults on purpose. Decide what the app does when a flag cannot be fetched.
  • Test both states. Automated tests should cover the flag on and the flag off.
  • Roll out in small steps. Never jump from zero to everyone for a risky change.
  • Protect Production. Use permissions, approvals, and the audit log.
  • Clean up. Remove temporary flags soon after a rollout finishes.

Common mistakes

MistakeWhat happensFix
Using a server-side key in a browserAnyone can download all your rulesUse the client-side key; rotate the leaked one
Random identity on every visitRollouts flicker; experiments are pollutedStore and reuse an identifier
Forgetting a trait in some requestsUsers randomly fall out of segmentsSend traits consistently from one place
Wrong segment orderA broad rule shadows a precise onePut narrow segments above broad ones
Editing a shared segment casuallyMany features change at onceReview segment edits like code
Expecting instant change with local evaluationConfusion during the refresh gapRemember the polling interval
No default valueCrashes or odd behaviour when offlineAlways configure a fallback
Putting secrets in flag valuesValues may reach browsersKeep secrets in a proper secrets store
The best flag is the one that did its job and was then deleted.

18Real-World Usage Patterns

The same few ideas show up inside well-known engineering organisations. Here is how the patterns look in practice.

Gradual rollouts at a social network

Facebook has publicly described an internal system called Gatekeeper that controls who sees new features. New code is typically exposed to employees first, then to small slices of users, and widened as confidence grows. It is the same shape you build in Flagsmith with an internal segment followed by percentage segments.

Experiments at a streaming service

Netflix has written extensively about running controlled experiments on things like artwork and interface layouts. Each member is placed consistently into one experience so results can be compared fairly. That is the job a multivariate flag with stable hashing does for you.

Configuration flags at an online marketplace

Etsy has described its practice of shipping code continuously and using configuration flags to switch behaviour on gradually, which keeps releases small and reversible. This matches the “deploy is not release” idea at the start of this article.

Canary releases at a search giant

Google popularised sending a new version to a tiny share of traffic first and promoting it only if the numbers look healthy. A flag-based percentage rollout applies the same caution at the feature level instead of the server level.

Plan-based features at a software-as-a-service company

A typical business app has a free plan, a team plan, and an enterprise plan. A plan trait on each identity plus segments for each plan lets the product team unlock features per tier, and sales can grant a single customer an early trial with an identity override. No developer has to deploy anything.

Kill switches during an incident

When a downstream service starts failing, an engineer flips a kill switch to disable the dependent feature, protecting the rest of the product. Many large companies keep kill switches for expensive or fragile features precisely so that this takes seconds rather than a full release.

i
A note on these examples

These organisations built their own in-house systems. They are included because they show the same ideas Flagsmith packages for everyone: stable targeting, gradual exposure, and instant reversal.

19Advantages, Disadvantages, and Trade-offs

Feature flags are powerful, but power has a price. A wise team knows both sides.

Advantages

  • Deploy and release become separate decisions, which lowers stress
  • Instant rollback by flipping a switch, with no new build
  • Safe gradual exposure and real-world testing
  • Targeting by plan, region, version, or any trait
  • Experiments and remote configuration in one tool
  • Open source, with the option to self-host and keep data in-house

Disadvantages

  • Extra code paths to test and maintain
  • Flag clutter if cleanup is neglected
  • One more system to depend on and monitor
  • Risk of human error in the dashboard
  • Small delay between a change and its effect because of caching
  • Privacy care needed for traits

The big trade-offs, plainly stated

ChoiceYou gainYou give up
Remote evaluationSimplicity, private rules, easy browser useA network call per identity, dependence on reachability
Local evaluationSpeed, resilience, low load on FlagsmithSlight staleness, a server-side secret, a bigger in-memory document
Short refresh intervalFresher flagsMore background traffic
Many fine-grained segmentsPrecise targetingHarder to reason about who sees what
Storing traits in FlagsmithMemory between visits, easier debuggingMore personal data to protect

There is no single best answer. The right balance depends on your traffic, your risk tolerance, and how fast your team needs changes to land.

20Frequently Asked Questions

Short answers to the questions that come up again and again.

Q1What is the difference between enabled and value?
Enabled is the on/off switch. Value is an optional piece of text, number, or true/false setting attached to the flag. A flag can be enabled with a value, disabled with a value, or just on or off with no value at all.
Q2If I do not send an identity, what do I get?
You get the environment-level flags, meaning the defaults for everyone. Segment targeting and percentage logic need an identity to look at, so they cannot apply.
Q3Which wins, an identity override or a segment override?
The identity override always wins, because it is the most specific rule. After that come segment overrides in priority order, and finally the environment default.
Q4What if a person matches two segments that both override the same flag?
Only the one with the higher priority is used. The overrides are not combined. You control the order in the dashboard.
Q5Will the same user always get the same percentage-rollout result?
Yes, as long as their identity stays the same and the setup is unchanged. The result comes from a stable calculation, not from a coin toss each time.
Q6Why did my change not show up immediately?
Some layer is probably holding an older copy. It may be the SDK cache, the serving layer, or, with local evaluation, the gap before the next refresh. Wait a little, or check your polling and caching settings.
Q7Can browsers use local evaluation?
No. Local evaluation needs the server-side key and downloads the full rulebook, which must never be exposed to browsers or devices. Client-side SDKs use remote evaluation.
Q8Are traits saved?
With remote evaluation, traits you send can be stored with the identity. With local evaluation they are used for the decision and not saved. Newer versions also let you mark identities or traits as transient so they are never stored.
Q9What should happen if Flagsmith is down?
Your app should keep working. Use cached answers, local evaluation’s last document, offline data, or a default flag handler, with each default chosen to be the safe option for that feature.
Q10Is it okay to use flags for permissions?
Flags are good for unlocking features by plan. They are not a replacement for real access control. Always enforce permissions on your server as well.
Q11How many flags is too many?
There is no magic number, but if nobody can explain what a flag is for, it is too many. Keep an owner and a removal plan for every temporary flag, and prune often.
Q12Can I test flags on my own machine without the network?
Yes. Use a separate Development environment, or the offline mode where available, so tests are fast and do not depend on live settings.

21Summary and Key Takeaways

Key Takeaways

  • Evaluation is a decision function: environment, identity, and traits go in; an enabled state and a value come out for every feature.
  • Precedence is strict: identity override first, then the highest-priority matching segment override, then the multivariate allocation, then the environment default.
  • Stable hashing keeps people consistent: percentage rollouts and multivariate splits give each identity the same result every time, and widening a rollout keeps earlier users inside.
  • Choose the mode that fits the place: remote evaluation with a client-side key for browsers and phones; local evaluation with a secret server-side key for busy backends.
  • Caching trades freshness for speed: know each layer’s delay, and remember that local evaluation refreshes about once a minute by default.
  • Fail safe and protect privacy: set a deliberate default for every flag, guard your keys, and send only the traits you truly need.
  • Keep flags tidy: give each one a clear name, an owner, and an end date, and delete it once its job is finished.