Feature Flagging with LaunchDarkly
What is Feature Flagging?
A feature flag is a software development process used to enable or disable functionality remotely without deploying code. With feature flags, new features can be deployed without making them visible to users. Feature flags enable application teams to add new features to their application and can be enabled for a specific subset of users. Feature flags also allow application teams to modify certain behaviours of their application without changing and deploying their code.
Benefits of Feature Flags
Validate feature functionality
Minimize Risk
Modify system behaviour without disruptive changes
Use Cases of Feature Flags
Product Testing
A/B Testing
Canary Launches
System Outage
What is LaunchDarkly?
LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. LaunchDarkly gives users the power to separate feature rollout from code deployment and manage feature flags at scale. With LaunchDarkly, users are enabled to deploy faster, reduce potential risk, and iterate continuously.
How LaunchDarkly Operates?
LaunchDarkly platform uses a real-time streaming connection which ensures fast feature management services for enterprises of any size. A global CDN ensures the lowest latency without remote requests. LaunchDarkly streaming architecture instantly turns features on/off when you need to, without introducing any latency to the site and it only takes 200 milliseconds to propagate flag updates.
How does streaming connection work?
LaunchDarkly streaming technology provides a consistent connection to SDKs allowing to instantly turn features on/off at a significantly lower cost than polling. Streaming allows to update flags in 200 milliseconds versus other services that poll every 30 seconds or longer and deliver inconsistent or delayed experiences to users and servers.
LaunchDarkly uses server-sent events (SSE), a protocol for one-way real-time messaging, to send messages to servers whenever a change in feature flag rules is made on the dashboard. The SSE connection is handled automatically by the SDKs.
A feature flag will always be available — all flags are stored locally and backed up by globally distributed CDN provider. Even if the CDN goes down (LaunchDarkly uses Fastly, a widely-used CDN provider), servers will continue operating with the last set of feature flag rules, so customers will continue seeing the right set of features.
By default in LaunchDarkly’s server-side SDKs, all SDKs work with an in-memory feature store and update the in-memory state if LaunchDarkly sends updates. This feature store requires no additional configuration. However, data in in-memory feature stores are not persistent. This means when application restarts, the SDK reloads the entire store’s contents. Persistent feature stores solve this problem by persisting their data so that they can be used across application restarts. LaunchDarkly provides integrations for server-side SDKs to store data in persistent data stores like Redis or DynamoDB instead.
One of the ways LaunchDarkly ensure high availability is through Relay Proxy Enterprise (RPE), a microservice that provides an extra layer of redundancy. Retrieve flags and rules from a local stream, reduce outbound connections, and run in a secure “offline” mode.
How feature flagging is integrated using LaunchDarkly in Angular application.
Pre-requisite:
1. A LaunchDarkly account.
2. A Feature Flag configuration.
LaunchDarkly SDKs can either be Client-side or Server-side depending on your use-case.
Using LaunchDarkly, developers can easily control the feature flag variations to be tested depending on the configuration of an authenticated user. Any changes on a flag are returned immediately during runtime and if that authenticated user belongs to the designated audience for testing, the corresponding updates will be received accordingly.
Basically, below are the THREE major steps that should be performed to successfully integrate the LaunchDarkly SDKs in your existing solution.
- Install and Import the LaunchDarkly SDK.
Run the following NPM command to install LaunchDarkly’s JavaScript SDK &
once installation is successful, import the SDK in your solution by updating app.component.ts file and add the line below:
npm install launchdarkly-js-client-sdk
import * as LDClient from "launchdarkly-js-client-sdk";
Initialize the LaunchDarkly Client
Once the SDK is installed and imported, you need to create a single, shared instance of the LaunchDarkly client. To do so, you should provide the environmentkey and featureflagkey which you can retrieve in your LaunchDarkly account.
launchDarkly() {
/*Define User Context*/
const context = {
key: this.username
};
/*LD Client Initialization*/
const ldClient = LDClient.initialize('<environmentkey>', context);
ldClient.waitForInitialization()
.then(() => {
let featureFlag = ldClient.variation('<featureflagkey>');
/*Get Feature Flag current status*/
ldClient.on("change", (value: any) => {
if (value["IsPilotUser"]) {
featureFlag = value['<featureflagkey>'].current;
}
});
});
}
- Run the application to validate flag variation
Here I have created an angular application "LaunchDarklyDemo" where I have successfully integrated LaunchDarkly in it.
Go check it out Feel free to post your question if any.
Subscribe to my newsletter
Read articles from Suraj Pandey directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Suraj Pandey
Suraj Pandey
I'm full stack developer with nearly 3 years of experience in developing applications with Angular, Azure function App(C#), MS SQL.