Skip to content

Node/Express app with a single endpoint, and a React client that fires traffic at the endpoint, designed to cause a regression when running a Guarded Rollout

Notifications You must be signed in to change notification settings

launchdarkly-labs/guardian-observability-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LaunchDarkly Guarded Rollout Demo

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.

Project Overview

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.

Architecture

  • 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

Prerequisites

  • LaunchDarkly account
  • A LaunchDarkly project with a "test" environment
  • Node.js and npm or yarn installed

Setup

1. LaunchDarkly Configuration

  1. Create a flag with the key release-new-api in your LaunchDarkly project
  2. Copy your project's "test" environment SDK key
  3. Create a .env file in the root directory:
LD_SDK_KEY=your_test_environment_sdk_key_here

2. Install Dependencies

Install server dependencies:

npm install

Install client dependencies:

cd src/client
npm install
cd ../..

Running the Demo

1. Start the Server

From the root directory:

npm run dev

This will start the Express server on port 3000. LaunchDarkly will automatically begin generating OpenTelemetry metrics.

2. Start the Client

In a new terminal, from the root directory:

npm run dev:client

The React client will open in your browser and begin generating API calls to the server when "Start Traffic" is clicked.

How Guarded Rollouts Works

Traffic Control

  • 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

Error Rate Monitoring

  • 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

Rollout/Rollback Process

  1. Start a Guarded Rollout in LaunchDarkly dashboard
  2. Traffic gradually shifts to new API logic
  3. Elevated error rates are detected
  4. Automatic rollback occurs (typically within 1 minute)
  5. Traffic returns to old API logic

LaunchDarkly Dashboard Setup

1. Configure Guarded Rollout

  1. Navigate to your flag's targeting page
  2. Select the "Test" environment
  3. Click "Guarded Rollout"
  4. Select "HTTP 5xx Response Rate" as the metric
  5. Check "automatically roll back"
  6. Click "Start Rollout"

2. Accelerate Testing (Optional)

To speed up the demo:

  1. Select a custom rollout duration from the dropdown
  2. Delete the first couple of stages
  3. Start at 25% traffic split for faster rollback detection

API Endpoints

  • 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

Error Rates

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.

Monitoring

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.

Troubleshooting

  • Ensure your .env file contains the correct LD_SDK_KEY
  • Verify the flag key matches release-new-api in your LaunchDarkly project
  • Check that the server is running before starting the client
  • Monitor LaunchDarkly dashboard for flag evaluation and metric collection

Project Structure

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

Learn More

About

Node/Express app with a single endpoint, and a React client that fires traffic at the endpoint, designed to cause a regression when running a Guarded Rollout

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •