Moving to the Cloud Presents New Use Cases for Feature Flags
LDUser user = new LDUser("user@test.com");
boolean showFeature = client.boolVariation("your.feature.key", user, false);
if (showFeature) {
// application code to show the feature
}
else {
// the code to run if the feature is off
}

How features are released to internal users and then increasingly to external ones, allowing for testing both in production and via canary deployments. (Diagram courtesy of LaunchDarkly)
Testing in Production
Testing in production used to be somewhat controversial, carrying connotations of cowboy programming and sloppy QA. And, as stated by Cindy Sridharan, a distributed systems engineer and O’Reilly author, it does require real care to do it safely:“[B]eing able to successfully and safely test in production requires a significant amount of automation, a firm understanding of the best practices as well as designing the systems from the ground up to lend themselves well toward this form of testing.”
However, it has significant advantages when done correctly. Sridharan has said:By contrast, testing in production enables your QA team to gain real-world insights about how a given feature actually performs. It can also highlight unexpected problems in other parts of an application that can be hard to stub out, or to replicate elsewhere. The use of tools like feature flags mean that if issues are encountered in the process — for example, the new feature causes some performance degradation, or a drop in customer engagement — a feature can instantly be switched out, simply by turning the flag off, without user disruption or the need to re-deploy. This process can be automated using signals from monitoring and observability tooling such as Datadog and Honeycomb, switching off a feature if a particular threshold is reached, without the need for manual intervention.I’m more and more convinced that staging environments are like mocks – at best a pale imitation of the genuine article and the worst form of confirmation bias.
It’s still better than having nothing – but “works in staging” is only one step better than “works on my machine”. — Cindy Sridharan (@copyconstruct) March 16, 2018
Feature Flags as Technical Debt
Of course, a less desirable but natural outcome of inserting feature flags into source code is the accumulated technical debt that comes from it. As feature flags become more pervasive, touching more elements of the stack, both the risk and the level of technical debt can rapidly grow. In light of this, it is important, when considering a vendor-based solution, to factor in what the product offers to allow better management of flags. A recent Forrester Wave report on feature management and experimentation singled out LaunchDarkly for particular praise in this area. The LaunchDarkly product includes the ability to run analytics to make it easier for development teams to see if a flag is in use, functionality called code references. “Once you’ve spotted a flag that is no longer needed, you can pinpoint the repository and line of code within a few clicks to remove it from the code base,” Ravi Tharisayi, senior director of product marketing at LaunchDarkly told The New Stack. This functionality is complemented by some suggestions on how to manage the removal of flags from a work item and process point of view.Infrastructure as a Feature
Whilst typically used for code-only features and UX experiments, the shift to the cloud and the rise of infrastructure as code has opened up additional use cases. “In a cloud world where the layers of the stack are so intertwined, you can take that concept and really expand the scope of what a feature is, applying those same concepts down to the infrastructure layer,” Tharisayi said. During her talk at Trajectory, Harbaugh described LaunchDarkly’s own database migration, where the vendor moved from an environment based on Postgres and MongoDB to CockroachDB. By running both the legacy and new databases in parallel, the LaunchDarkly team was able to reduce the risk of errors, and could monitor the application performance through each step of the migration. Moreover, customer support agents could gain insights into which version of the database a particular customer was on, enabling a more efficient troubleshooting process. As Charlie Custer noted on the CockroachDB blog, this approach offers further advantages, including time for learning:“[S]hifting to a new database system can require some shifts in thinking, particularly if you’re moving from a legacy, single-node system to a modern, multicloud, multiregion distributed system. It’s essential that you give your team the time and space to experiment and make those shifts — and that, in turn, is only possible if you’re taking a phased migration approach and starting with less critical workloads that allow you a bit of a margin for error.”
This same phased approach — a variation on the strangler pattern — can also be used for migrating from a monolith to a microservices-based architecture, and other types of re-platforming activity.