Skip to content

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:

  1. User Context Update: The Statsig client updates the user context with the current userID and stableID
  2. Flag Refresh: Statsig fetches the latest flag values from the server
  3. 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:

  1. Enabling Maintenance: When maintenance mode is enabled in Statsig dashboard, users will see the maintenance overlay within 5 minutes
  2. 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.js
const POLL_INTERVAL = 5 * 60 * 1000; // Adjust as needed

User Identification

The revalidation uses two identifiers:

  1. userID: Normalized company ID via normalizeStatsigUserID(companyId)
  2. stableID: Cross-session stable identifier stored in cookies

Both are required for proper Statsig user identification and flag evaluation.

Metrics to Track

  1. API Call Volume: Monitor Statsig API calls to ensure polling doesn’t overwhelm the service
  2. Revalidation Success Rate: Track how many revalidation calls succeed vs fail
  3. Flag Update Latency: Measure time between flag change in dashboard and user seeing the change