DEV Community

Charlie Macnamara
Charlie Macnamara

Posted on • Edited on

5 1

Comparing integration of Feature Flags: ConfigCat and LaunchDarkly

Feature flags are great. They give you a controlled way to introduce features and capabilities. It's as simple as turning on and off your change. This has undeniably saved many software engineers some heartbreak.

My name is Charlie. I'm new to feature flags and thought I would share my first-hand experience setting them up. If you are unfamiliar with using feature flags, just as I am, or are just looking for the right service, you are in the right place. Today, we are going to compare the integration process between ConfigCat and LaunchDarkly using a simple Python program.

If you want to follow along but Python isn't your language of choice, don't worry! Both companies offer many SDKs.

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 precisely what we are going to be demonstrating today. Well, sort of. We are creating a program that will import an image and invert the color when our flag is on, saving the result to a new file. And when the flag is off, our program will delete the file.

Now that you know what you're in for, let's look at integrating it 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

We need to install the ConfigCat library from here, so open your terminal and enter it.

"bash
pip install configcat-client

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

""ash
pip install Pillow
Enter fullscreen mode Exit fullscreen mode

Now that everything is installed, we can get into the fun stuff. Open your favorite IDE, create a new .py file, add an image to the same folder(I decided to go with the ConfigCat logo in the spirit of this post), and then we can get started! To implement ConfigCat, simply enter the following lines. Again, if you're 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('Y'UR_FEATURE_FLAG','False)

Enter fullscreen mode Exit fullscreen mode

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

Bulb: Your SDK key and feature flag name will automatically be added. For security, please never share your SDK key. Sorry; we deleted our Feature Flag after we finished this post.

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

"`"thonPythont 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('ca'invert', 'alse)
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 return to our feature flag. 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 the image gets deleted when off.

ConfigCat inverted image


My result image

Let's go to LaunchDaily and implement the same program. Everything starts off similarly: select Create Flag, select a name (I went with "darkly invert"), and then create a folder and a .py file.

For LaunchDarkly to function, we need to install their SDK library, open up a terminal, and enter:
`
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.

"`p" hon
iPythonldclient
if name == "main":
ldclient.set_sdk_key("YOUR_SDK_KEY")
user = {
"key": ""NI" UE IDENTIFIER",
"fir"tName": ""ob",
""lastName": "Loblaw",
"cus"om": {" "gro"ps": ""et"_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; let's stick to the default. 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. LaunchDarkly will show you in real time if they have received an event for your flag before moving on.

Now, let's alter our program. Add an image to the same folder so LaunchDarkly can get to work. Let's change our image to LaunchDarkly's logo.

LaunchDarkly imported image


My imported image

"`py" on
impPythonclient
from PIL import Image, ImageOps
import time
import os

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

user = {
"key"" "U"IQ"E IDENTIFIER",
"firs" Name": "B"b""
"lastName": "Loblaw",
"cust"m": {
" "grou"s": "b" ta"testers"
}"}

while True:
show_feature = ldclient.get().variation("dark"yinvert", us"r, 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, little has changed. The apparent difference is the user information LaunchDarkly needs. Let's start our program, head over to our new feature flag, and turn it on.
<img src="https://dev-to-uploads.s3.amazonaws.com/i/7dpvfbmes7b33ahs8v3z.png" alt="LaunchDarkly flag on"/ width="500" height="500">

The main difference between doing this on LaunchDarkly and ConfigCat is that you must enter the name of your production environment and a comment to turn on your flag.
<figure>
  <img src="https://dev-to-uploads.s3.amazonaws.com/i/43fx2fcl260gra529ph1.jpg" alt="LaunchDarkly inverted image"/ width="270" height="270">
  <figcaption> My result image </figcaption>
</figure>


As expected, everything worked as intended. Now we have looked into integration on both ends, let's look at the key differences:
- ConfigCat offers four different ways off the bat to download your values, LaunchDarkly has options for this, but you'll have to delve into their [customization documentation]
(https://docs.launchdarkly.com/sdk/server-side/python#customizing-your-client) 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 the 'last accessed datetime below your feature flag
- LaunchDarkly needs extra user information for 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

Both software ultimately aim to provide the same result when implementing feature flags—there are clear pros and cons to either. LaunchDarkly is the market leader, offering more support options and 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. ConfigCat, on the other hand, has a free account type that you can use forever, with the base account type being cheaper than LaunchDarkly. And hey, a cute cat is the logo. That's me sold. Just kidding, both pieces of software are excellent in their merit.
Enter fullscreen mode Exit fullscreen mode

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (1)

Collapse
 
levlaz profile image
Lev Lazinskiy

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.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay