loading...

Comparing integration of Feature Flags between ConfigCat and LaunchDarkly

wardenscotland profile image Charlie Macnamara ・6 min read

Feature flags are great pieces of software. They give you a controlled way to introduce features and capabilities so you don’t end up deploying a feature, only to find out it doesn’t work meaning you need to roll back your change. Instead, it’s as simple as turning on and off your change. This has undeniably saved many software engineers some heartbreak over the years.

My name is Charlie, I'm new to feature flags as a whole and thought I would run through my first-hand experience of setting them up. If you are unfamiliar with using feature flags, just as I am, or are just looking for the right service to put them to use them, you are in the right place. Today we are going to compare the integration process between ConfigCat and LaunchDarkly, using a simple program I created with Python. If you want to follow along, and python isn’t your language of choice. Not to worry! Both companies offer many SDK’s.

First, let’s talk about what we are going to build. For those who are familiar with ConfigCat and their feature flags section of their website, chances are you saw the isCoolCatEnabled toggle and thought “wow, if only I create something as neat”, well if so, you are in luck! That’s exactly what we are going to be demonstrating today. Well, sort of. We are creating a program which when our flag is on will import an image and invert the color, saving the result to a new file. And when the flag is off, our program will delete the file.

Now you know what you’re in for, let’s take a look at integrating on the ConfigCat side. To get started, sign in to your ConfigCat account and select Add Feature Flag, create a name (in my case I have gone with “catinvert”), then click Add Feature Flag. Yes really, it's that simple.

ConfigCat add feature flag

From here we need to install the ConfigCat library so open up your terminal and enter.

pip install configcat-client

If you’re following along with this post you’ll need another library too, so go ahead install the Pillow library with:

pip install Pillow

Now with everything installed, we can get into the fun stuff. Open your favorite IDE, create a new .py file, add an image into the same folder(I decided in the spirit of this post to go with the ConfigCat logo), then we can get started! To implement ConfigCat simply enter the following lines. Again, if your following along I import some more libraries, but this will be reflected as you read on.

ConfigCat imported image


My imported image

import  configcatclient
configcat_client = configcatclient.create_client_with_auto_poll( 'YOUR_SDK_KEY',poll_interval_seconds=10);
YOUR_FEATURE_FLAG = configcat_client.get_value('YOUR_FEATURE_FLAG', False)

Our top-line imports the library we need. Our second line is what determines how often ConfigCat will download and store the values from your program, there are four options you can select for how ConfigCat goes about this, but we have gone with the poll_interval option. The final line is what allows you to access your feature flags and settings.

💡 Please note your SDK key and feature flag name will automatically be added. For security, please never share your SDK key. Don’t worry, we deleted our Feature Flag after we were finished with this post.

Now, we have that out of the way let's have a look at the final program.

import configcatclient
from PIL import Image, ImageOps
import time
import os

configcat_client = configcatclient.create_client_with_auto_poll(
    '1uXXCAAgHzREa0_HhlhMIw/qLn4CgPtwEuTGys-Ropbmg', poll_interval_seconds=1); # <-- This is the actual SDK Key for your Production environment

while True:
    catinvert = configcat_client.get_value('catinvert', False)
    if catinvert:
        im = Image.open('logo.jpg') # imports file
        im_invert = ImageOps.invert(im) # inverts image
        im_invert.save('inverted-logo.jpg', quality=95) # saves new file
    else:
        try:
            os.remove('inverted-logo.jpg') # deletes created file
        except os.error:
            pass        
    time.sleep(1)

With everything in place, let’s run the program and head back to our feature flag. Simply turn the flag on, click save changes, and watch the magic unfold!
ConfigCat  feature flag

The program does exactly as we intended. When the flag is on, the imported image gets inverted, and when off, the image gets deleted.

ConfigCat inverted image
My result image

With all that out the way, let’s hop over to LaunchDarly and implement the same program. Everything starts off similarly, select Create Flag, select a name (I went with “darklyinvert”), and choose your language of choice, again we went for python. Now create a folder and a .py file.
So LaunchDarkly can function, we need to install their SDK library, open up a terminal, and enter the below line.

echo "launchdarkly-server-sdk==6.13.0" >> requirements.txt && pip install -r requirements.txt

Now let's look at what lines of code we need to implement.

import ldclient
if __name__ == "__main__":
  ldclient.set_sdk_key("YOUR_SDK_KEY")
