Frontend System Design · Lesson 85 of 86 · 3 min
Feature Flags and Remote Configuration
This topic tests your ability to design for operational safety, gradual rollouts, and experimentation—core skills for a senior role.
After this lesson, you'll be able to explain how to separate code deployment from feature release. This is the core purpose of feature flags. It allows you to merge and deploy unfinished work, mitigate risk by rolling features out gradually, and run experiments.
A feature flag is a conditional that gates a code path. Remote configuration is the system that delivers the state of that flag (and other dynamic values) from a server. Flags are just one type of remote config; you can also ship strings, numbers, or JSON objects to tweak app behavior without a new build.
This capability is the foundation for canary releases, kill switches, and the A/B tests discussed in the previous lesson. It is a prerequisite for effective trunk-based development.
What a robust client-side implementation looks like
In an interview, you should be able to sketch out a client-side implementation. The most common pattern in a component-based framework is a provider that fetches flags and a hook that consumes them.
This approach centralizes the logic for fetching, caching, and providing defaults.
import React, { createContext, useContext, useEffect, useState, ReactNode } from 'react';
type FlagValues = Record<string, boolean | string | number>;
const FeatureFlagContext = createContext<FlagValues>({});
// Simulate fetching from a remote service
async function fetchRemoteConfig(): Promise<FlagValues> {
await new Promise(resolve => setTimeout(resolve, 100)); // network delay
return {
'new-checkout-flow': true,
'header-text': 'Special Offer!',
'item-limit': 20,
};
}
export function FeatureFlagProvider({ children }: { children: ReactNode }) {
const [flags, setFlags] = useState<FlagValues>({});
useEffect(() => {
fetchRemoteConfig().then(setFlags);
}, []);
return (
<FeatureFlagContext.Provider value={flags}>
{children}
</FeatureFlagContext.Provider>
);
}
export function useFeatureFlag<T>(name: string, defaultValue: T): T {
const flags = useContext(FeatureFlagContext);
const value = flags[name];
return value === undefined ? defaultValue : (value as T);
}
The trap: A naive implementation like this causes UI flicker. The component renders once with an empty flags object, using default values. After the network request completes, it re-renders with the correct flag values, causing a visible layout shift.
To prevent this, you must provide the initial flag values before the first render. The best way is to evaluate flags on the server and embed them in the initial HTML document your server sends. The client can then bootstrap the provider with these values, ensuring the first render is correct.
Designing the end-to-end system
Beyond the client, you need to describe the full system. This includes the tools for managing flags and the service that delivers them.
A complete system has four main parts: an admin dashboard, a configuration service, a database, and the client-side SDK that consumes the data.
The Config Service API is the core. It takes a context object from the client (containing user ID, location, device type, etc.) and evaluates a set of rules to return the correct flag payload for that specific user.
"How do you ensure the client gets updated flag values quickly?"
Your answer should cover a hybrid approach. The SDK fetches on initial load. For subsequent updates, you can use periodic polling, which is simple but introduces latency. For faster updates, a real-time connection like WebSockets or Server-Sent Events allows the server to push changes instantly. The service can also use
ETagorLast-Modifiedheaders so clients can efficiently check for updates without re-downloading the entire payload.
How to manage flag lifecycle and avoid "flag debt"
The trap: Treating all flags as permanent. This is a common mistake that leads to "flag debt"—a codebase cluttered with dead if statements that are hard to reason about and test. A senior engineer knows that most flags are temporary and plans for their removal.
A mature flag lifecycle has four stages:
- Creation: A flag is created for a new feature, experiment, or operational control, and is tied to a ticket.
- Rollout: The flag is used to expose the feature.
- Resolution: The feature is either rolled out to 100% or rolled back. The experiment concludes.
- Cleanup: The flag is removed from the codebase and the flagging system. This is the most forgotten step.
To enforce cleanup, you can use static analysis to find code referencing stale flags. Require a cleanup ticket to be linked when a flag is created. Categorizing flags by purpose (release-toggle, experiment, ops-toggle) also helps clarify their intended lifespan.
Try it
In a personal project, find a hardcoded value, like a UI message or an API endpoint. Refactor it to be retrieved from a simple useFeatureFlag hook like the one above, with a hardcoded default. This takes about 15 minutes and builds the muscle memory for this pattern.
Next: We'll cover how to process the results from these experiments in Experiment Data Collection and Analytics.
Lock it in — apply this lesson under interview conditions.