In the previous chapter, Composite Readiness Logic, we built a "Master Checklist" to decide if the Voice Mode should be active. One of the items on that checklist was checking if the feature is actually enabled by the developers.
Now, we will learn how to control that specific item remotely using Feature Gating.
Imagine you just released a new update with Voice Mode. Thousands of users download it. Suddenly, you realize there is a critical bug: using Voice Mode crashes the entire application!
Without Feature Gating:
Time elapsed: Days. User frustration: High.
With Feature Gating:
Time elapsed: Seconds. User frustration: Low.
Think of your application like a house. The code you write is the wiring. Once the house is built (the app is installed), changing the wiring is hard.
Remote Feature Gating acts like a smart fuse box.
In our project, we use a tool called GrowthBook to manage these fuses.
We use a specific logic called a Kill Switch. Instead of asking "Is this feature on?", we ask "Is this feature disabled?"
We look at a specific flag named: tengu_amber_quartz_disabled.
(Don't worry about the strange name; it's just a code name for this specific emergency switch).
You don't need to talk to the remote server manually. We have a helper function in voiceModeEnabled.ts.
import { isVoiceGrowthBookEnabled } from './voiceModeEnabled';
if (isVoiceGrowthBookEnabled()) {
console.log("Fuse is intact. Feature is GO.");
} else {
console.log("Kill-switch is active. Feature is STOPPED.");
}
What happens here:
true (Safe to run) or false (Do not run).false.Checking a remote server every time you click a button would make the app slow. Instead, we use a Cached Strategy.
isVoiceGrowthBookEnabled runs, it reads from that local file. It is instant.Here is the flow of information:
Let's look at the implementation in voiceModeEnabled.ts. We combine two important checks here.
First, we check if the code exists at all. We will cover this concept in depth in Build-Time Code Elimination.
// Part 1: Check if the code is compiled
export function isVoiceGrowthBookEnabled(): boolean {
// If 'VOICE_MODE' is false during build, the rest of the code vanishes.
if (!feature('VOICE_MODE')) {
return false
}
// ... continued below
Explanation:
feature('VOICE_MODE') checks if we included the Voice code when we built the app. If not, we stop immediately.If the code is present, we check the remote flag.
// ... continued from above
// Part 2: Check the "Kill Switch" flag
// We check 'tengu_amber_quartz_disabled'.
// We provide a fallback value of 'false' (Not disabled).
const isDisabled = getFeatureValue_CACHED_MAY_BE_STALE(
'tengu_amber_quartz_disabled',
false
)
// We return TRUE only if it is NOT disabled.
return !isDisabled
}
Explanation:
getFeatureValue_CACHED_MAY_BE_STALE: This function reads the local cache. The name reminds us that the value might be a few minutes old (stale), which is acceptable for a feature flag.'tengu_amber_quartz_disabled': The ID of the flag in the GrowthBook system.false (The default): If the app can't reach the cache or server, we assume the feature is safe (not disabled) so users can use it.!isDisabled: The logic is reversed. If "Disabled" is true, "Enabled" is false.You have learned how to install a Smart Fuse in your application.
Now that we know the wiring (Code) is safe and the fuse (Flag) is on, we need to make sure the user has the right keys to actually use the voice service.
Next Chapter: Provider-Specific Authentication
Generated by Code IQ