News for hackers. Stuff that matters.
Re:Ask HN: Do you have a guide on how to use feature flags? by dabeeeenster on Monday April 04, 2022 @06:35AM (#30905034)
Re:Ask HN: Do you have a guide on how to use feature flags? by jaredsohn on Monday April 04, 2022 @06:22AM (#30904980)
The easiest way to do it is to create environment variables and check against them in code. This allows turning on / off functionality globally. Systems like AWS and Heroku allow toggling them without redeploying.

You can also create features that apply to individual users or if enterprise then to all users in the customer. This can be done by creating some boolean fields in the database (using a single feature_flags json field is recommended because then you don't have to change the schema every time a new feature flag is added.)

And then in code you check against the environment variable or against the user / customer before running changed functionality via a simple if statement.

Re:Ask HN: Do you have a guide on how to use feature flags? by swah on Monday April 04, 2022 @07:12AM (#30905256)
The idea is that for some particular new feature/behaviour/optimization your application has, instead of just coding it, code it in a way that can be disabled easily:

For example, I have some projects using using redux-saga, I'll do something like:

    if (env.EnableSomeNewThing) {
        yield fork(saga1)
    }
So this behavior can be enabled/disabled using an env variable instead of commenting/reverting code from Git. Of course this could also be more sophisticated: enable via configuration, enable for a sample of the users, or premium users...
Re:Ask HN: Do you have a guide on how to use feature flags? by efortis on Sunday April 03, 2022 @09:44PM (#30902596)
I export a boolean such as `hasFeatureX` and then delete it.

   if (hasFeatureX) doX()
   else …
If it has to be more complex than that, I use a feature branch.
Re:Ask HN: Do you have a guide on how to use feature flags? by Valord on Monday April 04, 2022 @12:27AM (#30903309)
Check out some of the blog posts from https://launchdarkly.com/blog/