Federation · Progressive Delivery

Safely roll out GraphQL schema changes with feature flags

Activate feature subgraphs for requests that send a header or cookie. Test changes with real traffic, roll them out gradually, and disable risky changes without deploying new router versions.

Gradual rollouts. Rollback without deploying new router versions.

Feature flags · request-based graph composition

Incoming requestheader · cookieCosmo Routerreads the flag header or cookieFeature compositionuses feature subgraphBase compositiondefault for other requestsRouters that poll Cosmo pick up flag changes · no router redeploy

Available onEvery Cosmo plan

The problem

Why GraphQL schema changes are hard to release safely

In a federated GraphQL architecture, one breaking change or performance regression can affect every client immediately. Staging alone cannot show how a change behaves with real production traffic.

Schema changes can affect every client immediately

A breaking change or performance regression can reach every client before teams know how it behaves in production. Without progressive rollout, teams cannot validate changes with a small user segment before rolling out to more traffic.

Rollback depends on another deployment

When a released feature causes problems, teams often have to revert code, redeploy services, or perform a full rollback deployment. That takes time during the exact moment when they need a fast, low risk way to disable the change.

Parallel subgraph changes collide in one schema

Different teams may change their subgraphs in ways that are incompatible with each other. With one schema, they cannot test those changes in isolation. Large environments cannot run a separate set of subgraphs for each feature branch, so teams need isolated compositions on a shared staging environment.

Our solution

Feature flags for safer GraphQL schema delivery

Feature subgraphs are alternative implementations of base subgraphs in your federated graph. When a feature flag is active for a request, Cosmo Router uses the feature subgraph instead of the base subgraph for that request. Teams can roll out schema changes by header or cookie without deploying a new router version.

How it works

  1. Create a feature subgraph as an alternative implementation of a base subgraph.

  2. Group one or more feature subgraphs into a feature flag. Its labels decide which federated graphs it applies to.

  3. Enable the flag. Routers that fetch config from Cosmo pick up the change on their next config poll. Routers that run from a static config file need the updated file.

  4. Requests select the flag with a header or cookie, set by your load balancer, API gateway, or client.

  5. For matching requests, Cosmo Router uses the graph composition with the feature subgraph. Other requests continue using the base composition. To roll back, stop sending the flag or disable it, without deploying new router versions.

Schema-aware. Federation-native. Without deploying new router versions.

Feature flags

What changes with Cosmo

Before CosmoWith Cosmo
Release schema changes broadlyGradually roll out to a growing share of traffic, such as 1%, 10%, 50%, then 100%. Your load balancer sets the X-Feature-Flag header on that share, and the router serves the flagged composition
Hard to validate a migration with production trafficFor migrations, use shadow mode to compare the new subgraph with the existing implementation before exposing it
Problematic changes often require rollback deploymentsDisable the feature flag without deploying new router versions. Routers pick up the change on their next config poll.
Separate staging environments for each featureShared staging with per-developer feature isolation, within your plan's feature flag limit

Activation methods

Activate a flag with a header or cookie

  • HTTP headers — send the flag name in the X-Feature-Flag header. If a request sends both a header and a cookie, the header wins.
  • Cookies — send feature_flag=<flag name> in the cookie. An unknown flag name gets the base graph.
  • Who sets it — your load balancer or API gateway for a share of traffic, or your client for a subset of users.

Key benefits

Release GraphQL changes gradually and roll back without a redeploy

Every Cosmo plan includes feature flags. See the pricing page for plan limits.

Roll out changes to specific user segments

Activate feature subgraphs for requests that send the flag in a header or cookie. Move from small user segments to broader rollout by changing which requests your load balancer or clients send the flag on, without deploying new router versions.

Validate a migration with real traffic before exposing it

For migration scenarios, use shadow mode to compare the new subgraph against the existing implementation for correctness and performance before wider exposure.

Disable risky changes without deploying new router versions

If a feature causes problems, disable the feature flag. Routers pick up the change on their next config poll, without code changes or new router versions.

Serve different graph compositions by request context

Activate feature flags with a header or cookie. Different requests can use different graph compositions from the same router, so you can run isolated experiments and give different users different API experiences.

Let developers test in isolation on shared staging

Each developer can create a feature subgraph for their changes and use a unique header or cookie while testing. Matching requests use their feature subgraph. Other traffic stays on the base composition, without dedicated staging infrastructure per developer. Each developer needs their own flag, so how many can test at once depends on your plan's feature flag limit.

How Cosmo Feature Flags work

01
Replaces one base subgraph.

Create a feature subgraph

Create a feature subgraph linked to the base subgraph it replaces, then publish its schema. When the flag is active, requests that select it use the feature subgraph instead of the base subgraph.

02
Starts disabled.

Create a feature flag

Group one or more feature subgraphs into a feature flag. Its labels must match the label matchers of the federated graphs it applies to. New flags start disabled, so keep the flag disabled until you are ready to test or roll out the change.

03
Enable, then header or cookie.

Enable the flag and send it

Enable the flag. Requests then select it with the X-Feature-Flag header or the feature_flag cookie, set by your load balancer, API gateway, or client. Cosmo Router serves those requests from the feature flag composition.

04
Start small.

Start with a small share of traffic

Send the flag on a small share of requests or for a subset of users, and monitor before wider exposure. For migrations, you can use shadow mode to compare results before exposing them.

05
No router redeploy.

Expand or disable the flag

Widen the share of requests that send the flag over time. If something goes wrong, stop sending it or disable the flag. Routers that fetch config from Cosmo pick up a disabled flag on their next config poll, without deploying new router versions.

What keeps a feature flag rollout safe

  • New flags start disabled. A flag serves traffic only after you enable it, or create it with --enabled.
  • A failed composition never reaches the router. If the base or feature flag composition fails, Cosmo does not produce the feature flag configuration.
  • Schema checks cover enabled flags. A check composes every enabled feature flag that uses the changed subgraph.
  • An unknown flag name falls back to the base graph. Requests without a matching header or cookie get the base composition.
  • Each flag shows up in your metrics. The router_info Prometheus metric has one series per feature flag configuration, labelled wg_feature_flag.

Use cases

Where Cosmo Feature Flags help most

Migrate from a monolith to federation safely

Migration

Create a feature subgraph that overrides fields from the monolith using `@override`. Use shadow mode to compare the monolith and federated implementation with real traffic, then gradually increase traffic to the new subgraph while monitoring performance. Once the migration is validated, publish the schema change without the feature flag.

Roll out experimental features to selected user segments

Rollout

Create a feature subgraph for the new implementation, then send the flag on requests from a selected user segment with a header or cookie set by your client or API gateway. Validate performance and gather feedback before expanding rollout by changing which requests get the header or cookie.

Let developers test independently on shared staging

Staging

Each developer creates a feature subgraph for their changes and uses a unique header or cookie while testing. Matching requests use their feature subgraph. Other traffic stays on the base composition, so teams can avoid dedicated staging infrastructure per developer. Each developer needs their own flag, so how many can test at once depends on your plan's feature flag limit.

When to use Cosmo Feature Flags

Use Feature Flags when

  • You want to release schema changes or new features to a small user segment before a full traffic rollout.
  • You need to validate changes with real production traffic before exposing them broadly.
  • You need to disable a problematic feature quickly without deploying a new router version.

Requirements

  • You need an existing federated graph with base subgraphs. Feature subgraphs act as alternatives to those base subgraphs.
  • You need Cosmo Router v0.95.0 or later and wgc CLI v0.58.0 or later.
  • Every Cosmo plan includes feature flags: 1 on Developer (free) and Launch, 3 on Scale, and a custom number on Enterprise. Self Hosted (free, open-source) and Enterprise Self Hosted have no limit.

Roll out GraphQL schema changes safely

Use Cosmo Feature Flags to test, roll out, and disable schema changes without deploying a new router version.

Ready to go deeper?

An overview of feature flag concepts, CLI commands for feature flags and feature subgraphs, and a step-by-step tutorial.

Related pages

FAQ

GraphQL feature flags

More detail in the feature flags documentation.