Slide 1

Slide 1 text

@__xuorig__ GraphQL Conf 2019 So You Want To Distribute Your GraphQL Schema?

Slide 2

Slide 2 text

GraphQL Conf 2019 @__xuorig__ Marc-André Giroux Montréal, Canada @__xuorig__

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

GraphQL Conf 2019 @__xuorig__ Distributed GraphQL?

Slide 5

Slide 5 text

GraphQL Conf 2019 @__xuorig__ Distributed GraphQL The Basic Case GraphQL API query GetRepositories { viewer { repositories(first: 10) { name owner { name } } } }

Slide 6

Slide 6 text

GraphQL Conf 2019 @__xuorig__ Distributed GraphQL Distributed Case query GetRepositories { viewer { repositories(first: 10) { name owner { name } } } } Search Service Monolith User Service

Slide 7

Slide 7 text

GraphQL Conf 2019 @__xuorig__ Distributed GraphQL Distributed Case query GetRepositories { viewer { repositories(first: 10) { name owner { name } } } } Search Service Monolith User Service ?

Slide 8

Slide 8 text

GraphQL Conf 2019 @__xuorig__ Distributed GraphQL Distributed Case query GetRepositories { viewer { repositories(first: 10) { name owner { name } } } } Search Service Monolith User Service

Slide 9

Slide 9 text

GraphQL Conf 2019 @__xuorig__ Schema Stitching

Slide 10

Slide 10 text

GraphQL Conf 2019 @__xuorig__ Schema Federation

Slide 11

Slide 11 text

GraphQL Conf 2019 @__xuorig__ GraphQL Gateway

Slide 12

Slide 12 text

GraphQL Conf 2019 @__xuorig__ GraphQL Modules

Slide 13

Slide 13 text

GraphQL Conf 2019 @__xuorig__ Namespaces

Slide 14

Slide 14 text

GraphQL Conf 2019 @__xuorig__ Schema Delegation

Slide 15

Slide 15 text

GraphQL Conf 2019 @__xuorig__ Schema Composition

Slide 16

Slide 16 text

GraphQL Conf 2019 @__xuorig__

Slide 17

Slide 17 text

"Though there is only one graph, the implementation of that graph should be federated" - https://principledgraphql.com/ GraphQL Conf 2019 @__xuorig__

Slide 18

Slide 18 text

GraphQL Conf 2019 @__xuorig__

Slide 19

Slide 19 text

GraphQL Conf 2019 @__xuorig__

Slide 20

Slide 20 text

GraphQL Conf 2019 @__xuorig__ The API Gateway pattern is far from new...

Slide 21

Slide 21 text

GraphQL Conf 2019 @__xuorig__ So what's different this time?

Slide 22

Slide 22 text

GraphQL Conf 2019 @__xuorig__ API Gateways Endpoint Based GET /users/1 Search Service Monolith User Service

Slide 23

Slide 23 text

GraphQL Conf 2019 @__xuorig__ API Gateways Endpoint Based GET /search?q=stuff Search Service Monolith User Service

Slide 24

Slide 24 text

GraphQL Conf 2019 @__xuorig__ In some ways, not so different...

Slide 25

Slide 25 text

GraphQL Conf 2019 @__xuorig__ Schema "Stitching"

Slide 26

Slide 26 text

GraphQL Conf 2019 @__xuorig__ query { search(query: "stuff") {} issue(id: "abc") {}
 user(id: "def") {} } Search Service Monolith User Service

Slide 27

Slide 27 text

GraphQL Conf 2019 @__xuorig__ Search Service Monolith User Service type Query { search(query: String!): [SearchResult!] } type Query { user(id: ID!): User } type Query { issue(id: ID!): Issue }

Slide 28

Slide 28 text

GraphQL Conf 2019 @__xuorig__ finalSchema = merge(user_schema, search_schema, monolith_schema)

Slide 29

Slide 29 text

GraphQL Conf 2019 @__xuorig__ Gateway type Query { search(query: String!): [SearchResult!] user(id: ID!): User issue(id: ID!): Issue }

Slide 30

Slide 30 text

GraphQL Conf 2019 @__xuorig__ In other ways, much more complex.

Slide 31

Slide 31 text

