Feature Flag Revalidation
Overview
The application implements automatic feature flag revalidation to ensure users receive updated flag values without requiring a page refresh. This is particularly important for flags that control critical application states, such as maintenance mode.
How It Works
Automatic Polling
The Maintenance component (components/Maintenance/index.js) implements a polling mechanism that revalidates Statsig feature flags every 5 minutes.
const POLL_INTERVAL = 5 * 60 * 1000; // 5 minutes
useEffect(() => { const id = setInterval(() => { updateUserAsync({ userID, customIDs: { stableID, }, }).catch(console.error); }, POLL_INTERVAL);
return () => clearInterval(id);}, [updateUserAsync, userID, stableID]);What Gets Revalidated
When updateUserAsync is called:
- User Context Update: The Statsig client updates the user context with the current
userIDandstableID - Flag Refresh: Statsig fetches the latest flag values from the server
- Component Re-render: Components using Statsig hooks (like
useStatsigConfig) automatically re-render with new values
Performance Optimization
The Maintenance component is wrapped in React.memo to prevent unnecessary re-renders:
export default memo<Props>(Maintenance);This ensures that:
- The component only re-renders when props (
userID,stableID) change - Or when Statsig config values (
enabled,loadingPercent) change - Parent component updates don’t trigger unnecessary re-renders
Use Cases
Maintenance Mode
The primary use case is the maintenance mode feature:
- Enabling Maintenance: When maintenance mode is enabled in Statsig dashboard, users will see the maintenance overlay within 5 minutes
- Disabling Maintenance: When maintenance is disabled, users will automatically return to the application within 5 minutes without refreshing
Configuration
Polling Interval
The polling interval is currently set to 5 minutes. To change this:
// In components/Maintenance/index.jsconst POLL_INTERVAL = 5 * 60 * 1000; // Adjust as neededUser Identification
The revalidation uses two identifiers:
userID: Normalized company ID vianormalizeStatsigUserID(companyId)stableID: Cross-session stable identifier stored in cookies
Both are required for proper Statsig user identification and flag evaluation.
Metrics to Track
- API Call Volume: Monitor Statsig API calls to ensure polling doesn’t overwhelm the service
- Revalidation Success Rate: Track how many revalidation calls succeed vs fail
- Flag Update Latency: Measure time between flag change in dashboard and user seeing the change