Skip to main content

Stand up the Lab

Wire the OpenFeature Java SDK and the flagd contrib provider into a Spring Boot service so flag evaluations are resolved by a flagd sidecar against a flags.json file. Author your first flag, then prove that editing flags.json flips the response on the next request: no app restart, no flagd restart, no redeploy.

Mission Objective

  • curl http://localhost:8080/ (opens in new tab) returns a vision_state reading resolved from flags.json (not the hard-coded 'untreated' fallback)
  • The response payload includes OpenFeature evaluation details: flag key, variant, reason, and value
  • Editing flags.json to change defaultVariant causes the next request to return the new variant without restarting the app or flagd

Key Learnings

  • How an OpenFeature client and provider work together: the SDK is provider-agnostic and the flagd provider plugs in via dependency only
  • What remote provider means in practice: the SDK calls a separate flag service (flagd) over gRPC, not parsing flags.json itself
  • What flags.json looks like for flagd (state, variants, defaultVariant)
  • Why hot-reload of the flag file matters operationally: configuration without redeploy
Best Suited For

Platform engineers, SREs, and developers curious about feature flags, with no prior OpenFeature experience needed, but familiarity with Spring Boot and basic Java will help.

The Story

The lab is on its first shift and it isn't reading the chart. Every subject who walks through the door gets the same hard-coded reading on their record, no matter what the lab director just signed off on. The label coming out of the lab is a literal string baked into the controller, not a reading pulled from the chart.

Your mission: replace that hard-coded label with an OpenFeature client, point that client at the flagd sidecar that already runs next to your Codespace, and let flags.json drive what gets recorded as the subject's vision_state. Prove the lab can change what it records without restarting anything.

Architecture

This level runs as two containers side-by-side in your Codespace: the Spring Boot lab and a flagd sidecar.

The Spring Boot service runs on http://localhost:8080/ (opens in new tab) with one endpoint, GET /. flags.json is mounted read-only into the flagd sidecar; edit it through the IDE and flagd's file watcher picks up the change within about a second. The flagd sidecar serves flag evaluations over gRPC on :8013. The OpenFeature SDK reads FLAGD_HOST and FLAGD_PORT from the environment (pre-set by the devcontainer), so there is no host or port to hard-code.

Ready to start?

Launch in a preconfigured devcontainer

Open in Codespaces (opens in new tab)

Free GitHub account required

Walkthrough
  1. Open in GitHub Codespaces. The devcontainer is pre-configured and starts automatically. When you push from Codespaces, GitHub forks the repository to your account automatically.

    Prefer working locally? Clone the repo and open it in any editor that supports the Dev Containers specification (VS Code, JetBrains IDEs, and others). The devcontainer config will be detected automatically.

  2. Run the lab from the terminal, or press F5 in VS Code with Laboratory.java open. The lab starts in the broken state, returning the hard-coded 'untreated' response:

    ./mvnw spring-boot:run
    
  3. Open the Ports tab and navigate to each service:

    • Port 8080: Spring Boot lab. The lab endpoint. On first load you will see the hard-coded 'untreated' response. This is the broken state you are fixing.
  4. Add the OpenFeature Java SDK and flagd contrib provider to pom.xml. GroupIds, artifactIds, and versions are in the OpenFeature Java SDK docs and the flagd Java provider README.

  5. Create a Spring @Configuration class that builds a FlagdProvider in RPC mode and registers it on the OpenFeature API at startup. No host or port to configure: the devcontainer pre-sets FLAGD_HOST and FLAGD_PORT.

  6. Open flags.json and add a flag named vision_state with two string variants (for example 'blurry' and 'clouded') and a defaultVariant. flagd's file watcher picks up changes within about a second, no restart needed.

  7. Replace the hard-coded return in Trial with an OpenFeature evaluation of vision_state, returning the full evaluation details (flag key, variant, value, reason).

  8. Restart the lab. Confirm the value resolves from flags.json, then edit flags.json, change defaultVariant, save, and re-run curl without restarting anything:

    curl -s http://localhost:8080/ | jq
    

Complete Your Challenge

  • When you push from Codespaces, GitHub forks the repository to your account automatically. If you are working locally, fork the repository on GitHub before pushing.
  • Verify your solution:
    ./verify.sh
    If it passes, it generates a Certificate of Completion you can paste into the discussion.
  • Share your solutions in the challenge thread (opens in new tab) on community.offon.dev.

Completed the challenge? Share your achievement on LinkedIn (opens in new tab)

Toolbox

  • ./mvnw - Maven wrapper checked in next to pom.xml, builds and runs the Spring Boot lab
  • curl (opens in new tab) - makes requests to http://localhost:8080/ (opens in new tab) and shows the reading the lab records
  • jq (opens in new tab) - pretty-prints and filters the JSON evaluation details returned by the SDK
  • flagd sidecar - already running in the devcontainer compose stack on the docker-internal network, no port forwarding needed
Know someone who'd enjoy this?