Coordinating Feature Flags Across Microservices featured image

A feature flag is a software development process that uses a switch or control feature to toggle a function without needing to deploy code. This process provides a way to test a feature before making it publicly available. It enables you to isolate software deployment from its release, giving us greater control over the development cycle.

Developers can implement feature toggling—enabling or disabling feature flags—by including a condition in the code that turns the feature on or off based on the given criteria. In their most basic form, feature flags can be created by inserting if statements directly into the code. However, this manual approach is far from the most sophisticated means of toggling features. 

Moreover, this method becomes extremely challenging to maintain as the code grows. A dedicated and well-resourced developer may be able to do so within monolithic applications. But it is nearly impossible to sustain when used for microservice-based architectures, wherein feature flags may be distributed across several infrastructures with code written in multiple languages. 

Therefore, feature management becomes an ideal solution for optimizing the benefits of microservice-based development. LaunchDarkly offers one such solution by providing powerful feature management tools that enable developers to apply automation, investigate analytics, and coordinate hundreds or thousands of feature flags across diverse architectures. 

To better understand the importance of proper feature management, we’ll first explore some common difficulties that arise when coordinating feature flags across microservices, and then show how LaunchDarkly helps.

Coordinating feature flags across microservices

Toggling a feature in microservices architecture often requires controlling several complex and interconnected pieces of code. Developers often experience difficulty within this architecture when attempting to change the states of certain features. This is because certain features often depend upon the states of other features.

Consider a scenario in which two development teams are managing the same feature. Team A fetches the user’s information, then stores a token generated from this data in the browser’s local storage. 

Simultaneously, Team B is developing a feature for which it must retrieve the token from the browser’s storage and then display concealed information to the dashboard. Therefore, if the former feature isn’t enabled, the latter feature will not work. 

Another challenge within microservices-based architectures is that code infrastructure can vary greatly among different architectures. To compound this issue, there is likely more than one coding language in use. Therefore, managing feature flags with manually produced if statements can significantly slow progress. It also requires exhaustive efforts to ensure consistent functionality across all languages. 

LaunchDarkly’s solutions

To remove the burden of feature management, LaunchDarkly provides several strategies to address the obstacles we most often encounter.

Extensive SDK suite

LaunchDarkly offers a powerful software development kit (SDK) suite that supports the use of feature flags within all major languages, as well as both client-side and server-side frameworks. Its diversity and flexibility are especially beneficial for working with microservice architectures. Furthermore, it supports multiple SDKs for a language and its provided integrations enable these SDKs to connect to any tool in your stack.

Additionally, LaunchDarkly’s SDKs provide API controls for each feature in your codebase via its REST API. These API controls provide a unified and documented way to implement feature flags in the desired language.

Consider React, a widely used client-side library. With LaunchDarkly, implementing feature flags merely requires the installation of the npm package, which contains the entire SDK. Once the installation is complete, you can use it anywhere in your codebase. 

Comprehensive feature management

When one state depends upon another, managing feature flags with if statements can be grueling. LaunchDarkly’s feature management capabilities address this by automatically coordinating complex states and providing a unified interface for managing feature flag states across our microservices. 

Moreover, this interface enables you to use all of the functionality of feature flags, allowing you to execute A/B testing and experiments, user segmentation, and feature delegation. This depth and ease of management mean smoother and more efficient development workflows.

Easy-to-use feature flags

LaunchDarkly provides different types of feature flags: boolean, multivariate, temporary, permanent, and client-side. These feature flags are locally stored, SDK-powered, and updated in real time, ensuring the most consistent development experience.

Additionally, setting up feature flags is straightforward and features ample support documentation. Adding LaunchDarkly feature flags into new or existing code is a simple, four-step process:

  1. Add the LaunchDarkly SDK according to the type of application or codebase you’re working with.
    For example, if you’re using React, you need to install LaunchDarkly’s npm package, launchdarkly-react-client-sdk. It’s worth noting that the client-side SDKs are designed to run on a single-user-based interface, while server-side SDKs are designed for multi-user systems.
  2. Initialize the LaunchDarkly SDK client as soon as you run the project.
    In a React application, you’d need to create an SDK client and wrap the entire application with the created client.
  3. Create flags using LaunchDarkly’s feature flags dashboard.
  4. Use the created flag in production. With LaunchDarkly, you can use rules to target specific groups of users, schedule feature availability timelines, and more.

    You can view LaunchDarkly’s documentation for a list of supported operators and more information about targeting users.

Buying versus building a feature management solution

Although it is possible to build out an experimental feature management solution, the process comes with some significant drawbacks.

Even the simplest if-statement solution requires the coordination and cooperation of several development resources. As a codebase continues to expand, maintaining this solution will monopolize developer time and distract from other issues. 

Furthermore, maintaining proper functionality without an accompanying interface adds unnecessary tedium. But building a separate interface consumes even more development and budgetary resources. Overall, what begins as a simple, homegrown feature management solution becomes an increasingly complex drain on resources.

Therefore, an enterprise-proven system often enables an organization to allocate its time and resources more efficiently. Plus, with LaunchDarkly, you can begin working with feature flags right away, rather than after the weeks or months required to build a functioning solution from scratch.

Conclusion

As beneficial as feature flags can be, they are only as useful as the way we manage them. While temporarily helpful, using the quick and easy if statement presents management challenges as the codebase grows. This is further exacerbated when working with multiple languages and infrastructures across our microservices architecture. When handled improperly, manually implementing and toggling feature flags can result in a broken application.

A feature management platform like that which LaunchDarkly provides can eliminate these stressors. With its extensive suite, SDK-driven approach to feature flags, intuitive UI, and support for the most popular frameworks, LaunchDarkly helps us focus on the implementation of business logic rather than on the minutiae of the deployment flow. 

Related Content

More about Feature Flags

January 3, 2023