System Design AI

Feature Flags in System Design Interviews: When to Use Them and What to Say

Feature flags are a runtime switch that enables or disables a piece of functionality without changing the deployed code. In an interview you can use them to show how you control risk when launching a new feature at scale.

The Problem Feature Flags Solve

When you add a new capability to a live service, you face two risks: a bug that crashes the service, and the inability to roll back quickly. Traditional approaches—code rollbacks or full redeploys—take minutes to hours and often require coordination across many teams. Feature flags give you a knob to turn the new path on for a small fraction of traffic, monitor its health, and expand gradually.

Concrete Example: Photo-Sharing Service

Imagine you are designing a photo-sharing platform that wants to add a new AI-based image compression algorithm. The existing pipeline uses a simple JPEG encoder. The new algorithm is heavier, runs on GPU, and is still being tuned. Deploying it to all users at once could overload the GPU fleet and break uploads.

How Feature Flags Work – Step by Step

  1. Define the Flag – Create an entry in a configuration store (e.g., DynamoDB, Consul, or a simple JSON file) named use_new_compressor with a default value false.
  2. Load at Startup – Each service instance reads the flag value on boot and caches it locally.
  3. Refresh Periodically – A background thread polls the config store every few seconds or subscribes to change events, updating the local cache.
  4. Check Per Request – In the upload handler, wrap the new code path:
go
 if cfg.UseNewCompressor {
 compressWithGPU(image)
 } else {
 compressWithJPEG(image)
 }
  1. Gradual Rollout – Change the flag value to a percentage (e.g., 30%). The service reads the flag and, for each request, draws a random number; if it falls below the percentage, it uses the new path.
  2. Monitoring & Rollback – Metrics (latency, error rate) are collected per branch. If the new branch spikes, set the flag back to false instantly.

Where Feature Flags Appear in Classic Design Questions

Design QuestionExact Spot to Insert a FlagWhy It Helps
Design a URL shortenerIn the redirect service to enable a new cache-first lookup strategyLets you test a CDN layer without breaking existing redirects
Design a real-time chat systemAround the message persistence layer to switch from synchronous DB writes to an async event-sourcing pipelineAllows you to verify eventual consistency before committing all traffic
Design a video streaming platformIn the transcoding pipeline to toggle a new codec (e.g., AV1)Gives you a safety net when the new codec consumes more CPU/GPU than expected

Trade-offs and Alternatives Interviewers May Probe

AspectWith Feature FlagsWithout Feature Flags
Deployment speedInstant rollout or rollback; no redeploy neededRequires a new build and deploy cycle
Operational complexityNeed to manage flag store, cache invalidation, and consistencySimpler code path, fewer moving parts
Latency impactExtra check (an in-memory read when cached) adds microseconds per requestNo extra check, marginally faster
Risk of stale configIf the cache isn’t refreshed, old values linger; need TTL strategyNo stale config risk

Common Alternatives

  • Blue-Green Deployments – Run two parallel versions of the service and switch traffic at the load balancer. Safer for large binary changes but requires double the infrastructure.
  • Canary Releases – Deploy a new version to a small subset of servers. Similar safety but still involves a full redeploy.
  • A/B Testing Frameworks – Often built on top of feature flags; the distinction is that flags are usually binary, while A/B tests handle multiple variants and statistical analysis.

Interviewers may ask you to compare flags to canary releases, focusing on the operational overhead of maintaining two codebases versus a single codebase with runtime switches.

30-Second Pitch

"Feature flags are runtime switches that let you turn new functionality on or off without redeploying. In a large service you store the flag in a central config, cache it locally, and check it on each request. This lets you roll out a new feature to a small percentage of traffic, monitor metrics, and roll back instantly if something goes wrong. The trade-off is a tiny latency increase and the need to keep the flag store consistent, but it’s far safer than a full redeploy or a blue-green deployment."

Mistakes Candidates Often Make

  • Treating flags as a silver bullet – Claiming they solve all rollout problems without acknowledging added complexity.
  • Skipping the cache refresh discussion – Forgetting to mention how stale values are avoided, which leads to inaccurate rollout percentages.
  • Omitting monitoring – Not tying flag branches to separate metrics, making it impossible to decide when to roll back.
  • Confusing flags with versioning – Suggesting a flag replaces the need for proper version control or CI pipelines.
  • Forgetting failure modes – Not addressing what happens if the config store is unavailable; a good answer includes a fallback to the default value.

How to Practice This

  1. Pick a classic design problem (e.g., URL shortener) and draw a full architecture diagram on a canvas.
  2. Identify a single component where a new feature could be toggled, then add a feature-flag box with its config store and cache.
  3. Use System Design AI’s practice brief to run through the interview flow, focusing on explaining the flag’s purpose, rollout plan, and trade-offs.

Questions people ask

When should I bring up feature flags in an interview?

Mention them when you’re adding a new, risky component—like a new compression algorithm, a different storage engine, or a major change to request handling. They show you think about safe rollouts.

How do I handle a config-store outage?

Design the service to fall back to a hard-coded default (usually the stable path). If the store can’t be reached, the cached flag stays unchanged, and the service continues using the default until it restarts.

Do feature flags add noticeable latency?

When cached locally, the check is a simple memory read, adding only microseconds per request. That’s negligible compared to network or disk latency, but you should still mention the cost.

What’s the difference between a feature flag and a canary deployment?

Feature flags toggle code paths inside a single version, giving per-request control. Canary deployments run a separate version on a subset of servers, controlling traffic at the server level. Both mitigate risk, but flags are finer-grained.