meridia.lol
The wallBlog

How feature flags and remote config work

Turning parts of your app on and off without redeploying: what happens inside, where they're evaluated, and the mistakes that cost the most.

Written by@Efrain_Jz

Deploying and releasing look like the same thing, but they aren't. Deploying is putting new code in production. Releasing is people seeing it. Feature flags exist to separate those two moments: the code is already in production, but what gets shown is decided by a value you can change without another deploy.

Feature flags and remote config: the same mechanism

A feature flag is an if whose value isn't written in the code:

if (flags.newCheckout) {
  return <NewCheckout />;
}
return <CurrentCheckout />;

Remote config is the same idea, but instead of yes or no it holds any value: a string, a number or a JSON object. A button color, how many products to show, or a banner message.

Feature flagRemote config
Valuetrue / falsestring, number, JSON
Questionis this shown?how is it shown?
Examplenew_checkout: truemax_items: 20

Inside they work the same way. That's why many tools mix them.

The three pieces

Every flag system, from a table in your database to a paid service, has three pieces:

1. Where the value lives   →  a table, a file, a service
2. Who reads it            →  your server or the user's app
3. How a change arrives    →  cache, periodic polling or real-time push

Almost every hard decision comes from pieces 2 and 3.

Where it's evaluated: server or client

On the server, your backend reads the flag and decides what to send. Whatever is off never leaves the server: the user can't see it even if they open the browser's dev tools.

On the client (the browser or a mobile app), the app downloads the values and decides by itself. It's necessary when the decision happens on the device, but it has two consequences:

  • The code for whatever is off does ship to the user. A client-side flag hides a feature, but doesn't protect it. Anything that must not be seen is validated on the server.
  • The app needs default values for when it hasn't downloaded the real ones yet, or when there's no connection.

Firebase Remote Config, for example, works this way: the app ships with defaults, the real values are downloaded (fetch) and applied (activate). By default it doesn't download again more than once every 12 hours, so a change doesn't reach every phone instantly.

This video from the Firebase team shows the whole flow in a web app: defaults, fetch, activate and the change from the console.

Types of flags

  • Yes/no: on for everyone or off for everyone. Works as a kill switch: if something breaks in production, you turn it off in seconds.
  • Value: a closed list of options ("off", "24h", "30d"). More flexible, but every option is a path you have to test.
  • Percentage: on for 10% of users, then 50%, then everyone. That's a gradual rollout.
  • Segment: on only for certain users (your team, a country, a plan).

How it decides who's in the 10%

Picking at random on every visit doesn't work: the same user would see the new feature on one visit and the old one on the next. What you do instead is hash the user id together with the flag name and keep a number from 0 to 99:

function bucket(userId: string, flag: string): number {
  return hash(`${flag}:${userId}`) % 100;
}

const enabled = bucket(user.id, "new_checkout") < percentage;

The same user always lands on the same number, so their experience doesn't change between visits. Going from 10% to 50% only adds users: the ones in the first 10% stay in. And because the flag name is part of the hash, it isn't always the same users trying everything new.

The mistakes that cost the most

1. Not deciding what happens if it fails. If the flag service doesn't answer, your code will use some value. Choose it on purpose: usually the safest one, which tends to be "off".

2. Caching an error. If the query fails and you return the default, that value can stay cached as if it were real. It's better for the error to show than for the flag to turn itself off for hours.

3. Cache versus freshness. Reading the flag on every request is slow and expensive. Caching it is fast, but a change takes time to show. The usual way out is a long cache that gets cleared when the flag changes.

4. Flags that never get deleted. Every flag doubles paths in your code. With 5 yes/no flags there are 32 possible combinations, and nobody tests them all. Once a feature is on for everyone, the flag gets deleted and so does the if.

Your own table or a service?

If you have a few flags and one person changes them, a table in your database is enough. A service like LaunchDarkly, Unleash, GrowthBook or PostHog starts to pay off when you need percentages, segments, change history, or someone who doesn't code to be able to flip them.

A feature flag doesn't make your code safer. It lets you decide when people see it, and turn it off fast if it breaks.