SlideShare a Scribd company logo
1 of 28
Download to read offline
Adding GraphQL to
your Existing Architecture
Sashko Stubailo
Open Source Lead, Apollo
@stubailo
• Client-side developer ergonomics
• Flexibility means fewer API changes
• Better efficiency, fetch just what you need
GraphQL makes everyone’s life better
So what might block people from using it?
• Where do I start?
• Can I use this at work without rewriting my
existing stuff?
• How do I get running in production?
First questions people ask
• Sometimes presented as totally new way of thinking,
which makes it seem like a big investment
• In practice, it’s a standardization of things people were
already doing
Is GraphQL really that different?
SIDE NOTE
• It’s what made React so easy to adopt
• Can you use it for just one feature or component?
• GraphQL can be done the same way
The golden ticket: Incremental adoption
Web App
Elastic Search MongoDB Dynamo DB
C L I E N T
S E R V E R
API Server
Existing app
Web App
Elastic Search MongoDB Dynamo DB
C L I E N T
S E R V E R
API Server
Existing app + GraphQL
?
?
• Fetch GraphQL anywhere you can do an HTTP request
• For fancier features—caching, network state
management, mutation handling—we’ve worked hard to
make Apollo Client compatible everywhere
• For some projects, great opportunity to improve your UI
and data management together
On the client, incremental is easy
• Model virtually any kind of application data
• Start with client-side needs, fill in API bit by bit
• Uniquely suited to being an API gateway, calling
your existing backends
• Suggestion: Experiment with clients that you can
push code to easily, like web or React Native
Incrementally adoptable API?
Two ways to present GraphQL
• Brownfield, existing app with existing
backend, every situation is different
• GraphQL addresses critical problems
• Greenfield, new app with new
backend, easy to write tutorials
• GraphQL sets you up to grow
• Most content builds “hello world” style APIs from
scratch, or starts with existing GraphQL API
• After you get a taste of the GraphQL experience, you
need a way to get it running in your existing app
• Everyone’s situation is unique
• Can we cut the problem into small bits?
Problem: Not enough guidance
Share live examples of GraphQL server patterns
Launchpad
• Mocking: launchpad.graphql.com/98lq7vz8r
• Neo4j: launchpad.graphql.com/3wzp7qnjv
• MongoDB: launchpad.graphql.com/vkmr1kl83
• Share your own patterns—DataLoader, pagination, etc
—at apollographql/awesome-launchpad
Existing samples on Launchpad
GROW
GRAPHQL COMMUNITY
Getting ready for
production
THE NEXT STEP
1. Understand what is going on inside your server
with instrumentation
2. Know the tools available to make improvements
3. Ensure that backend services are not adversely
affected by the new API layer
Production learning checklist
• You need your instrumentation to understand GraphQL
• Need to have some way to identify common queries,
expensive fields, critical paths, and schema usage
• Write your client code and queries in a way that lets you
identify what you see on the server
First: Instrumentation
Two classes of problems
• High latency or bandwidth usage causes bad experience
for the end-user client app
• Inefficient execution or expensive requests result in too
much load on the API or backend
Client-side improvements
• Load data judiciously to avoid
performance issues
• Load less data at a time, split into
multiple queries, avoid expensive fields
• Improve client-side caching with an
offline cache, cache redirects, and
optimistic UI
• Otherwise, need to improve server
query Human {
human {
name
weather
friends {
name
}
}
}
query Human
Biggest question: Server performance
• Executing each query with low latency needs to be
balanced with load on the API server and backends
• Two dimensions that can be optimized: GraphQL server
overhead, and work done by backend APIs and databases
GraphQL server overhead?
• GraphQL execution engine itself is quite efficient for the value it
provides, usually not the main thing to optimize
• Caching parsing and validation helps a lot, those are some of the
most expensive steps
• Make it stateless to scale horizontally
• Break out of GraphQL data model if necessary with custom scalars
• In general, overhead is easy to limit
Backend API usage
• GraphQL API is much closer to the backend, so
same number of roundtrips is less time
• We should try to make sure we do the same
number of fetches or less than we were doing
without GraphQL
• How can we reduce fetches to the backend or
make them more efficient?
REST
Reducing backend load
• Leverage backend features when you can
• Use something like DataLoader to collect requirements,
then make one batched request and avoid extra roundtrips
• Make sure GraphQL server manages backend load by
listening to backpressure or rate limiting calls
• In theory GraphQL can be very efficient since all data needs
are known ahead of time
Persisted queries?
• Save queries to a database and only send the ID instead
of the whole query string
• Supported by Apollo Client and Relay Modern
• Important to distinguish several possible concepts:
• Static queries - no runtime modification of queries
• Whitelisted queries - only accept known queries
• Persisted queries - send query ID, look it up on server
• Compiled queries - do some optimization in build step
• Different potential benefits from each one
{
id: ‘23235’,
variables: …
}
Preventing malicious queries
• Simple: Basic rate limiting
• Medium: Statically calculate cost from the query
document before execution, reject if too high
• Advanced: Track cost of each client over time, to block
people loading too much data quickly
• For extreme cases: Explicit whitelisting
Advanced performance ideas
• Get the same performance as a hand-crafted REST endpoint
but with no loss of generality
• For certain applications that have extremely common
queries, hand-optimize queries or fragments
• In the resolver, check if we are looking for that selection set
and run a more efficient batched fetch for the subtree
• HTTP caching of whole query results
• You can incrementally adopt GraphQL, start with a quick
prototype to get a feel for it
• Instrument everything to avoid unnecessary optimizations
• Work with backend devs to make sure the databases and
services are happy
• The normal thing is usually fine, but if you discover issues
there are many paths to optimize your GraphQL API
Conclusions
Help grow the community!
• Write more content about intermediate GraphQL topics,
to help people get this amazing API with their data
• Write about your production experiences, performance
optimizations you’ve made, and new patterns you come
up with
Tweet or DM me, let’s work together: @stubailo

