Firebase Remote Config — Feature Flags, A/B Testing, and Dynamic App Configuration
In this tutorial, you will learn about Firebase Remote Config. We cover key concepts, practical examples, and best practices to help you master this topic.
Firebase Remote Config lets you change app behavior without publishing updates by providing server-side configuration parameters that clients fetch and apply at runtime.
What You'll Learn
- Setting up Remote Config parameters
- Implementing feature flags
- Targeting users with conditions
Why It Matters
Remote Config enables instant changes without app store review, phased rollouts, and personalized experiences. DodaTech uses Remote Config for feature flags and A/B testing new security features.
Code Examples
// Web: Fetch and use Remote Config
import { getRemoteConfig, getValue, fetchAndActivate } from 'firebase/remote-config';
const remoteConfig = getRemoteConfig();
remoteConfig.settings.minimumFetchIntervalMillis = 3600000; // 1 hour
async function initializeConfig() {
await fetchAndActivate(remoteConfig);
// Get feature flag
const newDashboard = getValue(remoteConfig, 'new_dashboard_enabled');
if (newDashboard.asBoolean()) {
renderNewDashboard();
} else {
renderLegacyDashboard();
}
// Get string parameter
const apiEndpoint = getValue(remoteConfig, 'api_endpoint');
config.apiUrl = apiEndpoint.asString();
// Get number parameter
const maxItems = getValue(remoteConfig, 'max_items_per_page');
config.pageSize = maxItems.asNumber();
}
// Remote Config with React
import { useEffect, useState } from 'react';
import { getRemoteConfig, getValue, fetchAndActivate } from 'firebase/remote-config';
function useFeatureFlag(flagName) {
const [enabled, setEnabled] = useState(false);
useEffect(() => {
async function load() {
const rc = getRemoteConfig();
await fetchAndActivate(rc);
const value = getValue(rc, flagName);
setEnabled(value.asBoolean());
}
load();
}, [flagName]);
return enabled;
}
function App() {
const isNewUIEnabled = useFeatureFlag('new_ui_enabled');
const welcomeMessage = useFeatureFlag('welcome_message');
return (
<div>
{isNewUIEnabled ? <NewUI /> : <LegacyUI />}
<h1>{welcomeMessage}</h1>
</div>
);
}
# Admin SDK: Set Remote Config parameters
import firebase_admin
from firebase_admin import remote_config
template = remote_config.get_template()
# Add feature flag
new_feature = remote_config.Parameter()
new_feature.default_value = remote_config.ParameterValue(
value='false'
)
# Add condition-based value
ios_condition = remote_config.Condition(
name='isIOS',
expression='device.os == "ios"'
)
new_feature.conditional_values = [
remote_config.ConditionalValue(
condition_name='isIOS',
value=remote_config.ParameterValue(value='true')
)
]
template.parameters['new_feature_enabled'] = new_feature
template.conditions = [ios_condition]
# Publish
template = remote_config.publish_template(template)
print('Remote Config published')
# Manage Remote Config via CLI
firebase remoteconfig:get --template > config.json
# Edit config.json, then publish
firebase remoteconfig:deploy config.json
# Rollback to previous version
firebase remoteconfig:rollback --version=5
Common Mistakes
1. Using Too Short Fetch Intervals
Respect minimum fetch interval (default 1 hour). Use test mode for development.
2. Not Providing Default Values
If network fetch fails, default values are used. Always set sensible defaults.
3. Overusing Remote Config for Everything
Use for feature flags and configuration, not for user-specific data.
4. Forgetting to Publish Changes
Parameter changes in the console are not active until published.
5. Not Testing Configuration Changes
Test config changes in a development environment before publishing to production.
Practice Questions
- How do you define a Remote Config parameter?
- How do clients fetch and activate new config?
- What are conditions used for in Remote Config?
- How often should clients fetch new config?
- How do you roll back a configuration change?
Answers:
- In the Firebase Console or via the Admin SDK as a key-value pair with a default value.
- Call fetchAndActivate() to retrieve and apply the latest config.
- To target specific user segments: iOS/Android, country, language, etc.
- Respect the minimum fetch interval. Every 1-12 hours is typical.
- Use the Firebase Console rollback feature or CLI remoteconfig:rollback.
Challenge: Build a feature flag system with Remote Config. Implement flags for new UI, beta features, and API endpoint selection. Create conditions for testing on specific user groups. Set up A/B testing for a feature flag.
FAQ
Mini Project
Build a feature flag management system with Remote Config. Implement flags for multiple features, create conditions for user targeting, set up A/B testing for a new feature, and build an admin dashboard to control flags in real time.
What's Next
Learn about Firebase Analytics for tracking user behavior, then explore Firebase Crashlytics for error monitoring.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro