Feature Flag

Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2025-06-02

Problem Statement

Implement a feature flag library that exposes a single function. The function takes the flag's name and an optional map of values

flag.is_on("give_discount", {"user": "user_name", "product": "product_id"})

Design everything that is necessary for engineers to create and modify flags.


You're building a feature flag library that ships with your codebase.

Such a library would allow engineers to toggle functionality using flags without deploying new code. The library exposes a single static API to check whether a feature flag is enabled for a given context.

Example usage:

1# Should we enable a new integration? 2if flag.is_on("enable-new-integration"): 3 # Execute integration logic 4 ... 5 6# Should we calculate tax for this user? 7if flag.is_on("enable-tax-calculation"): 8 # Execute tax calculation 9 ...



To enable engineers to quickly turn feature flags on or off, the system should provide a web interface where flags can be toggled dynamically.

It is the responsibility of your system to interpret the flag parameters appropriately based on how they’ve been modified through the UI.

Task:

Starting from just the interface described above, design a complete system for:

•How a feature flag request is resolved
•How flag configurations are stored
•How flags are evaluated at runtime (e.g., based on user ID, region, or other context)
•How changes to flag values propagate to running services
•How engineers can interact with the system through a UI or API

You should address:

•Backend design
•Caching strategies
•Consistency and latency trade-offs
•Security and auditability of flag changes
•Rollout strategies (e.g., gradual rollout, targeting cohorts)
•Fallbacks and fail-safes


Solution

Comments