More Related Content

What's hot

GraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer toolsGraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer toolsSashko Stubailo
 
Into to GraphQL
Into to GraphQLInto to GraphQL
Into to GraphQLshobot
 
Taking Control of your Data with GraphQL
Taking Control of your Data with GraphQLTaking Control of your Data with GraphQL
Taking Control of your Data with GraphQLVinci Rufus
 
Graphql presentation
Graphql presentationGraphql presentation
Graphql presentationVibhor Grover
 
GraphQL Introduction
GraphQL IntroductionGraphQL Introduction
GraphQL IntroductionSerge Huber
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQLRodrigo Prates
 
How to GraphQL
How to GraphQLHow to GraphQL
How to GraphQLTomasz Bak
 
An intro to GraphQL
An intro to GraphQLAn intro to GraphQL
An intro to GraphQLvaluebound
 
How to GraphQL: React Apollo
How to GraphQL: React ApolloHow to GraphQL: React Apollo
How to GraphQL: React ApolloTomasz Bak
 
Better APIs with GraphQL
Better APIs with GraphQL Better APIs with GraphQL
Better APIs with GraphQL Josh Price
 
REST vs GraphQL
REST vs GraphQLREST vs GraphQL
REST vs GraphQLSquareboat
 
Serverless GraphQL for Product Developers
Serverless GraphQL for Product DevelopersServerless GraphQL for Product Developers
Serverless GraphQL for Product DevelopersSashko Stubailo
 
GraphQL With Relay Part Deux
GraphQL With Relay Part DeuxGraphQL With Relay Part Deux
GraphQL With Relay Part DeuxBrad Pillow
 
Introduction to graphQL
Introduction to graphQLIntroduction to graphQL
Introduction to graphQLMuhilvarnan V
 

What's hot (20)

GraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer toolsGraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer tools
 
GraphQL
GraphQLGraphQL
GraphQL
 
GraphQL + relay
GraphQL + relayGraphQL + relay
GraphQL + relay
 
Into to GraphQL
Into to GraphQLInto to GraphQL
Into to GraphQL
 
Taking Control of your Data with GraphQL
Taking Control of your Data with GraphQLTaking Control of your Data with GraphQL
Taking Control of your Data with GraphQL
 
Graphql presentation
Graphql presentationGraphql presentation
Graphql presentation
 
GraphQL Introduction
GraphQL IntroductionGraphQL Introduction
GraphQL Introduction
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
How to GraphQL
How to GraphQLHow to GraphQL
How to GraphQL
 
An intro to GraphQL
An intro to GraphQLAn intro to GraphQL
An intro to GraphQL
 
GraphQL & Relay
GraphQL & RelayGraphQL & Relay
GraphQL & Relay
 
GraphQL
GraphQLGraphQL
GraphQL
 
Graphql
GraphqlGraphql
Graphql
 
How to GraphQL: React Apollo
How to GraphQL: React ApolloHow to GraphQL: React Apollo
How to GraphQL: React Apollo
 
Better APIs with GraphQL
Better APIs with GraphQL Better APIs with GraphQL
Better APIs with GraphQL
 
REST vs GraphQL
REST vs GraphQLREST vs GraphQL
REST vs GraphQL
 
Serverless GraphQL for Product Developers
Serverless GraphQL for Product DevelopersServerless GraphQL for Product Developers
Serverless GraphQL for Product Developers
 
Intro to GraphQL
 Intro to GraphQL Intro to GraphQL
Intro to GraphQL
 
GraphQL With Relay Part Deux
GraphQL With Relay Part DeuxGraphQL With Relay Part Deux
GraphQL With Relay Part Deux
 
Introduction to graphQL
Introduction to graphQLIntroduction to graphQL
Introduction to graphQL
 

Similar to Adding GraphQL to your existing architecture

CONDG April 23 2020 - Baskar Rao - GraphQL
CONDG April 23 2020 - Baskar Rao - GraphQLCONDG April 23 2020 - Baskar Rao - GraphQL
CONDG April 23 2020 - Baskar Rao - GraphQLMatthew Groves
 
Introduction to Testing GraphQL Presentation
Introduction to Testing GraphQL PresentationIntroduction to Testing GraphQL Presentation
Introduction to Testing GraphQL PresentationKnoldus Inc.
 
Testing Graph QL Presentation (Test Automation)
Testing Graph QL Presentation (Test Automation)Testing Graph QL Presentation (Test Automation)
Testing Graph QL Presentation (Test Automation)Knoldus Inc.
 
apidays LIVE Australia - Have your cake and eat it too: GraphQL? REST? Why no...
apidays LIVE Australia - Have your cake and eat it too: GraphQL? REST? Why no...apidays LIVE Australia - Have your cake and eat it too: GraphQL? REST? Why no...
apidays LIVE Australia - Have your cake and eat it too: GraphQL? REST? Why no...apidays
 
GraphQL-ify your APIs - Devoxx UK 2021
 GraphQL-ify your APIs - Devoxx UK 2021 GraphQL-ify your APIs - Devoxx UK 2021
GraphQL-ify your APIs - Devoxx UK 2021Soham Dasgupta
 
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything togetherSashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything togetherReact Conf Brasil
 
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)Hafiz Ismail
 
Active Cloud DB at CloudComp '10
Active Cloud DB at CloudComp '10Active Cloud DB at CloudComp '10
Active Cloud DB at CloudComp '10Chris Bunch
 
Gutenberg and Headless WordPress.pdf
Gutenberg and Headless WordPress.pdfGutenberg and Headless WordPress.pdf
Gutenberg and Headless WordPress.pdfWP Engine
 
Advantages of Rails Framework
Advantages of Rails FrameworkAdvantages of Rails Framework
Advantages of Rails FrameworkSathish Mariappan
 
GraphQL Munich Meetup #1 - How We Use GraphQL At Commercetools
GraphQL Munich Meetup #1 - How We Use GraphQL At CommercetoolsGraphQL Munich Meetup #1 - How We Use GraphQL At Commercetools
GraphQL Munich Meetup #1 - How We Use GraphQL At CommercetoolsNicola Molinari
 
Running Airflow Workflows as ETL Processes on Hadoop
Running Airflow Workflows as ETL Processes on HadoopRunning Airflow Workflows as ETL Processes on Hadoop
Running Airflow Workflows as ETL Processes on Hadoopclairvoyantllc
 
Lessons learned on the Azure API Stewardship Journey.pptx
Lessons learned on the Azure API Stewardship Journey.pptxLessons learned on the Azure API Stewardship Journey.pptx
Lessons learned on the Azure API Stewardship Journey.pptxapidays
 
SOA with Zend Framework
SOA with Zend FrameworkSOA with Zend Framework
SOA with Zend FrameworkMike Willbanks
 
Your API on Steroids
Your API on Steroids Your API on Steroids
Your API on Steroids QAware GmbH
 
Untangling spring week11
Untangling spring week11Untangling spring week11
Untangling spring week11Derek Jacoby
 
Performance tuning Grails applications
Performance tuning Grails applicationsPerformance tuning Grails applications
Performance tuning Grails applicationsLari Hotari
 
API Management for GraphQL
API Management for GraphQLAPI Management for GraphQL
API Management for GraphQLWSO2
 

Similar to Adding GraphQL to your existing architecture (20)

CONDG April 23 2020 - Baskar Rao - GraphQL
CONDG April 23 2020 - Baskar Rao - GraphQLCONDG April 23 2020 - Baskar Rao - GraphQL
CONDG April 23 2020 - Baskar Rao - GraphQL
 
