This is a demo for how you can use feature flags with an nginx proxy to do a Guarded Rollout between different versions of a backend service. This can be helpful if you're trying to guard a change that isn't easily able to be flagged in application code, such as when you're changing dependency versions.
The project uses two Docker containers, one running as an nginx proxy and one running as demo Python app.
We run two copies of the Python app container, one blue container representing
the currently deployed copy of the app, and one green container representing
the candidate version of the app. The blue version is configured to serve errors
at a 1% error rate, and the green version is configured to serve errors at a 90%
error rate. The containers use the LaunchDarkly SDK to report metrics which can
be used to evaluate service health when performing the Guarded Rollout. (If you
want to adjust the error rates, you can do so by editing the blue.yaml and
green.yaml files in the app container directory.)
The nginx container is set up to use a LaunchDarkly feature flag to determine which version (blue or green) of the app container it should send requests to. The traffic split between the two different versions of the application will be managed by the Guarded Rollout.
Prerequisites:
- Clone this git repo.
- In your LD project, create the following resources (see our
docs for more information):
requestcontext kind. Make sure to enable it for experiments! It does not need to be the default, though.http-errorsmetric. It should be set up with themetric-keyandevent-keyboth equal tohttp-errors, as "Percentage ofrequestunits that sent the event, wherelower is betterincluding units that did not send any events, and setting their value to 0", and with theconversion: binarymetric kind.service-proxy-hostfeature flag. This should be a multivariate feature flag and its values should be the hostnames of the two containers. If you're using the default settings here, they should beservice-blueandservice-green. Set the flag to serve theservice-bluevariation to start.
- Create a file in the root directory of this project named
sdk-key.txtwhich contains only your sdk key. (E.g.cat sdk-key.txtshould output something like this:)$ cat sdk-key.txt sdk-(uuid)
- Follow the steps below to start the containers (currently only
docker-composeis supported). - Start a Guarded Rollout in the UI from the
service-blueflag variation to theservice-greenflag variation. For testing purposes, it's probably easiest to do a custom rollout with only a 50% traffic split. Enable auto-rollback if you want to see that in action. - Send traffic to the nginx proxy, e.g. by repeatedly
curling it:while true; do curl http://localhost:8080; echo ""; done
- You should see traffic going to the blue service only before you start the rollout, then a mix of traffic to the blue and green services, then only blue again after the rollout is rolled back (if you selected auto-rollback).
- Run
docker composeto create the containers:docker-compose up -d --build --force-recreate