Getting Started with Feature Flags by LaunchDarkly

Toggle

The space camp project provides guidance on how to easily get started with feature flags on launchdarkly and turning on features for a specific group of users.

Installation


Pre-req: Please make sure you have at least Python 3.8 installed

  1. Clone this project back to your local dev environment by running:
    • git clone https://github.com/kleeadrian/space-camp.git
  2. Navigate to space-camp folder
    • cd space-camp
  3. Install the necessary python dependencies by running
    • pip3 install -r requirements

Note: You can also run this within GitHub Codespaces. No need to perform step 1 or 2.

Setup


DO NOT COMMIT YOUR CODE WITH THE SDK KEY. THIS IS MEANT FOR A LOCAL ENVIRONMENT

Note: This section requires access to Launchdarkly. Please sign up for a trial at https://launchdarkly.com/start-trial/

  1. Login to your launchdarkly account by going to app.launchdarkly.com
  2. Navigate to Account Settings

Screen Shot 2021-12-10 at 12 53 11 am

3. Click on Projects > New Projects

Screen Shot 2021-12-10 at 12 53 24 am

4. Provide you project a unique name. Note: Good practice is to name your project that serves a group of users. For e.g. Mobile Apps, Desktop Users. In this example, I'll name it space-camp 5. Click Save 6. Copy the SDK Key of the Test environment

DO NOT COMMIT YOUR CODE WITH THE SDK KEY. THIS IS MEANT FOR A LOCAL ENVIRONMENT

  1. Screen Shot 2021-12-10 at 12 54 14 am
  2. Open up server.py in the space-camp folder and replace os.getenv('LD_SD_KEY') on line 12 with the key you copied. Example end result:

    • ldclient.set_sdk_key('XXXX-XXXXX-XXXXX-XXXXX-XXXXX')
  3. Type in the following command in terminal and navigate to http://127.0.0.1:5000 to see the following page

    • python3 server.py

DO NOT COMMIT YOUR CODE WITH THE SDK KEY. THIS IS MEANT FOR A LOCAL ENVIRONMENT

image

Creating Feature Flags!


  1. Head back to app.launchdarkly.com
  2. Click on Top Left yellow button to ensure that you're navigated to the correct project and environment. Make sure its the same project as the SDK key you copied earlier (incase you have multiple projects)
  3. Click on Feature Flags

Screen Shot 2021-12-10 at 1 51 41 am

4. Press on Create Flag

Screen Shot 2021-12-10 at 1 51 51 am

  1. Call this feature flag pricing-tier-3 (This has to match the Feature_FLAG_KEY in the codebase. Look at Line 32 in server.js
  2. Check the SDKs using Client-ID box
  3. Save
  4. Change the targeting to On and press on Save Changes and the website should have an extra tier image

It should look like

image

Targeting Users in Feature Flags via percentage rollout!


  1. Navigate back to your feature flag
  2. You can perform a percentage based rollout by only rolling out to a subset of users by configuring the feature flag rule

Screen Shot 2021-12-10 at 2 05 41 am

Note: You may want to roll it out 10-20% of users first, then gradually increase to 100% for minimal impact

Targeting Users in Feature Flags via attributes


  1. Navigate to your feature flag
  2. You can also target users based on a specific attribute. E.g. Target users with letters starting with A, B and it matches a regex image

Note: Find a meaningful rollout. Maybe roll it out to users on MAC first, then Android.

You can also view the insights of people who have accessed your web app by navigating to the Insights Tab
image

Things to consider in Production


  • Integrate it back to your APM to monitor any errors that may show up. A list of integrations have been created
  • Define a workflow and several approvers of each feature flag toggling.
  • Determine what scenarios would require a rollback
  • Define a rollout process by targetting users with specific OS, devices or geographies.
  • Keep track of all work items and stories by integrating it back to your work management system
  • Use a secret store to store all secrets
  • Rotate the keys often. A Guide is available here
  • As you add more and more feature flags. It may not become scalable as management of many feature flags may be tough. One idea would be to leverage the terraform provider to create feature flags via a terraform template. Have a look
  • Archive unused flags!