Environments in Flagsmith
How Flagsmith keeps development, staging, and production safely apart while sharing one feature list, and how to use environments to ship features with confidence, explained from the first idea to production-grade practice.
Imagine a large school with one rulebook but three different buildings. In the practice hall, students try new things, make mistakes, and nobody minds. In the rehearsal hall, a smaller group runs the full show to check that everything fits together. In the main auditorium, the real audience arrives, and every moment counts. The rulebook, which lists all the acts, is the same everywhere. But what is switched on, and for whom, is decided separately in each building.
That is almost exactly how environments work in Flagsmith, an open-source feature flag and remote configuration platform. A team defines a feature once, and then each environment keeps its own private answer to the question, “Is this feature on here, and what are its settings?” A developer can switch a feature on in the development environment all day long without any customer ever noticing, because production keeps its own separate answer.
This guide explains environments in Flagsmith from the very beginning. We will learn what an environment is, what lives inside one, how the secret and public keys work, how applications ask for flags, how changes travel from development to production, who should be allowed to change what, and which mistakes to avoid. We assume you know nothing yet. Every new word is explained the first time it appears, and every big idea comes with an everyday comparison.
Flagsmith is a living product, and menu names and plan limits change between versions. This guide teaches the lasting ideas. When you need an exact button name, price, or limit, check the official Flagsmith documentation for the version you use.
1Why We Need Environments at All
Before learning how Flagsmith does it, let us feel the problem that environments solve. It is the problem of trying things safely.
The danger of one shared switchboard
Suppose a team uses feature flags but keeps only one set of switches. Every flag has just one value: on or off. A developer working on a new checkout page turns the flag on to test it. But the same switch is read by the real website, so thousands of real customers suddenly see a half-finished checkout page. The developer meant to test, yet the world was affected.
To avoid this, the team might promise never to touch the switches carelessly. But promises are weak protection. People get tired, people misread a screen, and people click the wrong button. A safe system should not depend on perfect humans. It should make the dangerous mistake difficult in the first place.
What we really want
The team wants several separate places where code can run, each with its own private switches, so that testing in one place can never leak into another. These separate places are called environments. In each one, the same features exist, but the settings may differ: fully on in the practice hall, half on in the rehearsal hall, and still off in the main auditorium.
Safe experiments
Developers must be free to flip anything, any number of times, without touching real customers.
Realistic rehearsals
Testers need an environment that behaves like production, with the flags set the way production will have them next.
Controlled release
Production changes should be rare, careful, reviewed, and recorded.
Separate secrets
The keys that open the development switches must not open the production switches.
Clear history
When something goes wrong, the team must see who changed which flag in which environment.
One shared vocabulary
A flag called “new checkout” must mean the same feature in every environment, so teams are never confused.
Think of a chef who tests a new recipe. Nobody serves the first attempt to paying guests. The chef cooks it in a test kitchen, tastes it, adjusts it, lets colleagues taste it, and only then adds it to the real menu. Environments are the test kitchen, the tasting table, and the dining room. The recipe name is the same in all three, but the pot on each stove is separate.
A short story of a Friday mistake
Meera is a developer at a travel booking company. On a Friday afternoon she wants to test a new discount banner. Her company uses a single flag list with no environments. She flips the banner flag on. Within a minute, customers see a banner promising a discount that does not exist yet. The support team gets forty calls. Meera switches the flag off and spends the weekend worrying. The next Monday the team creates separate environments. From then on, Meera flips flags in development as much as she likes, and production simply never hears about it.
2Environments in Software: The Big Picture
The word environment is used all across software delivery. Understanding the general idea first makes the Flagsmith version easy.
What is an environment?
An environment is a separate, self-contained copy of a system where code can run. It has its own servers, its own database, its own settings, and its own secrets. What happens in one environment does not change another. The most common ones are listed below.
| Environment | Who uses it | Purpose | Risk if broken |
|---|---|---|---|
| Local | One developer on a laptop | Writing and trying code | None |
| Development | The whole development team | Shared experiments and early integration | Very low |
| Test or QA | Testers and automatic checks | Finding bugs before release | Low |
| Staging | Release managers, testers, product owners | Dress rehearsal that imitates production | Medium, as it hides surprises |
| Production | Real customers | The live service | High: money, trust, reputation |
The golden rule: same code, different settings
A famous guideline from the “twelve-factor app” way of building software says that the code should stay the same in every environment, while only the settings change from one environment to the next. The very same packaged build is moved from development to staging to production. The things that differ are database addresses, secret passwords, and, importantly for us, the values of feature flags.
This is why environments and feature flags fit together so naturally. A flag is a setting that can change behaviour without changing code. An environment is a container that holds one complete set of such settings. Put together, they let the same build behave differently in different places, in a controlled way.
Configuration drift: the quiet enemy
When environments are set up by hand, they slowly become different from each other in ways nobody planned. A setting is changed in staging and forgotten in production. This is called configuration drift. Drift is dangerous because a test that passed in staging may not mean anything for production, since the two are no longer alike. A good environment system makes differences visible and deliberate. We will see how Flagsmith helps with this later.
Imagine two identical kitchens where the chef practises. Over months, someone moves the salt in one kitchen, swaps a pan in another, and changes the oven temperature setting. When the chef finally cooks in the real restaurant, the habits learned in the practice kitchen no longer fit. Drift is the slow rearranging of kitchens until practice no longer predicts reality.
Why feature flags need their own environments
Infrastructure environments, meaning separate servers and databases, already exist in most companies. But the flag values need their own separation, for three reasons. First, flag values are changed far more often than servers, sometimes many times a day. Second, product managers and support staff, not only engineers, may change them. Third, a flag value can change what millions of people see in seconds. Because of this speed and reach, each environment needs its own flag values, its own access keys, its own permissions, and its own history.
A flag platform with no clear environment separation is like a building with one master key for every door. The convenience is tempting, and the risk is enormous.
3Meet Flagsmith and Its Building Blocks
To understand where an environment sits, we first need a quick tour of the whole platform and the family tree of its parts.
What is Flagsmith?
Flagsmith is a platform for feature flags and remote configuration. A feature flag is a switch that turns a feature on or off without releasing new code. Remote configuration means storing values, such as a number or a piece of text, that your application reads while running, so you can change them without redeploying. Flagsmith is open source, which means its code is public and anyone may read it. You can use the hosted service run by the Flagsmith company, or you can run Flagsmith on your own servers.
The family tree: organisation, project, environment
Flagsmith arranges everything in a tree with three main levels.
Organisation
The top level, usually a whole company. It holds the people, the teams, the billing, and all the projects. Think of it as the school itself.
Project
A group of features that belong together, usually one product or one application. The list of features, the segments, and the tags live at this level. Think of it as one rulebook for one show.
Environment
A separate place inside a project, such as development, staging, or production. Each environment holds its own switch positions and values for the project’s features. Think of it as one building where the show is performed.
flowchart TB
ORG["Organisation: the company"] --> P1["Project: Shopping App"]
ORG --> P2["Project: Admin Portal"]
P1 --> F["Shared definitions: features, segments, tags"]
P1 --> E1["Environment: Development"]
P1 --> E2["Environment: Staging"]
P1 --> E3["Environment: Production"]
E1 --> S1["Own feature states and overrides"]
E2 --> S2["Own feature states and overrides"]
E3 --> S3["Own feature states and overrides"]
E1 --> K1["Own access keys"]
E2 --> K2["Own access keys"]
E3 --> K3["Own access keys"]
The other main words you will meet
Feature
The named thing you want to control, such as “new checkout.” A feature can be a simple flag, a remote configuration value, or both. It is created once for the project.
Feature state
The answer for one feature in one environment: is it enabled, and what is its value? Every environment has its own feature state for every feature.
Identity
A user, device, or account that your application tells Flagsmith about, usually with a unique identifier such as a user number.
Trait
A fact stored about an identity, such as country, plan, or app version. Rules can use traits to decide who gets what.
Segment
A saved group of identities that match certain rules, such as “all premium users in India.” Segments are defined once for the project.
SDK
A small library you add to your application so it can talk to Flagsmith in your programming language.
Remember the pairing: definitions are shared and live in the project, while decisions are private and live in each environment. This one sentence explains most of how Flagsmith environments behave.
4What Exactly Is an Environment in Flagsmith?
An environment in Flagsmith is a named container, inside a project, that stores one complete and independent set of feature settings, together with the keys and rules that go with them.
The simplest definition
If a project says which features exist, an environment says what is true about those features right now, in one particular place. Two environments in the same project contain the same feature names but may hold different answers. For example, the feature “new checkout” might be enabled in development, enabled for ten percent of people in staging, and disabled in production.
What lives inside an environment
An environment is not just a label. It is a bundle of several things, and each of them is separate from the other environments.
flowchart LR
ENV["One environment, for example Production"]
ENV --> A["Feature states: enabled or disabled and value"]
ENV --> B["Segment overrides: special answers for groups"]
ENV --> C["Identity overrides and stored traits"]
ENV --> D["Environment keys: client and server"]
ENV --> E["Settings: name, description, approvals"]
ENV --> F["Permissions: who may view and change"]
ENV --> G["Audit history and webhooks"]
ENV --> H["Integrations: analytics and monitoring"]
Feature states
For each feature: the on or off position, the configured value, and, for multivariate features, the percentage given to each option.
Segment overrides
Special answers for chosen groups. For example, in production, premium users get the new feature even though everyone else does not.
Identity data
The identities and traits your application has told this environment about. A user known to production is not automatically known to staging.
Keys
Separate access keys, so that an application talking to staging cannot read or change production.
Settings
The name, a description, and options such as how many approvals a change needs before it takes effect.
Audit history
A diary of who changed what in this environment and when.
Webhooks and integrations
Messages and connections that fire when something changes here, such as a note to a chat channel or an event sent to a monitoring tool.
Permissions
Rules about which people and teams may see or change this particular environment.
The default environments
When a new project is created in Flagsmith, it normally starts with two environments, commonly named Development and Production. You can rename them, add more, and delete ones you do not need. Two is a sensible beginning, but most teams that deliver software every day end up with at least a third one, usually staging or test, placed between them.
A concrete picture
Let us imagine a project called “Shopping App” with a feature named “new checkout.” The table below shows how the same feature can look in each environment at the same moment.
| Environment | Is “new checkout” enabled? | Segment override | Value for button text |
|---|---|---|---|
| Development | Yes, for everyone | None needed | Pay now (experimental text) |
| Staging | Yes, mirrors the next release | Testers segment always on | Buy securely |
| Production | No, still off | Employees segment on | Buy securely |
Notice that the feature definition, its name, and its description are the same everywhere. Only the decisions differ. A developer who changes development changes nothing in production.
Picture three identical control rooms, each with the same panel of labelled switches, each wired to a different building. The labels on the panels never differ. Only the positions of the switches and the building they control are different.
5Project Level Versus Environment Level
Knowing what is shared and what is separate is the key to using Flagsmith without surprises. Let us sort the main things into two boxes.
Shared across the project
- The list of features and their names.
- Feature descriptions and tags.
- Segment definitions, meaning the rules that describe a group.
- The type of each feature, such as plain flag or multivariate.
- Project-wide settings and the project’s permissions.
Separate in each environment
- Whether each feature is enabled or disabled.
- The value of each feature.
- Segment overrides, meaning which groups get special answers.
- Identities, traits, and identity overrides.
- Access keys and environment-level permissions.
- Audit history, webhooks, and many integration settings.
Why this split is clever
Because features are defined once, every environment always has the same list of features. A developer cannot accidentally create a feature in development that production has never heard of. When a new feature is created, it appears in every environment at once, normally in a safe, off state, and each environment can then decide independently what to do with it. This keeps the environments aligned in shape while leaving them free in decisions. It is a powerful defence against configuration drift.
When creating a feature, defaults can be applied
When a person creates a feature in Flagsmith, they can choose an initial enabled state and an initial value. By default these initial choices are applied to the new feature in all environments. That is convenient, but for a risky feature it may be exactly what you do not want, since production would also receive the starting value. Flagsmith offers project-level settings to prevent defaults from being applied to every environment, and many teams prefer to keep new features off everywhere except development. Check the project settings in your version to see the exact option and its name.
When you create a new feature, look carefully at the starting state before you save. A feature created as “enabled” with default propagation could appear switched on in production the moment it exists, even though no code is using it yet. Make it a habit to create features switched off.
Comparing environments
Because the feature list is identical, comparing two environments is easy and meaningful. A useful habit is to review the difference between staging and production before a release. Flagsmith provides views that help compare environments, and teams can also fetch the settings of two environments through the management interface and compare them with a simple script. The question to ask is always the same: “Which features are in a different state here than there, and is each difference deliberate?”
Use case: the pre-release diff
A mobile banking team is about to release a new version of its app. The release manager opens the comparison of staging and production. Five features differ: three are intentional, as they are new and still off in production. Two are surprising, because someone turned them on in staging last week for a demo and forgot. The team switches those two back before the release, and the rehearsal in staging becomes trustworthy again.
6Environment Keys: The Doors and Their Locks
How does an application tell Flagsmith which environment it belongs to? It shows a key. Understanding the two kinds of keys is one of the most important safety lessons in this guide.
The environment key
Every environment has an identifying key, a long string of letters and numbers. When your application starts, you give this key to the Flagsmith SDK. Each time the SDK asks for flags, it presents the key, usually in a request header, and Flagsmith uses it to find the right environment and to return that environment’s answers. In other words, the key is both the address and the proof of belonging. An application holding the staging key sees staging. It cannot see production, because it does not hold production’s key.
Two kinds of keys
| Kind of key | Where it is used | Is it secret? | What it can do |
|---|---|---|---|
| Client-side environment key | Web pages, mobile apps, and other code the user can inspect | No, it is treated as public | Ask for the flags that apply to one user, one identity at a time |
| Server-side environment key | Your own back-end servers and trusted services only | Yes, keep it secret | Read the full environment, enabling local evaluation, and work with identities |
The client-side key is designed so that exposing it is acceptable. A browser can see it in the page source, and that is fine, because it only allows reading the flags for a single user. The server-side key is more powerful. It can download the complete rules of the environment, and it must be stored like a password, in a secrets manager or in protected environment variables, and never placed into a web page, a mobile app, or a public code repository.
The client-side key is like the public address of a shop. Anyone can know it and walk up to the counter and ask what is on offer. The server-side key is like the key to the back office. Only trusted staff may hold it, because the back office contains the full price list, the plans for next season, and the safe.
The API keys for management are different
Do not confuse environment keys with the keys used to manage Flagsmith itself. Environment keys are for applications reading flags. Management actions, such as creating a feature or changing a state through automation, use a different credential tied to a person or a service account, usually called an Admin API key or token. This second kind of key has far more power, because it can change flags, and it must be guarded even more carefully.
Rules for living with keys
- One key per environment per purpose. Never reuse the production key in a test setup.
- Keep server keys out of code. Read them from a protected setting at start-up.
- Rotate when in doubt. If a server key may have leaked, create a new one, switch your servers over, and delete the old one.
- Different keys for different services. If each back-end service has its own server key, a leak in one service is easier to contain.
- Never put secrets inside flag values. Flag values can be read by many systems. They are for behaviour, not for passwords.
A very common mistake is shipping a mobile app with the server-side key inside it because “it was easier.” Anyone can pull that key out of an app. Always use the client-side key in code that runs on a user’s device.
Use case: one codebase, three keys
A team builds a web application once. In development, its start-up settings hold the development key. In staging, the same build is given the staging key. In production, the same build receives the production key. The code is identical in all three places. Only one setting differs, and with it the whole personality of the flags. This is the twelve-factor idea in action.
7Designing Your Set of Environments
How many environments should you create, and what should you call them? There is no single right answer, but there are sensible shapes that fit most teams.
Start from your delivery pipeline
The best guide to your environments is the path your code already walks on its way to customers. Each stage in the pipeline that needs different flag values deserves an environment. If your pipeline has a development stage, a staging stage, and production, then Flagsmith should have three environments with matching names. When the names match, nobody has to translate in their heads.
Common shapes
Two environments
Development and Production. The simplest shape, good for small teams and new projects. The weakness is that nothing sits between experiments and real customers.
Three environments
Development, Staging, and Production. The most popular shape. Staging is the dress rehearsal where flags are set exactly as production will have them next.
Four or more
Adds a test environment for automatic checks, a pre-production environment, or a performance testing environment. Useful in larger companies with strict release steps.
Per-developer or per-branch
Each developer or each pull request gets a temporary environment, created and deleted automatically. Great for isolation, but it needs automation to avoid clutter.
Per-region or per-customer
Separate production environments for different regions, or for large customers who need special handling. Powerful, but multiplies the work of keeping them aligned.
Demo and sandbox
An environment used for sales demonstrations or for customers to try an API. It keeps polished demo settings away from real systems.
Naming rules that save headaches
- Use plain, predictable names. “Development,” “Staging,” and “Production” are understood by everyone.
- Match your infrastructure names. If your servers say “prod,” do not call the flag environment “live.”
- Keep production unmistakable. Many teams give production a distinctive colour in the Flagsmith interface so nobody edits it by accident. Flagsmith lets you choose a colour label for each environment.
- Write a description. A single line explaining who uses the environment and how it is deployed prevents long arguments later.
The cost of too many environments
It is tempting to create an environment for every possible purpose. But each environment needs care: its flags must be kept sensible, its keys managed, and its permissions reviewed. With ten environments and two hundred features, there are two thousand feature states to keep tidy. Environments that nobody uses become stale and misleading. A good rule is to create an environment only when you can name the person responsible for it and the situation in which it is used.
Think of the number of rooms in a house. Too few rooms and everyone crowds together, creating mess. Too many rooms and the family spends all weekend cleaning rooms that nobody enters. A comfortable house has rooms that all have a clear purpose.
Creating an environment: what happens
Choose a name and description
Open the project in the Flagsmith dashboard and add a new environment, giving it a clear name and a one-line description.
Decide how to start it
You may create a blank environment, where every feature starts in the default state, or clone an existing environment so the new one begins with the same states and overrides. Cloning is handy for creating a staging environment that mirrors production.
Receive the keys
Flagsmith generates fresh keys for the new environment. They are different from every other environment’s keys.
Set permissions
Decide who may view and change the environment. New environments are a good moment to apply the principle of least privilege.
Configure the applications
Place the new key into the start-up settings of the application, through the secret storage of the deployment system.
Verify
Start the application and confirm that it reads the expected flag values. A simple check is to flip a harmless flag in the new environment and see the application react.
When you clone an environment, review the copied feature states before using it. A clone of production carries production’s switches, which may not be what a safe testing environment should begin with. Many teams clone and then deliberately switch risky features off.
8Feature States: Different Answers in Each Place
A feature state is the heart of an environment. It is the actual answer to “what should happen here?” Let us look at what it can hold.
The parts of a feature state
For one feature in one environment, the feature state contains the following.
- Enabled or disabled. The main switch. A disabled feature returns “off” no matter what else is configured, unless the application chooses to look at the value.
- A value. Optional remote configuration, such as a number, a piece of text, or a small block of structured data. For example, “maximum upload size is fifty files.”
- Multivariate options. If the feature has several variants, each variant has a percentage of users in this environment. Development may give each variant an equal share, while production may give ninety percent to the old variant and ten percent to the new one.
An example across the pipeline
Consider a feature called “recommendation engine” that has a configurable value for how many items to show. A team might hold the following states.
| Environment | Enabled | Items to show | Reasoning |
|---|---|---|---|
| Development | Yes | 3 | Small numbers make screens easy to inspect |
| Staging | Yes | 10 | Realistic size to test layout and load |
| Production | No, then gradually yes | 10 | Waits until staging has proven the feature |
Notice how a value can differ between environments for good reasons. A development environment may use a small test number, a staging environment a realistic one. Such differences are healthy, as long as they are known and intentional.
Same feature, different pace
Because states are separate, each environment can move at its own pace. Development changes freely, many times in a day. Staging changes when a release candidate is ready. Production changes only when the business is satisfied and the checks are green. In effect, the environments form a ladder: a change climbs one rung at a time, and each rung gives more evidence that it is safe.
flowchart LR
D["Development: experiment freely"] -->|"Idea works"| S["Staging: rehearse as production will be"]
S -->|"Tests pass and owners agree"| P["Production: gradual release"]
P -->|"Problem"| R["Turn off in production only"]
R --> D
The value of safe defaults
When code asks for a flag and Flagsmith cannot be reached, the code needs a fallback. Most SDKs let you supply a default value, which is used when the real answer is unavailable. Defaults are not stored in an environment. They live in your code. A good default is the old, proven behaviour, because it protects users when anything fails. Some SDKs can also be started with a copy of environment data saved earlier, so that even a first start during an outage has sensible answers.
A feature that is “enabled” in an environment still answers “off” for a person if a segment override or an identity override says so. Always remember that the final answer a user sees comes from several layers, and the plain enabled switch is only the bottom layer.
9Segments, Overrides, and Identities per Environment
Beyond the simple on and off switch, Flagsmith lets you give special answers to groups and to single users. The important point here is where these special rules live.
Segments: defined once, used separately
A segment is a named group of identities that match a set of rules. For example, “Beta testers” might mean identities whose trait group equals beta, or “Premium India” might mean identities whose plan is premium and whose country is India. Segment definitions belong to the project, so every environment understands the same segment names with the same meaning.
Segment overrides: the decision is per environment
A segment override says, “for this feature, in this environment, give people in this segment a special answer.” The override is stored inside the environment. That is a very useful feature. In staging, you might override the “new checkout” flag for the “QA testers” segment. In production, you might override it for the “Employees” segment first. The groups are the same everywhere, but the answers are chosen separately.
flowchart TB
Q["Request: flags for identity 4821 in Production"] --> I{"Identity override exists?"}
I -->|"Yes"| ANS1["Use the identity override"]
I -->|"No"| SG{"Matches a segment override?"}
SG -->|"Yes, highest priority wins"| ANS2["Use the segment override"]
SG -->|"No"| ENVS["Use the environment default feature state"]
ANS1 --> OUT["Return flag value to the application"]
ANS2 --> OUT
ENVS --> OUT
The order of decision
Flagsmith decides in layers, from the most specific to the most general. First it checks whether the single identity has a personal override. If not, it looks at the segment overrides the identity qualifies for, and when several segments match, a priority order decides which one wins. If none match, the plain environment value is used. This layered design means you can say “everyone gets this, except premium users, except this one person” in an orderly way.
Think of airport rules. There is a general rule for all passengers. A special rule applies to frequent flyers, and an even more specific rule applies to one passenger with a personal arrangement. The agent always checks from the most specific to the most general, and the first rule that fits decides the treatment.
Identities live inside an environment
When your application tells Flagsmith about a user, giving an identifier and some traits, that identity is recorded in the environment whose key was used. A person who exists in production does not exist in staging unless your staging application also reported them. This separation is healthy, because test users and real users never get mixed. It also means that traits used by segments must be sent by every environment’s application, or the segments will not match there.
Identity overrides: the personal touch
An identity override gives one specific identity a special answer for a feature in one environment. This is perfect for letting a single customer try a beta, or for helping a support engineer reproduce a problem. Identity overrides are also stored per environment, which means giving a person special access in staging says nothing about production.
Common ways teams use overrides in each environment
| Environment | Typical segment overrides | Purpose |
|---|---|---|
| Development | Usually none, since everything is on for developers | Keep it simple and fast |
| Staging | QA testers always on, selected demo accounts | Prove behaviour for specific groups before release |
| Production | Employees first, then beta customers, then regions | Gradual, targeted release |
Test your segment rules in staging with real-looking traits before you trust them in production. A misspelled trait name is the most common reason a segment silently matches nobody.
10How an Application Reads an Environment
What actually happens when your application asks Flagsmith for flags? There are two main ways, and the choice affects speed, cost, and reliability.
Mode one: remote evaluation
In remote evaluation, the SDK sends a request over the internet each time it needs flags. It presents the environment key and, if relevant, the identity and its traits. Flagsmith’s servers run the rules and send back the answers for that user. This is simple, works with the client-side key, and is the normal mode for web pages and mobile apps. The cost is a network trip for each fetch, so applications usually fetch once at the start of a session and keep the answers in memory.
Mode two: local evaluation
In local evaluation, a server-side SDK uses the server-side key to download the whole environment’s rules, called the environment document, and keeps them in memory. From then on it computes the answers itself, with no network trip for each check. It refreshes the document in the background every so often. This makes flag checks extremely fast and keeps working if Flagsmith becomes briefly unreachable, because the last known rules are still in memory. The trade-off is that changes arrive after the next refresh, rather than instantly.
| Aspect | Remote evaluation | Local evaluation |
|---|---|---|
| Key used | Client-side or server-side key | Server-side key |
| Where rules run | On Flagsmith’s servers | Inside your own server |
| Speed per check | A network request each fetch | Almost instant, from memory |
| Freshness of changes | Immediate on the next request | After the next background refresh |
| Survives an outage | Only with cached answers or defaults | Yes, with last known rules |
| Best for | Browsers and mobile apps | High-traffic back-end services |
sequenceDiagram
participant U as User
participant A as Application
participant SDK as Flagsmith SDK
participant FS as Flagsmith API
U->>A: Opens a page
A->>SDK: Get flags for identity 4821
SDK->>FS: Request with environment key and identity
FS->>FS: Find the environment from the key
FS->>FS: Apply identity overrides then segments then defaults
FS-->>SDK: Flags and values for this identity
SDK-->>A: Flag results kept in memory
A-->>U: Shows the right version of the page
The role of the edge
Flagsmith offers an architecture designed to serve flag requests from servers spread across the world, so that answers are delivered quickly and reliably wherever your users are. In the hosted service, requests from SDKs are normally answered by this distributed layer rather than a single central database. For teams that run Flagsmith themselves, the deployment guide describes the options available, including the use of a local cache. The practical lesson is the same: whatever the internal machinery, applications should fetch flags sparingly, cache them, and always have a safe default.
Keeping the answers fresh in a browser or app
Browsers and phones cannot refresh as casually as servers. A typical approach is to fetch flags at the start of a session, store them, and refresh at moments such as returning to the app, or on a modest timer. Some SDKs also support receiving updates pushed from the server, so that a kill switch can act within seconds. Teams choose the balance between freshness and the load of constant polling according to how critical each flag is.
Offline and fallback behaviour
Good SDKs follow a ladder of fallbacks. First, use the answers already in memory. If the application restarts during an outage, use a saved copy of the last known environment data, when the SDK supports it. If even that is missing, use the default value written in the code. Designing every flag check with a safe default is one of the most valuable habits in the whole Flagsmith practice.
Ask a simple question about every application: “If Flagsmith disappeared this minute, what would our users see?” The right answer is “the safe, old behaviour, with no errors.”
11Moving Changes From One Environment to the Next
Since each environment keeps its own state, a change that works in development does not automatically appear in production. This is deliberate, and it means teams need a clear routine for carrying changes upward.
No automatic copying, by design
When you enable a feature in development, nothing happens in staging or production. That separation is the whole point. The cost is that someone must repeat the change in the next environment at the right moment. Flagsmith does not push states upward by itself, because pushing automatically would defeat the safety that separation creates. Instead, it gives you tools to make the manual step careful and visible.
The usual promotion routine
Create the feature
A developer creates the feature, switched off. It now exists in every environment.
Switch on in development
The developer builds and tests the new behaviour with the flag on in development only.
Deploy the code everywhere
The code travels through the pipeline to staging and production with the flag still off in those two environments.
Rehearse in staging
The team sets the staging state the way production will have it. Testers run their checks and compare the numbers.
Release in production
The state is changed in production, often via a reviewed request, first for employees, then a small share of users, then everyone.
Clean up
After a stable period, the code path and the flag are removed, and the feature is deleted from the project, which removes it from all environments at once.
flowchart TB
A["Create feature: OFF in all environments"] --> B["Enable in Development and build"]
B --> C["Deploy code to all environments with flag OFF"]
C --> D["Set Staging like next Production state"]
D --> E{"Staging checks pass?"}
E -->|"No"| B
E -->|"Yes"| F["Request change for Production"]
F --> G{"Approved?"}
G -->|"No"| B
G -->|"Yes"| H["Apply in Production gradually"]
H --> I{"Healthy?"}
I -->|"No"| J["Disable in Production"]
I -->|"Yes"| K["Stable period then remove flag and old code"]
J --> B
Tools Flagsmith provides for careful promotion
Change requests
Instead of changing a state straight away, a person submits a request. Another person reviews and approves it, and only then does the change take effect. You can require a number of approvals per environment. Availability depends on your plan.
Scheduled changes
A change can be set to happen at a chosen future time, which suits coordinated launches that must start at a precise moment, such as the start of a sale.
Feature versioning
Environments can keep versions of a feature’s state, so that a previous version can be inspected or restored. This supports quick recovery after a mistake.
Audit log
Every change is recorded with who, what, and when, so reviews and investigations have facts to work with.
Admin API
A programming interface for creating and changing features and states by script. It lets pipelines apply the same change to an environment automatically after tests pass.
Infrastructure as code
Flagsmith can be managed through tools that describe settings in files, such as a Terraform provider, so that environments are created and configured from reviewed text, not by hand.
Why reviewed text beats hand clicking
When the shape of your environments is stored as text in a code repository, every change can be reviewed like code, recorded in history, and repeated exactly. A new environment can be created identically in minutes. Drift becomes easy to detect, because the written description and the real system can be compared automatically. Teams that run many environments, or many projects, gain the most from this approach.
Do not let a pipeline change production flags with a powerful administrative key that every developer can read. Protect that key as carefully as a production database password, and give the pipeline only the permissions it needs.
12Permissions and Governance for Each Environment
Different environments deserve different levels of care. Flagsmith lets you give people exactly the access they need in each one.
The principle of least privilege
Least privilege means each person or system receives only the permissions necessary for their job, and nothing more. A developer may need to change anything in development, but only view production. A support engineer may need to manage identity overrides for customers in production, but should never change the value of a payment feature. A release manager may need to approve changes. Flagsmith lets administrators grant permissions at the organisation, project, and environment levels, and to individuals or to groups.
Typical permission levels at environment level
| Permission idea | What it allows | Who often has it in production |
|---|---|---|
| View the environment | See features and states | Developers, testers, support, product |
| Update feature state | Turn features on or off, change values | A small trusted group, often through reviewed requests |
| Manage segment overrides | Choose which groups get special answers | Release managers and product owners |
| Manage identities | Create identity overrides and edit traits | Support and customer success |
| Create change requests | Propose a change for review | Developers |
| Approve change requests | Authorise a proposed change | Leads and release managers |
| Administer the environment | Manage keys, settings, and permissions | Platform or operations owners |
Teams and groups instead of individuals
Granting permissions person by person is slow and easy to forget. A better habit is to create groups such as “Developers,” “Release managers,” and “Support,” grant permissions to each group, and then place people into groups. When someone changes jobs, you update the group membership, and all their access changes at once. Many organisations connect Flagsmith to their company sign-in system, so that people use one account and are removed everywhere when they leave.
Approval flows for production
For the environments where mistakes cost the most, a second pair of eyes is a bargain. With change requests, a developer proposes “enable new checkout at ten percent,” and a colleague reviews the proposal. The reviewer checks that staging was rehearsed, that the right audience is selected, and that the timing is sensible. Only after approval does the change go live. The history is stored, so months later anyone can see who proposed it, who approved it, and why.
Notifications and visibility
Each environment can send webhooks, which are automatic messages to another system, whenever something changes. A common use is posting a line into a shared chat channel such as “Production: new checkout set to ten percent by Anil.” This simple habit means that when something odd happens, the first question, “what changed?”, is answered in seconds. Flagsmith also connects with analytics and monitoring tools through integrations that are configured per environment, so production data can go to production dashboards while development data goes elsewhere or nowhere.
Use case: protecting the payment flag
A fintech company marks its production environment as requiring one approval for any change. Developers can propose changes but not approve their own. When a developer wants to raise the rollout of a new payment screen from five to twenty-five percent, the release manager checks the live error graphs, approves, and the change takes effect. Two weeks later an auditor asks who authorised the change, and the history gives a complete answer in a minute.
Be generous in development and strict in production. If every environment has the same heavy rules, people will find shortcuts. If only the dangerous one is strict, people accept the friction because it is clearly justified.
13Environments Inside a Continuous Delivery Pipeline
Flagsmith environments become most useful when they line up with the stages of your delivery pipeline. Let us see how the two fit together.
A quick reminder about the pipeline
A delivery pipeline is an automatic assembly line that takes a code change from a developer’s laptop to production. It builds the code, tests it, stores the finished package, places it in a staging area, and finally releases it to customers. The same package moves forward through each stage. Nothing is rebuilt along the way. Only the settings change from stage to stage, and flag values are among those settings.
flowchart LR
C["Commit"] --> B["Build and unit tests"]
B --> DEV["Deploy to Development"]
DEV --> T["Automatic integration tests"]
T --> STG["Deploy to Staging"]
STG --> UAT["Acceptance and performance checks"]
UAT --> G{"Release approved?"}
G -->|"Yes"| PRD["Deploy to Production"]
PRD --> M["Monitor and roll out flags gradually"]
DEV -.->|"uses Development key"| FD["Flagsmith Development environment"]
STG -.->|"uses Staging key"| FS["Flagsmith Staging environment"]
PRD -.->|"uses Production key"| FP["Flagsmith Production environment"]
How the pieces line up
| Pipeline stage | Flagsmith environment | What flags do here |
|---|---|---|
| Local and development | Development | Everything new is on, so developers can build and try features |
| Automatic test stage | Test or Development | Flags set to known, fixed values so tests are repeatable |
| Staging | Staging | Flags set exactly as production will have them after the next release |
| Production | Production | Flags rolled out gradually with monitoring and approvals |
The key is the only difference
The beauty of this design is its simplicity. The deployment step for each stage places the right environment key into the application’s settings. That is the entire difference between the stages as far as flags are concerned. The package, the code, and the SDK are identical. If staging behaves well, you have strong evidence about how production will behave, provided that staging’s flags truly resemble what production will have.
Separating deploy and release again
In an earlier lesson on continuous delivery, we learned that deploy and release are different events. Environments make this idea concrete. A deploy puts code onto production servers. A release changes the production flag state. The first is done by the pipeline, the second by a human or a rule, in the Flagsmith production environment. Because they are separate, deployments can happen many times a day, and releases happen when the business is ready.
A theatre can build a new set behind a closed curtain while a play continues in front. Building the set is the deploy. Opening the curtain is the release. Each environment is a separate theatre with its own curtain, so the crew can open the curtain in the practice theatre a hundred times, and the real audience never sees it.
Keeping environments aligned with releases
As a release approaches, a good habit is to make staging’s flags match the state that production will have on release day. Then the final tests in staging answer the real question: “Will production behave well after we change these flags?” If staging has flags that production will not have, the rehearsal proves nothing. Teams often add a step before each release to compare staging and production and explain every difference.
Use case: weekly release train
A retail company releases to production every week. On Monday, the pipeline deploys the release candidate to staging. The staging flags are set to match the plan for the week: three new features on, one feature held back. Testers run their checks all Tuesday and Wednesday. On Thursday morning, the release manager creates change requests for the production flags. After two approvals, the changes are applied in steps through the afternoon while the team watches dashboards. Because every stage used its own environment, the whole week passed without a single surprise for customers.
14Testing With Flagsmith Environments
Environments help testing in several ways, but they also bring new questions. How do you keep tests repeatable when flags can change?
Repeatable tests need stable flags
An automatic test must give the same answer every time. If a test depends on a flag whose value people change during the day, the test becomes unpredictable. The cure is a dedicated environment for automatic tests, where flag values are fixed and changed only by the test team. Many teams create a “Test” environment for this reason. Another approach is for the test itself to set the flag values it needs, using the management interface, before it runs and to put them back afterwards.
Test both sides of every flag
Every flag has an off path and an on path. Automatic tests should cover both. A very common failure is testing only the new path, while the old path quietly breaks, so that turning the flag off in an emergency leads to a worse failure. Use the test environment, or local overrides, to run the same suite with each important flag on and off.
Temporary environments for isolation
Larger teams sometimes create a temporary environment for each pull request or each feature branch. The pipeline creates the environment through the Admin API, runs the tests against it, and deletes it afterward. This isolation means two developers can test conflicting flag settings at the same moment without interfering. The price is the automation effort and the need to clean up reliably, since forgotten temporary environments pile up.
Create
The pipeline creates an environment named after the branch, perhaps by cloning the test environment.
Configure
It sets the flags needed by the new feature and starts a copy of the application using the new environment’s key.
Test
Automatic tests and, if wanted, manual reviewers use the temporary copy.
Delete
When the branch is merged or abandoned, the pipeline deletes the environment and its keys.
Testing safely in production
No staging environment is exactly like production. Real traffic, real data, and real integrations behave in ways rehearsals cannot copy. Flagsmith makes careful testing in production possible. A segment override can switch a new feature on for employees only, or for a short list of identities, while everyone else sees the old behaviour. The team can use the feature on real systems, find the problems staging missed, and fix them before customers ever see them.
Never point automatic tests at the production environment’s flags and let them change states. A faulty test could switch a live feature on or off for real customers. Tests belong to the test environment, or to temporary ones.
The combinations problem
If a program has ten flags, there are over a thousand ways they can be combined. No team can test every combination. The skill lies in testing the ones that matter: the planned production state, the planned next state, the old state used as a fallback, and any pairs of flags that touch the same screen or data. Environments help because each one can hold a different important combination at the same time.
| Environment | Combination it holds | Question it answers |
|---|---|---|
| Test | Known, fixed values | Do the automatic checks pass repeatably? |
| Staging | Planned next production state | Will the next release behave well? |
| Production | Current live state | Is the real service healthy? |
| Temporary | One experimental combination | Does this particular idea work? |
15Advantages, Disadvantages, and Trade-offs
Environments are a powerful idea, and like any powerful idea they bring both gains and costs. A sensible engineer weighs both.
Advantages
- Experiments in development never touch real customers.
- Staging gives a realistic rehearsal before each release.
- Production can be locked down with approvals and strict permissions.
- Each environment has its own keys, so a leak in one does not open another.
- The feature list is shared, so environments stay aligned in shape.
- Segment and identity overrides let each environment target its own audiences.
- Audit history is kept per environment, making investigations faster.
- The same build works everywhere, only the key changes.
Disadvantages
- Each environment must be kept tidy, and neglected ones become misleading.
- Changes must be repeated in each environment, which costs time.
- Forgotten differences between environments cause configuration drift.
- More keys and permissions mean more things to manage and secure.
- A staging environment never perfectly matches production.
- Too many environments multiply the work of every new feature.
- Per-environment segment data may be missing, causing silent mismatches.
- Plan limits on features such as approvals may restrict some designs.
Key trade-offs to decide on purpose
| Decision | Option A | Option B | Guidance |
|---|---|---|---|
| Environments per project | Few, such as three | Many, such as ten | Start with three and add one only when a named owner and purpose exist |
| One project or many | One project per product | One project for everything | One project per application keeps feature lists focused |
| Evaluation mode | Remote, simple | Local, fast and resilient | Local for busy servers, remote for browsers and apps |
| Production change style | Direct and fast | Reviewed through requests | Reviewed for critical features, direct for low-risk ones |
| Creating environments | By hand in the dashboard | By code and automation | Automate once you have more than a few or need repeatability |
| Staging flag policy | Free for anyone to change | Kept as a mirror of the next release | Treat staging as a rehearsal, not a playground |
One project or several?
A frequent question is whether to put several applications into one Flagsmith project or to give each its own. Because features and segments are shared across the environments of a project, the project should hold things that belong together. A mobile app and its back end that evolve together may share a project, so a single feature can be read by both. Two unrelated products should have separate projects, otherwise their feature lists become a confusing mix and permissions become hard to express.
16Security, Privacy, and Compliance
A flag dashboard is a remote control for your product. Environments are the first and strongest line of defence for that remote control.
Isolation is the main security feature
The biggest security gain from environments is isolation. An application with the development key cannot read or change production. A mistake, a leak, or a malicious act in a lower environment stays in that lower environment. This is why you must never reuse a production key outside production, even “just for a quick test.”
Protect the server-side key and the admin key
As we learned, the client-side key is public by design, while the server-side key and any administrative token must be secret. Store them in a proper secrets manager, grant access only to the services that need them, and rotate them on a schedule and after any suspected leak. Never commit them to a code repository, even a private one, since repositories are copied and shared more widely than people expect.
Anything that reaches a browser or a mobile app can be inspected. Do not place secrets, unreleased product names, or private pricing in flag values that client-side code will read. And never rely on a client-side flag to guard something important. Enforce access to paid content or private data on the server.
Privacy of user data
Identities and traits can contain personal information. Good practice is to send only what the rules truly need. Use opaque identifiers rather than names or email addresses, and send traits such as “plan” or “country” instead of anything sensitive. If your Flagsmith runs on your own servers, personal data stays under your control, which can help with laws such as the European GDPR or India’s data protection law. If you use the hosted service, review the provider’s data handling terms and decide what to share. Local evaluation also helps, since identity details can stay inside your own servers while only the rules are downloaded.
Separate test data from real data
Because identities live inside the environment whose key reported them, test users and real users never mix. Keep it that way. Never load real customer data into development or staging identities, since lower environments are usually protected less strictly. Use made-up test identities and traits instead.
Audit, access reviews, and compliance
- Audit log. Keep the history of changes. Many compliance rules require proof of who approved production changes.
- Regular access reviews. Every few months, check who holds permissions in production and remove anyone who no longer needs them.
- Single sign-on. Connect Flagsmith to the company identity system so people leave access when they leave the company.
- Separation of duties. The person who proposes a production change should not be the only one who approves it.
- Break-glass access. Define a documented emergency path for turning a feature off quickly, with extra review afterward.
Self-hosting and data location
Teams with strict rules about where data may live sometimes choose to run Flagsmith on their own infrastructure, in a region of their choice, behind their own network controls. In that case, the same environment design applies, but the responsibility for updates, backups, and availability moves to the team. It is a serious decision, and the rewards of control must be weighed against the work of operating the service reliably.
17Monitoring, Logging, and Metrics
When flags change what users see, you need to know whether the change helped or harmed. Observability is how you find out.
Know which environment you are looking at
The first rule of monitoring in a multi-environment world is that every graph, log line, and alert must be labelled with the environment it comes from. A spike of errors in development is normal. The same spike in production is an incident. If the labels are missing, people waste time and make wrong decisions. Tag your metrics with the environment name, and keep separate dashboards, or clear filters, for each.
Tag signals with flag states
The most useful habit is to record which flag variation a request ran with. Then any graph can be split into two lines: users with the feature and users without it. The question “is the new checkout slower?” becomes a comparison of two lines. Flagsmith can send flag evaluation data to analytics and monitoring tools through integrations, and many teams also add the flag state to their own logs.
Metrics
Numbers over time, such as error rate, response time, and orders per minute. Perfect for dashboards and alarms during a rollout.
Logs
Detailed records of events, including which flag states were active. Useful for investigating one user’s report.
Traces
The path of a single request through many services, showing where time is spent when a flag changes behaviour in one of them.
Change events
Notes about when flags changed, drawn onto graphs so that a jump in a number can be linked to the change that caused it.
Guardrail metrics during a production rollout
Before raising a production flag, a team writes down the numbers that must not get worse: error rate, slow-request time, payment success, app crashes, and support contacts. These are called guardrail metrics. If any one crosses its limit, the rollout pauses or reverses. Because the change is a flag in a single environment, reversing it is a matter of one click in production, with no redeployment.
flowchart TB
A["Change flag state in Production"] --> B["Webhook posts note to team channel"]
A --> C["Audit log records who, what, when"]
A --> D["Applications receive new state"]
D --> E["Metrics tagged with environment and flag state"]
E --> F{"Guardrails healthy?"}
F -->|"Yes"| G["Continue to next step"]
F -->|"No"| H["Alarm and flag disabled"]
H --> I["Investigate with logs and traces"]
Watch the health of the flag setup itself
Besides watching features, watch the plumbing. How often do SDKs fail to reach Flagsmith? How old is the rule data held in each server? How many requests fall back to default values? A rising number of fallbacks is an early warning that something is wrong between your applications and the flag service, long before users complain.
Cost and volume
A busy service may check flags for every request. Sending an event for each check would produce enormous volumes. Teams control this with sampling, by sending summaries instead of single events, and by sending detailed data only for flags used in experiments. Keep in mind the usage limits of your Flagsmith plan, since the number of requests per month may be part of the pricing model.
18Performance, Scale, and Reliability
A flag check can happen on almost every request, so speed and dependability matter. Environments add their own questions about scale and failure.
Keep flag checks cheap
If every flag check required a trip across the internet, a page with twenty flags would feel slow. The standard approach is to fetch once, keep the answers in memory, and refresh in the background. Back-end servers use local evaluation so that each check takes only a tiny slice of time. Browsers and apps fetch at the start of a session and reuse the results.
Designing for failure
Everything fails sometimes, so the design assumes it. These protections are the main ones.
Cached answers
Applications keep the last known flags in memory, so a short outage of the flag service goes unnoticed.
Safe defaults in code
Every flag check supplies a default, normally the old and proven behaviour.
Timeouts
Applications should not wait forever for the flag service at start-up. A short time limit with a fallback keeps start-up fast.
Saved environment data
Where supported, a server can save the environment data to disk, or start from a bundled copy, so a restart during an outage still has real answers.
Separate production from the rest
Heavy testing against development must never share limits or connections with production traffic.
Eventual consistency between servers
When a flag is changed, servers do not all learn about it at the same instant. With local evaluation, each server updates at its next refresh. For a few seconds or minutes, some servers may have the old state and some the new. For most features this is harmless. For multi-step journeys such as a checkout, make the decision once at the start, store it with the session, and reuse it, so that a user never sees the design change halfway through.
Scaling to many environments and many flags
The size of an environment’s data grows with the number of features, segments, and overrides. A very large environment document means a bigger download for local evaluation and more memory on every server. Tidy habits keep it light: delete finished flags, remove unused segments, and avoid creating thousands of identity overrides when a single segment rule would do.
Treat deletion of old features as a performance practice as well as a tidiness practice. Every dead flag adds to what every server must download, store, and evaluate.
Mobile apps and slow updates
Once an app version is installed, its code cannot change until the person updates. Flags therefore act as a remote control for features already inside the installed app. Because the environment key inside a released app points to production, you can switch a faulty feature off on millions of phones without waiting for an app store review. Take care that flags guarding code absent from older app versions include a condition on the app version, so that old apps do not wait for a feature that was never built into them.
19Design Patterns and Anti-Patterns
A pattern is a proven solution to a repeating problem. An anti-pattern is a tempting solution that causes trouble. Learn both.
Patterns worth adopting
Mirror staging to production
Before each release, set staging flags to the state production will have after release, so that the rehearsal predicts the reality.
Create everything off
New features begin switched off in every environment, and are enabled deliberately, starting with development.
Environment as code
Describe environments and their settings in reviewed files, and create them through automation, so that they are repeatable and drift is detectable.
One key per service per environment
Each back-end service receives its own server key, which limits the damage of a leak and shows which service is calling.
Flag wrapper
Wrap the Flagsmith SDK in a thin layer of your own with clear names, safe defaults, and easy test overrides, so changing providers or SDK versions touches one place.
Release through segments
In production, release first to an employees segment, then to a beta segment, then to a percentage, then to everyone.
Anti-patterns to avoid
The shared key
Using one environment key everywhere, or copying the production key into development “to make it work.” Testing then changes live behaviour, and the separation that environments promise disappears.
Better approach
Give every environment its own keys. Place each key into the matching deployment’s secret storage, and never copy production secrets downward.
The playground staging
A staging environment where anyone changes flags at any time. Its state no longer resembles production, so passing tests in staging means nothing.
Better approach
Treat staging as a rehearsal stage. Change its flags only to mirror the planned production state, and keep experiments in development.
Environment sprawl
Creating a new environment for every little need and never deleting any. Soon nobody knows which are used, flags rot, and keys remain active with no owner.
Better approach
Give every environment an owner and a purpose. Review the list regularly, and delete environments and their keys when they are no longer needed.
Enabled-by-default creation
Creating a new feature as enabled with defaults copied to all environments. Production may show an unfinished feature the moment it exists, or an old flag name may suddenly mean something new.
Better approach
Create features switched off, never reuse the name of an old feature for a different purpose, and enable them in development first. The famous 2012 Knight Capital incident, where a reused flag name and an incomplete rollout across servers revived old code and cost roughly four hundred and forty million dollars in under an hour, is a sharp reminder of why.
Secrets inside flag values
Storing passwords, tokens, or private addresses in remote configuration values because it is convenient. These values travel to many systems and may be visible to browsers and logs.
Better approach
Keep secrets in a secrets manager. Use flag values only for behaviour and harmless settings.
Silent drift
Making changes in one environment and forgetting about them. Weeks later, staging and production differ in ways nobody can explain, and release rehearsals mislead.
Better approach
Compare environments before every release, record intentional differences, and prefer automated changes that are written down and repeated across environments.
20Best Practices and Common Mistakes
These habits come from many teams learning the hard way. Following them saves you from most of the pain.
Best practices
- Match environments to pipeline stages. Use the same names in the pipeline and in Flagsmith so nobody has to translate.
- Start with three environments. Development, Staging, and Production cover most needs. Add more only with a clear owner and purpose.
- Make production unmistakable. Give it a distinctive colour and a clear description so nobody edits it by accident.
- Create features switched off. Enable them deliberately, starting in development.
- Use the client-side key in client code and the server-side key only on servers. Keep server keys in a secrets manager.
- Give each service its own key. A leak is then easier to find and contain.
- Apply least privilege. Be generous in development and strict in production, using groups instead of individuals.
- Use change requests for critical features in production. A second pair of eyes is cheap protection.
- Mirror staging to the next production state before each release. Make the rehearsal predict the performance.
- Compare environments regularly. Explain every difference or fix it.
- Always supply safe defaults in code. The default should be the old, proven behaviour.
- Label every metric and log with the environment name. Avoid confusing a development spike with a production incident.
- Announce production changes in a shared channel. Use a webhook so that everyone sees what changed.
- Delete finished flags and unused environments. Cleaning is part of the job, not an optional extra.
- Describe your setup as code when it grows. Repeatable beats hand-clicked.
Common mistakes
Server key in a mobile app
Anyone can extract it and read the full environment. Use the client-side key on user devices.
Testing against production flags
A test that changes production states can affect real customers. Tests belong in test environments.
Forgetting traits in lower environments
Segments rely on traits. If staging does not send them, segment overrides silently match nobody and the rehearsal misleads.
Assuming one change applies everywhere
Enabling in development does not enable in production. Plan the promotion step explicitly.
Ignoring overrides
A feature enabled in an environment can still show “off” for a user because of a segment or identity override. Check all layers.
Cloning production without review
A clone copies live switches into a place meant for testing. Review and reset risky features.
Rolling out too fast
Jumping from zero to everyone in one step removes the safety that gradual release provides.
No owner for environments
Unowned environments rot, and their keys stay active long after anyone needs them.
Adopting environments in a team that already uses flags
Many teams meet environments after they already have a pile of flags in a single place. Moving to a clean structure is possible without stopping work, if it is done in small, careful steps.
Take stock
List every environment you have today and every place where an environment key is used, including build scripts, mobile apps, and old servers. Note who owns each one.
Separate the keys first
Create the missing environments and give each deployment its own key. This single step removes the greatest risk, which is lower environments sharing production’s switches.
Align the states
Compare the environments, decide which differences are deliberate, and reset the rest. Staging should now resemble the next production state.
Add permissions and review
Create groups, restrict production, and introduce change requests for the few features that would hurt most if mishandled.
Add measurement and announcements
Label dashboards with environment names and send production changes to a shared channel so that people learn to trust the new routine.
Automate and review regularly
Describe environments as code when the number grows, and hold a short monthly review of environments, keys, and permissions.
It also helps to talk openly about culture. Environments work best in teams where turning something off in production is treated as a normal, healthy action and not as a failure to be hidden. If people fear blame, they will hesitate to reverse a bad change, and the main strength of flags, their speed, is wasted. Teams that celebrate a quick, calm reversal and study it without blame become safer over time. Write down the simple rules, such as which environment is used for what and who may change production, and put them where every new joiner will see them on the first day.
A short checklist before changing a production flag
Am I in the right environment?
Check the name and the colour at the top of the screen. Many mistakes begin with editing the wrong place.
Was this rehearsed in staging?
Confirm that staging held the same state and that the checks passed.
Do I know the safe state?
Be able to say exactly what happens when the flag is off, and be sure it has been tested.
Are the dashboards open?
Have the guardrail graphs ready and the alerts working before you click.
Does the team know?
Tell support and on-call staff so they can connect any reports to your change quickly.
21Real-World and Industry Examples
The idea of separate stages with separate settings is common to the best-known engineering organisations. Here are public lessons you can use, followed by an illustrative story built on Flagsmith.
Amazon: staged waves before everyone
Amazon has publicly described its habit of deploying changes through a series of stages, beginning with early, low-risk stages and moving through progressively larger ones, with automatic checks between stages, before reaching all customers. Each stage has its own configuration and its own monitoring. This is the same shape as development, staging, and production environments, only extended to more waves for very large systems.
Netflix: pipelines that know their stages
Netflix, together with Google, open-sourced a delivery platform called Spinnaker, which models pipelines made of stages and environments, with strategies such as canary and blue/green releases. Its automated canary analysis tool compares the numbers of a new version against the old one before the release continues. The lesson for Flagsmith users is to let each stage own its settings and let measurements, not feelings, decide whether to advance.
Facebook (Meta): employees first, then the public
Facebook became well known for exposing new features to its own employees before the wider public, and then to growing slices of users. That is the same idea as using a segment override in production for an employees group before a percentage rollout. It lets real people use the real system while mistakes remain cheap.
Google: one codebase, careful gating
Google engineers largely work from a single shared main line of code and rely on strong automated testing and flags to keep it healthy. Behaviour is often hidden behind a flag and switched on gradually. The shared definition and separate decision, which Flagsmith expresses through project and environment, is the same pattern at a larger scale.
Knight Capital: when environments and flags go wrong
In 2012 a trading firm deployed new software to only some of its servers, while a flag that had been repurposed woke up old code on a server that had not been updated. The firm lost hundreds of millions of dollars in under an hour. The lesson is not that flags are dangerous, but that flag names must never be reused, deployments must be verified to be complete, and the ability to switch things off quickly must be practised.
An illustrative story: a media app launching a new player
The following story is an invented example, shown to tie the ideas together. A video streaming company has a project in Flagsmith with three environments: Development, Staging, and Production. A feature called “new video player” is created, switched off everywhere.
Week one: Development
Developers enable the flag in Development. They build the player in small pieces and merge daily, since the flag keeps unfinished work invisible everywhere else.
Week two: Staging
The same build moves to Staging, where the flag is enabled for the “QA testers” segment. Testers check playback on many devices, and performance tests run against a realistic data set.
Week three: Production for employees
The release manager files a change request to enable the flag in Production for the “Employees” segment. After approval, employees use the new player on the real service for two days.
Week three: Production percentage
The flag is enabled for one percent of viewers, then ten, then fifty. At each step the team checks start-up time, buffering rate, and crash rate against the group still on the old player.
A hiccup and a fast reversal
At fifty percent, buffering rises on one family of televisions. The team disables the flag in Production within a minute, investigates in Staging using a test device, fixes the problem, and resumes the rollout two days later. No redeployment was needed.
Cleanup
After three stable weeks at one hundred percent, the old player code and the feature are removed, and the feature disappears from every environment at once.
Think of a new medicine. First it is tried in a laboratory, then in a small, closely watched trial, and only then offered to more people, with doctors ready to stop immediately if something looks wrong. Each stage has its own rules and records. Flagsmith environments give software teams the same careful, staged, reversible path.
Patterns in all these stories
| Source | Main idea | Flagsmith equivalent |
|---|---|---|
| Amazon | Staged waves with checks between | Development, Staging, Production, and gradual rollout in Production |
| Netflix | Pipelines and automated judgement | Pipeline stages using matching environment keys, plus guardrail metrics |
| Employees first | Segment overrides in Production | |
| Shared main line with gating | Shared feature list with separate states | |
| Knight Capital | Reused flags and incomplete deployment | Create features off, never reuse names, verify and rehearse the off state |
22Frequently Asked Questions
Short, clear answers to questions that beginners and experienced engineers often ask about Flagsmith environments.
23Summary and Key Takeaways
You have travelled from the danger of a single shared switchboard to a well-organised set of separate, safe stages. Here is what to remember.
A Flagsmith environment is a separate, self-contained set of decisions about your features, together with its own keys, overrides, permissions, and history. The project defines what exists, and each environment decides what is true here. With environments, developers can experiment boldly, testers can rehearse realistically, and production can be protected carefully, all while one build of the code moves unchanged through every stage. The practical habit to carry away is simple: before touching any flag, ask which environment you are standing in, what it is for, and who will feel the change. Teams that make this question automatic rarely suffer the painful Friday surprises that first led them to adopt environments, and they ship new features with calm confidence, because each stage has already proven what the next one needs to know.
Key Takeaways
- Shared definitions, separate decisions. Features, segments, and tags live at the project level, while on-off states, values, overrides, identities, and keys live in each environment.
- The key is the address. Each environment has its own keys. Use the public client-side key in browsers and apps, and keep the secret server-side key and admin tokens on trusted servers only.
- Match environments to your pipeline. The same build moves from development to staging to production, and only the environment key changes. Start with three environments and add more only with a clear purpose and owner.
- Nothing is copied automatically. Promote changes deliberately, using change requests, scheduled changes, the Admin API, or infrastructure as code, and mirror staging to the next production state before each release.
- Protect production most. Apply least privilege, require review for critical changes, announce changes in a shared channel, and keep an audit trail.
- Plan for failure and measure everything. Always supply safe defaults, prefer local evaluation for busy servers, label every metric with its environment, and watch guardrail numbers during rollouts.
- Create features off and clean up often. Never reuse a flag name, compare environments regularly to catch drift, and delete finished flags and unused environments.