5. Managed federation & the supergraph
3m

Overview

Our are running locally, and it's time to see how they fit in with the rest of our architecture. Let's take a step back and look at the overall process for how a supergraph gets made, from start to finish, using .

In this lesson, we will:

  • Outline the overall process for how a gets made from start to finish

The managed federation workflow

Managed federation is an approach to maintaining a . With , updates to your are handled by Apollo Studio and the schema registry, all with zero downtime for your - which we'll get to in a bit.

At a high-level, the workflow looks like this:

  1. Backend developers design and build their .
  2. Someone creates a new in Apollo Studio.
  3. Backend developers publish their to the Apollo schema registry.
  4. The schema registry automatically composes the together into a supergraph schema. and makes it available via Apollo Uplink.
  5. The automatically polls Uplink for any new versions of the .

Let's take a closer look at each of these steps.

Step 1: Teams build their subgraphs

As we've already seen, when using a schema-first approach, the frontend and backend teams first agree on the types and their will include. From there, we move to the backend to decide how to distribute those types and fields across multiple .

The schema agreement from earlier, with each field highlighted to show whether it belongs to the locations or reviews subgraph.

With all that in place, backend teams can independently build out their , complete with schemas, , and .

An illustration showing the first step of the process: backend teams can independently build out their subgraph servers, complete with schemas, resolvers, and data sources.

Step 2: Creating a new supergraph in Apollo Studio

Next, someone needs to create a new in Studio, which will be used by all the for this app. Only one person needs to do this step.

Step 2: create a new deployed graph in Apollo Studio where the subgraphs can be registered

Step 3: Publishing subgraphs

When we're happy that our are looking slick, we'll use the to publish each subgraph's schema to the schema registry. The schema registry is an Apollo-hosted version control system, which enables us to track changes to our schemas over time.

Step 3: publish each subgraph's schema to the Apollo schema registry

Step 4: Composing the supergraph schema

When the schema registry gets a new or updated version of a , it starts a process called composition. The schema registry attempts to combine all of the schemas from the registered into a single . Pretty cool!

Step 4: Composing the supergraph schema

If fails, the schema registry displays an error in Studio, and the process stops there. No stress: we can use the error messages to fix the issue in our , and then try publishing the subgraph with again.

If composition fails, the schema registry displays an error in Apollo Studio

If succeeds and there are no validation errors, the schema registry produces a supergraph schema.

The schema registry automatically sends the to an internal service within Studio called Apollo Uplink. Uplink is a server that stores the latest supergraph schema for each graph.

The schema registry automatically sends the supergraph schema to an internal service within Studio called Apollo Uplink

Step 5: The router polls Uplink for the latest supergraph schema

Next, we need to create another server for the , which we connect to the created in Studio in step 2.

The automatically polls Uplink periodically to see if there's a new version of the .

Most of the time, the sees that the stored in Uplink is the same version as the one it's already using. In this case, nothing changes.

But if the sees that Uplink contains a new version of the , the automatically updates to use the new version - with no need to restart the server, and no downtime!

Step 5: The router polls Uplink for the latest supergraph schema

Now, any clients that communicate with the will be able to reference and the updated schema. But let's come back to that.

Here is the full workflow with the :

The full managed federation workflow

Practice

Managed federation process
Every supergraph includes one or more 
 
, each of which has its own schema. With 
 
, each of these schemas is published to the Apollo schema registry. Whenever a subgraph schema is published, the schema registry triggers a process called 
 
. If successful, this process results in the creation of a 
 
, which is then fetched by the supergraph's 
 
 via periodic polling.

Drag items from this box to the blanks above

  • resolvers

  • data source

  • router

  • supergraph schema

  • composition

  • version control

  • construction

  • subgraphs

  • managed federation

Key takeaways

  • After creating or updating a , developers use the Rover CLI to publish the to the Apollo schema registry.
  • The Apollo schema registry composes the into a , which the uses to resolve incoming client requests.
  • With , schema updates to the are managed by Apollo Studio and happen with zero downtime.

Up next

Awesome, we've learned how the we've built are going to fit into our federated architecture. We're ready to get back to FlyBy and apply what we've learned.

Next up, we're going to use the to publish our .

Previous

Share your questions and comments about this lesson

Your feedback helps us improve! If you're stuck or confused, let us know and we'll help you out. All comments are public and must follow the Apollo Code of Conduct. Note that comments that have been resolved or addressed may be removed.

You'll need a GitHub account to post below. Don't have one? Post in our Odyssey forum instead.