user = {
  "key": "UNIQUE IDENTIFIER",
  "firstName": "Bob",
  "lastName": "Loblaw",
  "custom": {
    "groups": "beta_testers"
  }
}

show_feature = ldclient.get().variation("YOUR_FEATURE_FLAG", user, False)
ldclient.get().close()

The top line imports the LaunchDarkly library. Our second line sets our SDK key. Next, our user information is sent in, we are just sticking to the default information. Following that show_feature allows you to access our feature flags and settings.

💡 Your SDK key and Feature Flag are automatically added.

Once we have done all this, we can save and test our program. Here LaunchDarkly will show you in real-time if they have received an event for your flag before moving on, which is a nice touch to make sure everything is working as intended.

Now, let's use the same program from before to see how everything runs. Below we have the full program code so you can have a clear look at what has been changed, remember, if you're following along you’ll need to add an image into the same folder so LaunchDarkly can get to work. To be fair, let's change our image to LaunchDarkly's logo.

LaunchDarkly imported image


My imported image

import ldclient
from PIL import Image, ImageOps
import time
import os

if __name__ == "__main__":
  ldclient.set_sdk_key("sdk-17e098af-f9df-417b-b846-a29d65144779")

user = {
  "key": "UNIQUE IDENTIFIER",
  "firstName": "Bob",
  "lastName": "Loblaw",
  "custom": {
    "groups": "beta_testers"
  }
}


while True:
    show_feature = ldclient.get().variation("darklyinvert", user, False)
    if show_feature:
        im = Image.open('logo.jpg') # imports file
        im_invert = ImageOps.invert(im) # inverts image
        im_invert.save('inverted-logo.jpg', quality=95) # saves new file
    else:
        try:
            os.remove('inverted-logo.jpg') # deletes created file
        except os.error:
            pass        
    time.sleep(1)

ldclient.get().close()

As you can see, there’s not too much that has changed. The clear difference is the user information LaunchDarkly needs. Let’s run our program, head over to our new feature flag, and turn it on.
LaunchDarkly flag on

The main difference to doing this on LaunchDarkly’s end compared to ConfigCat is that to turn on your flag you must enter the name of your production environment and a comment.

LaunchDarkly inverted image


My result image

As expected, everything worked as intended. Now we have looked into integration on both ends, let’s summarise the key differences:

  • ConfigCat offers 4 different ways off the bat to download your values, LaunchDarkly has options for this, but you’ll need to delve into their customization documentation to set up some extra stuff with their parameters
  • LaunchDarkly tests your connection in the startup process, prompting you to try again if the connection has failed. ConfigCat displays if your initial request was successful by displaying 'last accessed datetime’ message below your feature flag
  • LaunchDarkly needs extra User information in your program. ConfigCat does not require this step
  • Switching your flag on with ConfigCat is as simple as on-off, LaunchDarkly requires you to input some extra information

While both pieces of software ultimately aim to provide the same result of implementing feature flags, there are clear pros and cons to either. With LaunchDarkly being the market leader they offer more support options and you have the security of using a long-standing product, however since you can only use your account on a trial basis this may not be ideal for students, or people just looking to try out feature flags, as well it takes a few more steps to setup. ConfigCat, on the other hand, has a free account type which you can use for as long as you see fit, with the cheapest account type also coming in cheaper than LaunchDarkly’s cheapest account type. And hey, there's also a cute cat as the logo. Just kidding, both pieces of software are great in their own merit and I hope this article has given some extra insight into which one you should use.

Posted on by:

wardenscotland profile

Charlie Macnamara

@wardenscotland

Student, coder, writer, learner of things.

Discussion

markdown guide
 

Hey Charlie, this is a great overview. Thanks for posting this.

[Disclaimer: I work at LaunchDarkly]

I wanted to mention a few things:

"The main difference to doing this on LaunchDarkly’s end compared to ConfigCat is that to turn on your flag you must enter the name of your production environment and a comment."

This is an optional security feature. Often times people would like to force their team members to make a comment before making a change in the production environment.

By default this is turned on for the "Production" environment, and is turned off for the "Testing" environment. You can enable or disable this in the project settings page.

Regarding "LaunchDarkly needs extra User information in your program." - this is also not quite correct. You can pass in an empty user object such as {"key": "any"} if all you wanted to do was turn a feature globally on and off for everyone. The user information allows you to do fine grained targeting, such as being able to target people in a specific location.