Introduction to Testing GraphQL Presentation
Introduction to Testing GraphQL PresentationIntroduction to Testing GraphQL Presentation
Introduction to Testing GraphQL Presentation
 
Testing Graph QL Presentation (Test Automation)
Testing Graph QL Presentation (Test Automation)Testing Graph QL Presentation (Test Automation)
Testing Graph QL Presentation (Test Automation)
 
apidays LIVE Australia - Have your cake and eat it too: GraphQL? REST? Why no...
apidays LIVE Australia - Have your cake and eat it too: GraphQL? REST? Why no...apidays LIVE Australia - Have your cake and eat it too: GraphQL? REST? Why no...
apidays LIVE Australia - Have your cake and eat it too: GraphQL? REST? Why no...
 
GraphQL.net
GraphQL.netGraphQL.net
GraphQL.net
 
GraphQL-ify your APIs - Devoxx UK 2021
 GraphQL-ify your APIs - Devoxx UK 2021 GraphQL-ify your APIs - Devoxx UK 2021
GraphQL-ify your APIs - Devoxx UK 2021
 
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything togetherSashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
 
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
 
Active Cloud DB at CloudComp '10
Active Cloud DB at CloudComp '10Active Cloud DB at CloudComp '10
Active Cloud DB at CloudComp '10
 
Gutenberg and Headless WordPress.pdf
Gutenberg and Headless WordPress.pdfGutenberg and Headless WordPress.pdf
Gutenberg and Headless WordPress.pdf
 
Advantages of Rails Framework
Advantages of Rails FrameworkAdvantages of Rails Framework
Advantages of Rails Framework
 
GraphQL Munich Meetup #1 - How We Use GraphQL At Commercetools
GraphQL Munich Meetup #1 - How We Use GraphQL At CommercetoolsGraphQL Munich Meetup #1 - How We Use GraphQL At Commercetools
GraphQL Munich Meetup #1 - How We Use GraphQL At Commercetools
 
Running Airflow Workflows as ETL Processes on Hadoop
Running Airflow Workflows as ETL Processes on HadoopRunning Airflow Workflows as ETL Processes on Hadoop
Running Airflow Workflows as ETL Processes on Hadoop
 
Key alias dev standard final
Key alias   dev standard finalKey alias   dev standard final
Key alias dev standard final
 
Lessons learned on the Azure API Stewardship Journey.pptx
Lessons learned on the Azure API Stewardship Journey.pptxLessons learned on the Azure API Stewardship Journey.pptx
Lessons learned on the Azure API Stewardship Journey.pptx
 
SOA with Zend Framework
SOA with Zend FrameworkSOA with Zend Framework
SOA with Zend Framework
 
Your API on Steroids
Your API on Steroids Your API on Steroids
Your API on Steroids
 
Untangling spring week11
Untangling spring week11Untangling spring week11
Untangling spring week11
 
Performance tuning Grails applications
Performance tuning Grails applicationsPerformance tuning Grails applications
Performance tuning Grails applications
 
API Management for GraphQL
API Management for GraphQLAPI Management for GraphQL
API Management for GraphQL
 

Recently uploaded

A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentMahmoud Rabie
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialJoão Esperancinha
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sectoritnewsafrica
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 

Recently uploaded (20)

A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career Development
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorial
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 

