Build your first feature-flagged backend service

5 minute read

In this tutorial we will build a working backend API service that connects to CloudBees Unify Feature Management and demonstrates how feature flags control API responses and service behavior. Along the way we will encounter server-side SDK integration, REST API configuration, and how feature flags enable dynamic backend behavior without code deployments.

By the end, you will have a running API service that responds differently based on feature flag values and understanding of how feature flags work in server-side applications.

Before we begin

Before we begin, ensure you have:

  • Completed Get started with feature management.

  • A development environment for at least one backend framework (Java/Maven or Gradle, Python/pip, Go, or .NET SDK).

  • Git installed for cloning repositories.

  • A tool to test APIs such as curl, Postman, or your web browser.

Choose and set up your backend framework

We will start by setting up a pre-built example service that already has feature flag integration configured. You can choose from several backend frameworks: all demonstrate the same feature flag concepts applied to API services.

  1. Choose your preferred framework and clone the corresponding repository:

    Java Spring Boot service
    git clone https://github.com/cloudbees-io/springboot-fm-example.git cd springboot-fm-example
    Python Django service
    git clone https://github.com/cloudbees-io/django-fm-example.git cd django-fm-example
    Go Gin service
    git clone https://github.com/cloudbees-io/gin-fm-example.git cd gin-fm-example
    NET Core service
    git clone https://github.com/cloudbees-io/dotnetCore-fm-example.git cd dotnetCore-fm-example
  2. Open the project in your code editor. You will see a typical backend service structure with API controllers, configuration files, and dependency management.

Notice that the CloudBees Unify SDK is already integrated into the service architecture. This means we can focus on seeing feature flags control API behavior rather than configuring the SDK integration from scratch.

Connect your service to CloudBees Unify Feature Management

Now we need to connect our backend service to your CloudBees Unify Feature Management environment using an SDK key. The SDK key enables the service to fetch feature flag values and respond accordingly.

  1. Navigate to Feature management  Flags in CloudBees Unify.

  2. Select your application from the list. If you don’t see an application, you may need to create one following the getting started tutorial.

  3. Select Copy next to the SDK key to copy it to your clipboard. The SDK key uniquely identifies your feature management environment for this service.

  4. Add the SDK key to your service configuration:

    Java Spring Boot service

    Open the file src/main/resources/application.yaml and locate this line:

    key: "<Your CloudBees SDK key>"

    Replace <Your CloudBees SDK key> with the SDK key you copied.

    Python Django service

    Open the file demo/fm_init.py and locate this line:

    sdk_key = "<Your CloudBees SDK key>"

    Replace <Your CloudBees SDK key> with the SDK key you copied.

    Go Gin service

    Open the file main.go and locate this line:

    sdkKey := "<YOUR-SDK-KEY>"

    Replace <YOUR-SDK-KEY> with the SDK key you copied.

    .NET Core service

    Open the file Demo/Program.cs and locate this line:

    var sdkKey = "<YOUR-SDK-KEY>";

    Replace <YOUR-SDK-KEY> with the SDK key you copied.

  5. Save the file.

Your service is now configured to communicate with your CloudBees Unify Feature Management environment. The SDK will connect automatically and fetch feature flag values when we start the service.

Start your backend service

Let’s start the development server and see our API service running with feature flag integration active.

  1. Install the service dependencies and start the server:

    Java Spring Boot service
    ./gradlew bootRun
    Python Django service
    python3 -m venv venv source venv/bin/activate pip install -r requirements.txt python manage.py migrate python manage.py runserver 8000
    Go Gin service
    go run main.go
    .NET Core service
    dotnet run --project=Demo

The service will start and display the local URL where it’s accessible.

  1. Test the API endpoint by opening your web browser or using curl to access the demo endpoint:

    Java Spring Boot and .NET Core services

    Navigate to: http://localhost:8080/api/demo

    Python Django service

    Navigate to: http://localhost:8000/demo/

    Go Gin service

    Navigate to: http://localhost:8080/demo

You will see a JSON response containing message data controlled by feature flags. The response shows the current state of all feature flag values as they affect the API output.

Test the API and verify flag integration

Now that our service is running and responding to requests, let’s confirm that the feature flags have been automatically detected and are available for configuration.

  1. Return to CloudBees Unify and navigate to Feature management  Flags.

  2. Select your application. You should now see four feature flags that were automatically detected when your service connected:

Table 1. Feature flags in the backend service
Flag name Flag type Description

showMessage

Boolean

Controls whether the message appears in the API response.

message

String

Sets the text content returned in the API response.

fontSize

Number

Controls the font size value returned in the API response.

fontColor

String

Sets the color value returned in the API response.

Notice how these flags control different aspects of the API response structure and content. Unlike frontend flags that directly change what users see, backend flags control data and behavior that can affect multiple clients or downstream services.

If you don’t see these flags, make sure you made at least one request to your API endpoint, as the SDK registers flags when the service first evaluates them.

Control API responses with feature flags

Now we can modify feature flag values in CloudBees Unify and see how they immediately affect our API service responses without any code changes or service restarts.

  1. In CloudBees Unify, select Menu next to the showMessage flag.

  2. Select Configure.

  3. Select your environment from the list.

  4. Change the flag value from its current setting to the opposite (if it’s currently true, set it to false).

  5. Select Save.

  6. Set the Configuration status to On if it isn’t already.

  7. Return to your browser or API testing tool and refresh the API endpoint. Within a few seconds, you will see the API response change: the message data will either appear or disappear from the JSON response.

Let’s try controlling other aspects of the API response:

  1. Configure the message flag and change its value to "Hello from backend feature flags!".

  2. Configure the fontSize flag and set it to 24.

  3. Configure the fontColor flag and set it to red.

  4. Save each change and set the configuration status to On.

Refresh your API endpoint after each change. The JSON response will update immediately to reflect the new flag values, demonstrating how feature flags enable dynamic backend behavior.

This immediate control over API responses is what makes feature flags powerful for backend services. You can modify business logic, toggle features, and control data flow without deploying new code or restarting services.

Conclusion

We have built a backend API service that responds to feature flags in real-time, giving us complete control over service behavior and API responses through the CloudBees Unify Feature Management console. Along the way we encountered server-side SDK integration, automatic flag detection, and how feature flags enable dynamic backend configuration.

You now have hands-on experience with feature flags in backend services and understanding of how server-side feature flagging differs from frontend implementations.

From here, you might want to: