What Is a Feature Flag—and Why Use One?

Updated: Nov 2026

What is a feature flag?

In WunderGraph Cosmo, a feature flag serves a different version of your federated schema to selected requests. The Cosmo Router picks the flag per request: it reads the X-Feature-Flag header or the feature_flag cookie, and the header wins if both are set. The router does not decide what share of traffic gets the flag; your load balancer, proxy, or gateway does that by setting the header.

In WunderGraph Cosmo , feature flags work by creating toggle-able collections of “subgraph replacements”, known as feature subgraphs, for one or more supergraphs.

The three pieces

In summary, a feature flag is built from three things:

Base subgraph. A normal subgraph that already composes your supergraph.

Feature subgraph. An override of a base subgraph. It is linked to exactly one base subgraph and is meant to replace it when active. It carries a new version of that subgraph's schema.

Feature flag. A named, toggle-able collection of one or more feature subgraphs. When the flag is enabled and matched to a request, each of its feature subgraphs replaces its respective base subgraph for that request.

How they fit together

A feature subgraph does nothing on its own. It only takes effect once it is part of a feature flag and that flag is enabled. Toggling a feature flag is what swaps the feature subgraphs in for their base subgraphs.

When you enable a flag, Cosmo runs a fresh composition that includes the feature subgraphs, and embeds that result as a feature-flag configuration inside the router's execution config.

Execution config. The composed artifact the router loads to execute requests. It includes the supergraph schema, subgraph routing info, and any embedded feature-flag compositions so the router can plan and serve queries per request.

Core terminology

This course uses a few core GraphQL Federation terms. As a quick primer, here are the terms we will use in this course:

The overall approach: a way to combine many independently built GraphQL APIs into one unified API, allowing consumers to call a single endpoint instead of each service separately.

Our exercise (using WunderGraph Cosmo)

You'll also come across some vendor-specific terms, such as:

We'll self-host the router locally for this exercise, as described in the next lesson.

Why use feature flags?

Migrating functionality
  • How: Pull a capability out of a monolith into a new subgraph and evaluate the results. Once the outputs match and performance looks good, you promote the flag from shadow to a real rollout.
  • Why: De-risks migration efforts.
Incremental rollout
  • How: Ship a schema change to 1% of clients, watch your metrics, and ramp up only when it looks healthy.
  • Why: If something is wrong, you disable the flag instead of rolling back an entire deploy.
Schema evolution
  • How: Run more than one version of a subgraph's schema at the same time.
  • Why: Clients that opt into the flag see the new fields; everyone else keeps the stable schema until they are ready.
Dynamic configuration
  • How: Because the flag is chosen per request (via a header or cookie), you can drive it from a JWT claim, a cookie, or a gateway rule.
  • Why: Effectively a per-user or per-cohort toggle.
Staging environments
  • How: Instead of standing up a full parallel stack per developer, a single shared environment plus a feature flag can give each developer or team an isolated view of their in-progress schema.
  • Why: Reduces infrastructure overhead and lets developers collaborate or test safely in isolation.

What the router does not handle

An important boundary: the Cosmo Router is not responsible for deciding which percentage of traffic gets the flag.

The router simply reads a header or cookie on each request and serves the matching schema. Deciding which requests carry that header—1%, then 10%, then 100%—is the job of your load balancer, proxy, or gateway. We come back to this in the gradual-rollout lesson.

Learn more in the feature flags docs and on the Cosmo feature flags page.


Task

Knowledge check

What is a feature subgraph?

A feature subgraph on its own, not part of any flag, will…

Who decides what percentage of traffic receives a feature flag?

Frequently asked questions

What is a feature subgraph?

An override of exactly one base subgraph, carrying a new version of its schema.

What does a feature subgraph do on its own, outside any feature flag?

Nothing, until it is part of an enabled feature flag.

Who decides what percentage of traffic receives a feature flag?

Your load balancer, proxy, or gateway that sets the header. The Cosmo Router does not split traffic.