GraphQL Conf 2019 @__xuorig__ API Gateways •Types, and even singular fields, can possibly be resolved by `n` services •Nested fields may need to be resolved outside the current service •Resolution logic is extremely complex (Avoiding N+1's, handling failure scenarios within resolution of a query, etc) GraphQL

Slide 32

Slide 32 text

GraphQL Conf 2019 @__xuorig__ Search Service Monolith User Service type Query { search(query: String!): [SearchResult!] } union SearchResult = User | Issue type Query { user(id: ID!): User } type Query { issue(id: ID!): Issue } type Issue { owner: User! } Schema Stitching The Harder Parts

Slide 33

Slide 33 text

GraphQL Conf 2019 @__xuorig__ Schema Stitching The Harder Parts Search Service Monolith User Service type Query { search(query: String!): [SearchResult!] } union SearchResult = User | Issue type Query { user(id: ID!): User } type Query { issue(id: ID!): Issue } type Issue { owner: User! }

Slide 34

Slide 34 text

GraphQL Conf 2019 @__xuorig__ •Individual Schemas are invalid on their own, only the final merged schema is valid. •The Gateway is now much more complex than just simple "proxying" Schema Stitching The Harder Parts

Slide 35

Slide 35 text

GraphQL Conf 2019 @__xuorig__ finalSchema = merge(user_schema, search_schema, monolith_schema)

Slide 36

Slide 36 text

GraphQL Conf 2019 @__xuorig__ finalSchema = merge(user_schema, search_schema, monolith_schema)

Slide 37

Slide 37 text

GraphQL Conf 2019 @__xuorig__ finalSchema = merge(...schemas, links)

Slide 38

Slide 38 text

GraphQL Conf 2019 @__xuorig__ Schema Stitching Developer Experience Search Service Monolith User Service Gateway Add the "User.pullRequests" field Add the "User.pullRequests" link

Slide 39

Slide 39 text

GraphQL Conf 2019 @__xuorig__ •Brittle Gateway Code •Business logic often creeping into the Gateway •What we wanted to decentralize often ends up being centralized Schema Stitching Developer Experience

Slide 40

Slide 40 text

GraphQL Conf 2019 @__xuorig__

Slide 41

Slide 41 text

https://www.apollographql.com/docs/graphql-tools/schema-stitching/

Slide 42

Slide 42 text

GraphQL Conf 2019 @__xuorig__ If not schema stitching, then what?

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

GraphQL Conf 2019 @__xuorig__ Hard Mode: The Magic Gateway

Slide 46

Slide 46 text

GraphQL Conf 2019 @__xuorig__ Schema Federation: Don't miss tomorrow's talk!

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

GraphQL Conf 2019 @__xuorig__ Let's take a step back

Slide 49

Slide 49 text

GraphQL Conf 2019 @__xuorig__ Is there a more pragmatic approach to a GraphQL Gateway?

Slide 50

Slide 50 text

GraphQL Conf 2019 @__xuorig__ Why are we here today? Why GraphQL?

Slide 51

Slide 51 text

GraphQL Conf 2019 @__xuorig__ One Size Fits All APIs

Slide 52

Slide 52 text

GraphQL Conf 2019 @__xuorig__ Netflix's Server Side Adapters https://medium.com/netflix-techblog/embracing-the-differences-inside-the-netflix-api-redesign

Slide 53

Slide 53 text

GraphQL Conf 2019 @__xuorig__ Netflix's Server Side Adapters - Daniel Jacobson The better approach for handling API design [...] is to create true separation of concerns, rather than have all server-side decisions made by the API provider.

Slide 54

Slide 54 text

GraphQL Conf 2019 @__xuorig__ SoundCloud's BFF Pattern

Slide 55

Slide 55 text

GraphQL Conf 2019 @__xuorig__ GraphQL can be our BFF

Slide 56

Slide 56 text

GraphQL Conf 2019 @__xuorig__ GraphQL can be our server side client adapter engine

Slide 57

Slide 57 text

GraphQL Conf 2019 @__xuorig__ https://medium.com/netflix-techblog/embracing-the-differences-inside-the-netflix-api-redesign-15fd8b3dc49d

Slide 58

Slide 58 text

GraphQL Conf 2019 @__xuorig__ GraphQL queries are kind of on- demand resource representations

Slide 59

Slide 59 text

GraphQL Conf 2019 @__xuorig__ GraphQL API query { viewer { repositories(first: 10) { name owner { name } } } } "I want this resource in this shape pls"

Slide 60

Slide 60 text

GraphQL Conf 2019 @__xuorig__ GraphQL API query { viewer { repositories(first: 10) { name owner { name } } } } "K, it's accessible at /api/abc"

Slide 61

Slide 61 text

GraphQL Conf 2019 @__xuorig__ GraphQL API GET /api/abc

Slide 62

Slide 62 text

GraphQL Conf 2019 @__xuorig__ We're basically all using REST at this point

Slide 63

Slide 63 text

GraphQL Conf 2019 @__xuorig__ This actually sounds like a great feature for an API gateway!

Slide 64

Slide 64 text

GraphQL Conf 2019 @__xuorig__ What are we looking for in an API Gateway?

Slide 65

Slide 65 text

GraphQL Conf 2019 @__xuorig__ Decouple the clients from the services involved in the consumed use cases

Slide 66

Slide 66 text

GraphQL Conf 2019 @__xuorig__ Avoid domain logic #

Slide 67

Slide 67 text

We remain concerned about business logic and process orchestration implemented in middleware [...] Vendors in the highly competitive API gateway market are continuing this trend by adding features through which they attempt to differentiate their products. This results in OVERAMBITIOUS API GATEWAY products whose functionality — on top of what is essentially a reverse proxy — encourages designs that continue to be difficult to test and deploy. https://www.thoughtworks.com/radar/platforms/overambitious-api-gateways GraphQL Conf 2019 @__xuorig__

Slide 68

Slide 68 text

GraphQL Conf 2019 @__xuorig__ Do we really want to commit to GraphQL for inter-service communication?

Slide 69

Slide 69 text

GraphQL Conf 2019 @__xuorig__ Not all of us are starting from scratch!

Slide 70

Slide 70 text

GraphQL Conf 2019 @__xuorig__ Use Case Based, Curated API

Slide 71

Slide 71 text

GraphQL Conf 2019 @__xuorig__ Really need a distributed schema?

Slide 72

Slide 72 text

GraphQL Conf 2019 @__xuorig__ •Make sure you're not designing your API according to how your services are split up. •Dynamic / runtime "stitching" is scary, proceed with care. •Consider statically building a gateway from a distributed schema using tooling as a middle of the road approach.

Slide 73

Slide 73 text

GraphQL Conf 2019 @__xuorig__ The GraphQL Gateway of my dreams

Slide 74

Slide 74 text

GraphQL Conf 2019 @__xuorig__ •Configuration based / make it hard to do the wrong thing. •Thinest layer achievable •The API Gateway is "just" another service. •If distributed schemas are necessary, make it easy to "import" them into the gateway. •However, the gateway schema is its own thing that represents the source of truth for our exposed API. It requires •Resolution is done through your service communication of choice.

Slide 75

Slide 75 text

GraphQL Conf 2019 @__xuorig__ Often a tradeoff between development & operational complexity

Slide 76

Slide 76 text

GraphQL Conf 2019 @__xuorig__ Alternative: Make developer experience great by building tooling and best practices

Slide 77

Slide 77 text

GraphQL Conf 2019 @__xuorig__ 300+ Contributors to GitHub's GraphQL Schema

Slide 78

Slide 78 text

GraphQL Conf 2019 @__xuorig__ Megabytes of schema definitions

Slide 79

Slide 79 text

GraphQL Conf 2019 @__xuorig__ Multiple teams working on one schema has not been the hard part

Slide 80

Slide 80 text

GraphQL Conf 2019 @__xuorig__ It is very hard to operate a large GraphQL schema at scale, even as a single schema

Slide 81

Slide 81 text

GraphQL Conf 2019 @__xuorig__ GraphQL has all we need to build a great aggregator or gateway!

Slide 82

Slide 82 text

GraphQL Conf 2019 @__xuorig__ Before choosing a solution, ask yourself if the schema itself needs to be distributed

Slide 83

Slide 83 text

Thank you Come see me after the talk! 
 or
 @__xuorig__ on Twitter