This project demonstrates LaunchDarkly's Guarded Rollout feature, which automatically detects regressions and rolls back releases based on real-time metrics. The demo consists of a Node.js Express server and a React client application that work together to showcase automatic rollback functionality.
The demo simulates a scenario where you're migrating from an old API endpoint to a new one. The new API has a higher error rate (30% vs 10%), which will trigger LaunchDarkly's regression detection and automatically rollback to the old API logic.
- Server: Node.js Express server with a single API endpoint (/:key)
- Client: React application that generates API calls with random user keys
- LaunchDarkly: Controls traffic routing and monitors error rates via Observability SDK
- Guarded Rollout: Automatically detects elevated HTTP 5xx response rates and rolls back
- LaunchDarkly account
- A LaunchDarkly project with a "test" environment
- Node.js and npm or yarn installed
- Create a flag with the key release-new-apiin your LaunchDarkly project
- Copy your project's "test" environment SDK key
- Create a .envfile in the root directory:
LD_SDK_KEY=your_test_environment_sdk_key_hereInstall server dependencies:
npm installInstall client dependencies:
cd src/client
npm install
cd ../..From the root directory:
npm run devThis will start the Express server on port 3000. LaunchDarkly will automatically begin generating OpenTelemetry metrics.
In a new terminal, from the root directory:
npm run dev:clientThe React client will open in your browser and begin generating API calls to the server when "Start Traffic" is clicked.
- The server uses LaunchDarkly to determine whether to execute old or new API logic
- Each API call includes a randomly generated user key as the LaunchDarkly context
- The flag value controls the percentage of traffic sent to each API version
- Old API: 10% error rate
- New API: 30% error rate
- LaunchDarkly Observability SDK captures HTTP 5xx response rates
- When error rates exceed thresholds, Guarded Rollout triggers automatic rollback
- Start a Guarded Rollout in LaunchDarkly dashboard
- Traffic gradually shifts to new API logic
- Elevated error rates are detected
- Automatic rollback occurs (typically within 1 minute)
- Traffic returns to old API logic
- Navigate to your flag's targeting page
- Select the "Test" environment
- Click "Guarded Rollout"
- Select "HTTP 5xx Response Rate" as the metric
- Check "automatically roll back"
- Click "Start Rollout"
To speed up the demo:
- Select a custom rollout duration from the dropdown
- Delete the first couple of stages
- Start at 25% traffic split for faster rollback detection
- GET /:key- Main endpoint that routes traffic based on LaunchDarkly flag- :key- Random user identifier used as LaunchDarkly context key
- Returns JSON response indicating which API version was used
 
The demo intentionally uses different error rates to demonstrate regression detection:
- Old API Logic: 10% error rate
- New API Logic: 30% error rate
These rates are configurable in src/server/server.ts via the ERROR_RATES constant.
LaunchDarkly automatically generates OpenTelemetry metrics when the server starts. In the LaunchDarkly dashboard, you can see the full list of autogenerated metrics by clicking "Metrics" in the left sidenav. These include various flavors of error rates and latency metrics.
- Ensure your .envfile contains the correctLD_SDK_KEY
- Verify the flag key matches release-new-apiin your LaunchDarkly project
- Check that the server is running before starting the client
- Monitor LaunchDarkly dashboard for flag evaluation and metric collection
guarded-rollout-demo/
├── src/
│   ├── server/
│   │   └── server.ts          # Express server with LaunchDarkly integration
│   └── client/
│       ├── src/
│       │   ├── App.tsx        # React application
│       │   └── main.tsx       # Client entry point
│       └── package.json       # Client dependencies
├── package.json               # Server dependencies
└── README.md                  # This file