Feature Flags Guide

Learn how to use Switchyy as a feature flag system for your applications. Control what features users see without deploying new code.

Overview

Feature flags in Switchyy work through our mode system. While traditional feature flag services give you boolean toggles, Switchyyprovides mode-based control that's perfect for common use cases like maintenance windows, staged rollouts, and emergency shutdowns.

How Feature Flags Work

When your app loads, it connects to Switchyy and receives the current mode for your project. Based on this mode, you can:

  • Show or hide entire features
  • Display maintenance pages
  • Redirect users to different URLs
  • Show custom messages

Implementation

Option 1: Script Tag (Easiest)

Add our script to your HTML and we'll handle everything automatically:

<script 
  src="https://switchyy.vercel.app/switchy.js?key=YOUR_KEY&project=YOUR_ID"
></script>

Option 2: API Integration

For more control, call our decision API directly:

const response = await fetch(
  'https://switchyy.vercel.app/api/v1/decide?projectId=YOUR_ID&key=YOUR_KEY'
);
const { data } = await response.json();

if (data.mode === 'maintenance') {
  // Show maintenance page
} else if (data.mode === 'custom') {
  // Handle custom mode with data.message, data.redirect
} else {
  // Normal operation (live mode)
}

Real-Time Updates

When you change a mode in the dashboard, all connected clients receive the update instantly via Server-Sent Events. No polling required.

Pro Tip

Our script handles SSE connections automatically. If you're using the API directly, connect to /api/v1/events/[projectId] for real-time updates.

Best Practices

  • Fail open: If Switchyy is unreachable, default to showing your app normally.
  • Cache decisions: Our API responses include cache headers. Respect them to reduce latency.
  • Test all modes: Before going live, test how your app behaves in each mode.