Adding GraphQL to your existing architecture

  • 1. Adding GraphQL to your Existing Architecture Sashko Stubailo Open Source Lead, Apollo @stubailo
  • 2. • Client-side developer ergonomics • Flexibility means fewer API changes • Better efficiency, fetch just what you need GraphQL makes everyone’s life better So what might block people from using it?
  • 3. • Where do I start? • Can I use this at work without rewriting my existing stuff? • How do I get running in production? First questions people ask
  • 4. • Sometimes presented as totally new way of thinking, which makes it seem like a big investment • In practice, it’s a standardization of things people were already doing Is GraphQL really that different? SIDE NOTE
  • 5. • It’s what made React so easy to adopt • Can you use it for just one feature or component? • GraphQL can be done the same way The golden ticket: Incremental adoption
  • 6. Web App Elastic Search MongoDB Dynamo DB C L I E N T S E R V E R API Server Existing app
  • 7. Web App Elastic Search MongoDB Dynamo DB C L I E N T S E R V E R API Server Existing app + GraphQL ? ?
  • 8. • Fetch GraphQL anywhere you can do an HTTP request • For fancier features—caching, network state management, mutation handling—we’ve worked hard to make Apollo Client compatible everywhere • For some projects, great opportunity to improve your UI and data management together On the client, incremental is easy
  • 9. • Model virtually any kind of application data • Start with client-side needs, fill in API bit by bit • Uniquely suited to being an API gateway, calling your existing backends • Suggestion: Experiment with clients that you can push code to easily, like web or React Native Incrementally adoptable API?
  • 10. Two ways to present GraphQL • Brownfield, existing app with existing backend, every situation is different • GraphQL addresses critical problems • Greenfield, new app with new backend, easy to write tutorials • GraphQL sets you up to grow
  • 11. • Most content builds “hello world” style APIs from scratch, or starts with existing GraphQL API • After you get a taste of the GraphQL experience, you need a way to get it running in your existing app • Everyone’s situation is unique • Can we cut the problem into small bits? Problem: Not enough guidance
  • 12. Share live examples of GraphQL server patterns Launchpad
  • 13. • Mocking: launchpad.graphql.com/98lq7vz8r • Neo4j: launchpad.graphql.com/3wzp7qnjv • MongoDB: launchpad.graphql.com/vkmr1kl83 • Share your own patterns—DataLoader, pagination, etc —at apollographql/awesome-launchpad Existing samples on Launchpad
  • 16. 1. Understand what is going on inside your server with instrumentation 2. Know the tools available to make improvements 3. Ensure that backend services are not adversely affected by the new API layer Production learning checklist
  • 17. • You need your instrumentation to understand GraphQL • Need to have some way to identify common queries, expensive fields, critical paths, and schema usage • Write your client code and queries in a way that lets you identify what you see on the server First: Instrumentation
  • 18. Two classes of problems • High latency or bandwidth usage causes bad experience for the end-user client app • Inefficient execution or expensive requests result in too much load on the API or backend
  • 19. Client-side improvements • Load data judiciously to avoid performance issues • Load less data at a time, split into multiple queries, avoid expensive fields • Improve client-side caching with an offline cache, cache redirects, and optimistic UI • Otherwise, need to improve server query Human { human { name weather friends { name } } } query Human
  • 20. Biggest question: Server performance • Executing each query with low latency needs to be balanced with load on the API server and backends • Two dimensions that can be optimized: GraphQL server overhead, and work done by backend APIs and databases
  • 21. GraphQL server overhead? • GraphQL execution engine itself is quite efficient for the value it provides, usually not the main thing to optimize • Caching parsing and validation helps a lot, those are some of the most expensive steps • Make it stateless to scale horizontally • Break out of GraphQL data model if necessary with custom scalars • In general, overhead is easy to limit
  • 22. Backend API usage • GraphQL API is much closer to the backend, so same number of roundtrips is less time • We should try to make sure we do the same number of fetches or less than we were doing without GraphQL • How can we reduce fetches to the backend or make them more efficient? REST
  • 23. Reducing backend load • Leverage backend features when you can • Use something like DataLoader to collect requirements, then make one batched request and avoid extra roundtrips • Make sure GraphQL server manages backend load by listening to backpressure or rate limiting calls • In theory GraphQL can be very efficient since all data needs are known ahead of time
  • 24. Persisted queries? • Save queries to a database and only send the ID instead of the whole query string • Supported by Apollo Client and Relay Modern • Important to distinguish several possible concepts: • Static queries - no runtime modification of queries • Whitelisted queries - only accept known queries • Persisted queries - send query ID, look it up on server • Compiled queries - do some optimization in build step • Different potential benefits from each one { id: ‘23235’, variables: … }
  • 25. Preventing malicious queries • Simple: Basic rate limiting • Medium: Statically calculate cost from the query document before execution, reject if too high • Advanced: Track cost of each client over time, to block people loading too much data quickly • For extreme cases: Explicit whitelisting
  • 26. Advanced performance ideas • Get the same performance as a hand-crafted REST endpoint but with no loss of generality • For certain applications that have extremely common queries, hand-optimize queries or fragments • In the resolver, check if we are looking for that selection set and run a more efficient batched fetch for the subtree • HTTP caching of whole query results
  • 27. • You can incrementally adopt GraphQL, start with a quick prototype to get a feel for it • Instrument everything to avoid unnecessary optimizations • Work with backend devs to make sure the databases and services are happy • The normal thing is usually fine, but if you discover issues there are many paths to optimize your GraphQL API Conclusions
  • 28. Help grow the community! • Write more content about intermediate GraphQL topics, to help people get this amazing API with their data • Write about your production experiences, performance optimizations you’ve made, and new patterns you come up with Tweet or DM me, let’s work together: @stubailo