, 18 tweets, 4 min read Read on Twitter
Recently at Knotel we moved our #GraphQL server to use the new @apollographql feature called Federation. vq.io/2yokIkE

At its core Federation stitches together many microservices into a single GraphQL graph exposed to clients

@KnotelEngineer @UriGoldshtein

1/
At Knotel we have a microservice architecture but wanted a single GraphQL endpoint any of our client apps could hit to access our entire data graph. We didn’t want a client app to have to talk to 5 different GraphQL endpoints to get its data.

2/
We also didn’t want a monolithic backend architecture because we wanted engineering squads to own their services, to separate concerns, and to have flexibility as to implementation on a per-service basis.

3/
Further, at Knotel our business (providing flexible workspaces) touches many different concerns across the spectrum from finding real estate to construction and design to helping tenants find space to managing space.

4/
We also have internal, customer-facing, and broker-facing products

tl;dr a monolithic architecture was not optimal for our business case

We tried Schema stitching with Apollo to consolidate microservices into a single graph and found it lacking

5/
So we set up the microservices with REST and stood up a single GraphQL server which housed all of the typedefs, resolvers, etc. because this was pre-Federation. So we basically rolled our own

We called this GraphQL server Foundation because it was core to our infrastructure

6/
This was great for our client apps because they now had a one-stop shop for all their needs (just construct a GraphQL query to hit Foundation and tell it what you need!) but introduced many pain points.

7/
Pain Point 1: Clients talked GraphQL to Foundation but our microservices were REST so Foundation had a ton of boilerplate code essentially converting GraphQL to REST in our resolvers. We wrote utilities to convert but were engineering our way around the problem

8/
Federation fixed this as now our microservices speak GraphQL directly and we have been able to drop that translation layer

Pain Point 2: Any change to a microservice also required a change to Foundation to update the typedefs and resolvers to match.

9/
This resulted in changes needed in multiple microservices to enact a single change. We had a lot of lockstep deployments as a result, losing some of the benefit of using microservices and landing us in a deployment hell.

10/
Federation fixed this because now only the microservice with the change needs deployment on change*. Changes can be isolated to one Service which can wholly own the business logic, the typedefs, and the resolvers.

*note, the Federation service does need to be bounced

11/
Pain Point 3: We also ran into complications with Authorization because we wanted to define role-based access control (RBAC) at the microservice level but as our Foundation GraphQL server was our gateway, it controlled access.

12/
So we had a fragile scheme of services defining roles and permissions and propagating to Foundation whenever they were updated.

Federation fixed this because now the service which holds the RBAC policies directly receives requests so they can be gated by the service itself

13/
Pain Point 4: We also have types we’d like to span microservices to separate concerns and house business logic in the right places. This wasn’t possible with Apollo before Federation cleanly

14/
We hacked it a bit by having all of our types on one server which could then resolve a single type from multiple services, but again this introduced all of the aforementioned mess (one change updates multiple services, requiring lockstep deployments, etc.)

15/
Federation fixed this by giving us an elegant way to split types across services and schema directives make it easy to tell the Federation query planner where to get what without having to write code to do so manually.

Business logic concerns are once again separated!

16/
Overall we’re just getting started with Federation so these are my thoughts a week in (I’m sure we’ll find some pain points once the honeymoon phase wears off)

So far though it's been rad! We chucked thousands of lines of code and removed a whole service from our infra

17/
Apollo Federation vastly simplifies our infrastructure, keeps our concerns separated, and fixes a lot of the pain points we encountered trying to deliver a single graph backed by multiple microservices before Federation

fin

18/
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to Victor Quinn
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!