SlideShare uma empresa Scribd logo
1 de 38
Serverless GraphQL
InfoQ.com: News & Community Site
• Over 1,000,000 software developers, architects and CTOs read the site world-
wide every month
• 250,000 senior developers subscribe to our weekly newsletter
• Published in 4 languages (English, Chinese, Japanese and Brazilian
Portuguese)
• Post content from our QCon conferences
• 2 dedicated podcast channels: The InfoQ Podcast, with a focus on
Architecture and The Engineering Culture Podcast, with a focus on building
• 96 deep dives on innovative topics packed as downloadable emags and
minibooks
• Over 40 new content items per week
Watch the video with slide
synchronization on InfoQ.com!
https://www.infoq.com/presentations/
serverless-graphql
Purpose of QCon
- to empower software development by facilitating the spread of
knowledge and innovation
Strategy
- practitioner-driven conference designed for YOU: influencers of
change and innovation in your teams
- speakers and topics driving the evolution and innovation
- connecting and catalyzing the influencers and innovators
Highlights
- attended by more than 12,000 delegates since 2007
- held in 9 cities worldwide
Presented at QCon San Francisco
www.qconsf.com
Howdy!
I’m Jared Short
Director of Innovation @
@shortjared
GraphQL
A query language for your API, and a
runtime for executing the queries
Why GraphQL
● One endpoint for your API
● Can provide an easy to understand API layer for
your aggregated resources
● Only get the data you ask for, in the same shape
● Streamlined API iteration and extensibility
● Fantastic tooling / community
Technical Details of GraphQL
● Typed API and schema definitions
● Queries == Read, Mutations == Write
● Execution engine parses query to graph, each
node runs through resolvers to fetch data
● Elegantly solves 1+n problem
Example Schema
type Speaker {
firstName: String!
lastName: String!
talks: [Talk]
}
type Talk {
speakers: [Speaker!]
startTime: Int!
endTime: Int
title: String!
room: String!
}
Understanding the Schema
TLDR
GraphQL Schema Cheat Sheet
● Explicitly define all types
in the graph
● Define lists of types
● Nullable vs non nullable
(!)
● Scalars, Unions, Enums,
Inputs, etc
● Queries and
mutations
available at the
“root”
● Accept arguments
for scalars or input
types, return types
Query / Mutation Root
type QueryRoot {
speakers(limit: Int = 10): [Speaker]
talks(sort: ASCENDING): [Talk]
}
input TalkInput {
title: String!
Speakers: [ID!]!
}
type MutationRoot {
createTalk(talk: TalkInput): Talk
}
Understanding Root Resolvers
type QueryRoot {
speakers(limit: Int = 10): [Speaker]
talks(sort: ASCENDING): [Talk]
}
Understanding Root Resolvers
QueryRoot: {
speakers(root, args, context){
return new SpeakerService(context).loadSpeakers(args.limit);
},
talks(root, args, context){
Return new TalkService(context).loadTalks(args.sort);
}
}
type Speaker {
firstName: String!
lastName: String!
talks: [Talk]
}
Understanding Field Resolvers
Speaker: {
talks(root, args, context){
Return new TalkService(context).loadByIds(root.talkIds);
}
}
A Thin Wrapper on Business Logic
● GraphQL is NOT your business logic layer
● As thin as possible on top of your business logic
● You can map to multiple data sources
○ Rest API, Database, Filestore, etc
Developer Client Experience
● Ask for and receive exactly what you want, how
you want it
● Limited API versioning concerns
● Easy to write efficient network requests
● API introspection (GraphiQL)
Developer Client Experience
● Ask for and receive exactly what you want, how
you want it
● Limited API versioning concerns
● Easy to write efficient network requests
● API introspection (GraphiQL)
Serverless
Serverless?
● Still run on servers, you just don’t care
● Moves your responsibility higher up the stack
● Billing at ms increments (micropayments!)
● Pairs very well with event driven models
Why Serverless
● Reduced complexity of scaling
● High availability
● Economics / Total Cost of Ownership
● Rapid iteration, learn fast
Developer Hints
● Your Functions as a Service (FaaS) provider
should be irrelevant
● Rethink traditional requirements and
approaches
● Can it be event driven?
Serverless
GraphQL
● All the normal serverless wins (scalability,
availability, etc)
● All the power of GraphQL for clients and systems
● Smooth out some rough edges of GraphQL
○ Resource Exhaustion Attacks
○ Complex Resolvers
Why Serverless GraphQL
● Think DoS attack that’s easy to do by mistake
● Deeply nested request / pagination abuse
● Useful Optimization & Prevention
○ Enforce pagination & limits
○ Maximum depth checking
○ Request Batching & Caching
Resource Exhaustion Attacks
Resource Exhaustion Attacks
REQUEST RESPONSE
REA Mitigation (The Easy Way)
● Each graphql execution is allocated its own
resources
● Set a reasonable resource allocation & timeout
● Web Application Firewalls to stop bad actors
Query Metrics
179 Speakers & 130 Talks
No Cache or Batching
Requests: 359
Cache Only / Batch Only
Requests: 132 / 3
Cache & Batching
Requests: 2
Example Query
query {
speakers {
firstName
talks {
title
speakers {
firstName
}
}
}
}
● Fresh cache for each
invocation
● Hard part abstracted
away from devs
● DataLoader
https://github.com
/facebook/dataloader
Request Batching & Caching
Complex Resolvers & Multi-Data Sources
● Multiple data sources
and aggregation made
easy
● More expensive
queries, split to
different lambda
Schema Stitching
Souce: https://dev-blog.apollodata.com/graphql-schema-stitching-8af23354ac37
Schema Stitching
Souce: https://dev-blog.apollodata.com/graphql-schema-stitching-8af23354ac37
REQUEST RESPONSE
Schema Stitching
Souce: https://dev-blog.apollodata.com/graphql-schema-stitching-8af23354ac37
Schema Stitching with Links
Souce: https://dev-blog.apollodata.com/graphql-schema-stitching-8af23354ac37
REQUEST RESPONSE
Schema Stitching So What
● Still a newer concept and area in GraphQL
● Keep thinking in microservices
● Easily extend and add functionality to your
services
● Composable services and products
○ Encourage reuse of services
○ Compose services into whole new offerings
A word of
warning….
Don’t be that person...
When not to use (force) it
● Non-problem rarely used legacy system
● Big data exports (async returns is fine)
● Internal buy in is key, if inertia is strongly
against you, don’t force it, start small
● You can sneakily integrate downstream without
forcing them to migrate
Protect Downstream Systems
● You are only as strong as your weakest
resources
● Serverless scales, your dependencies don’t
● Queues, caching, play nice
Back to Basics
● Authorization
● Pagination (relay spec)
● Good documentation
Getting Started
GraphQL
Dan Schafer - GraphQL at Facebook Talk (Pagination & Auth discussed) (via YouTube)
Apollo Stack - http://dev.apollodata.com/
GraphQL Schema Cheat Sheet
Serverless GraphQL
Boilerplate Starter: https://github.com/serverless/serverless-graphql
Graphcool
Hybrid Faas Framework & GraphQL engine: https://www.graph.cool/
- Open Source with SaaS Offerings
Thanks!
Questions?
@shortjared
Watch the video with slide
synchronization on InfoQ.com!
https://www.infoq.com/presentations/
serverless-graphql

Mais conteúdo relacionado

Mais de C4Media

Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDC4Media
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine LearningC4Media
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at SpeedC4Media
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsC4Media
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsC4Media
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerC4Media
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleC4Media
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeC4Media
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereC4Media
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing ForC4Media
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data EngineeringC4Media
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreC4Media
 
Navigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery TeamsNavigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery TeamsC4Media
 
High Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in AdtechHigh Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in AdtechC4Media
 
Rust's Journey to Async/await
Rust's Journey to Async/awaitRust's Journey to Async/await
Rust's Journey to Async/awaitC4Media
 
Opportunities and Pitfalls of Event-Driven Utopia
Opportunities and Pitfalls of Event-Driven UtopiaOpportunities and Pitfalls of Event-Driven Utopia
Opportunities and Pitfalls of Event-Driven UtopiaC4Media
 
Datadog: a Real-Time Metrics Database for One Quadrillion Points/Day
Datadog: a Real-Time Metrics Database for One Quadrillion Points/DayDatadog: a Real-Time Metrics Database for One Quadrillion Points/Day
Datadog: a Real-Time Metrics Database for One Quadrillion Points/DayC4Media
 
Are We Really Cloud-Native?
Are We Really Cloud-Native?Are We Really Cloud-Native?
Are We Really Cloud-Native?C4Media
 
CockroachDB: Architecture of a Geo-Distributed SQL Database
CockroachDB: Architecture of a Geo-Distributed SQL DatabaseCockroachDB: Architecture of a Geo-Distributed SQL Database
CockroachDB: Architecture of a Geo-Distributed SQL DatabaseC4Media
 
A Dive into Streams @LinkedIn with Brooklin
A Dive into Streams @LinkedIn with BrooklinA Dive into Streams @LinkedIn with Brooklin
A Dive into Streams @LinkedIn with BrooklinC4Media
 

Mais de C4Media (20)

Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CD
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine Learning
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at Speed
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep Systems
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.js
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly Compiler
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix Scale
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's Edge
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home Everywhere
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing For
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data Engineering
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
 
Navigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery TeamsNavigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery Teams
 
High Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in AdtechHigh Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in Adtech
 
Rust's Journey to Async/await
Rust's Journey to Async/awaitRust's Journey to Async/await
Rust's Journey to Async/await
 
Opportunities and Pitfalls of Event-Driven Utopia
Opportunities and Pitfalls of Event-Driven UtopiaOpportunities and Pitfalls of Event-Driven Utopia
Opportunities and Pitfalls of Event-Driven Utopia
 
Datadog: a Real-Time Metrics Database for One Quadrillion Points/Day
Datadog: a Real-Time Metrics Database for One Quadrillion Points/DayDatadog: a Real-Time Metrics Database for One Quadrillion Points/Day
Datadog: a Real-Time Metrics Database for One Quadrillion Points/Day
 
Are We Really Cloud-Native?
Are We Really Cloud-Native?Are We Really Cloud-Native?
Are We Really Cloud-Native?
 
CockroachDB: Architecture of a Geo-Distributed SQL Database
CockroachDB: Architecture of a Geo-Distributed SQL DatabaseCockroachDB: Architecture of a Geo-Distributed SQL Database
CockroachDB: Architecture of a Geo-Distributed SQL Database
 
A Dive into Streams @LinkedIn with Brooklin
A Dive into Streams @LinkedIn with BrooklinA Dive into Streams @LinkedIn with Brooklin
A Dive into Streams @LinkedIn with Brooklin
 

Último

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 

Último (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

Serverless & GraphQL

  • 2. InfoQ.com: News & Community Site • Over 1,000,000 software developers, architects and CTOs read the site world- wide every month • 250,000 senior developers subscribe to our weekly newsletter • Published in 4 languages (English, Chinese, Japanese and Brazilian Portuguese) • Post content from our QCon conferences • 2 dedicated podcast channels: The InfoQ Podcast, with a focus on Architecture and The Engineering Culture Podcast, with a focus on building • 96 deep dives on innovative topics packed as downloadable emags and minibooks • Over 40 new content items per week Watch the video with slide synchronization on InfoQ.com! https://www.infoq.com/presentations/ serverless-graphql
  • 3. Purpose of QCon - to empower software development by facilitating the spread of knowledge and innovation Strategy - practitioner-driven conference designed for YOU: influencers of change and innovation in your teams - speakers and topics driving the evolution and innovation - connecting and catalyzing the influencers and innovators Highlights - attended by more than 12,000 delegates since 2007 - held in 9 cities worldwide Presented at QCon San Francisco www.qconsf.com
  • 4. Howdy! I’m Jared Short Director of Innovation @ @shortjared
  • 5. GraphQL A query language for your API, and a runtime for executing the queries
  • 6. Why GraphQL ● One endpoint for your API ● Can provide an easy to understand API layer for your aggregated resources ● Only get the data you ask for, in the same shape ● Streamlined API iteration and extensibility ● Fantastic tooling / community
  • 7. Technical Details of GraphQL ● Typed API and schema definitions ● Queries == Read, Mutations == Write ● Execution engine parses query to graph, each node runs through resolvers to fetch data ● Elegantly solves 1+n problem
  • 8. Example Schema type Speaker { firstName: String! lastName: String! talks: [Talk] } type Talk { speakers: [Speaker!] startTime: Int! endTime: Int title: String! room: String! } Understanding the Schema TLDR GraphQL Schema Cheat Sheet ● Explicitly define all types in the graph ● Define lists of types ● Nullable vs non nullable (!) ● Scalars, Unions, Enums, Inputs, etc
  • 9. ● Queries and mutations available at the “root” ● Accept arguments for scalars or input types, return types Query / Mutation Root type QueryRoot { speakers(limit: Int = 10): [Speaker] talks(sort: ASCENDING): [Talk] } input TalkInput { title: String! Speakers: [ID!]! } type MutationRoot { createTalk(talk: TalkInput): Talk } Understanding Root Resolvers
  • 10. type QueryRoot { speakers(limit: Int = 10): [Speaker] talks(sort: ASCENDING): [Talk] } Understanding Root Resolvers QueryRoot: { speakers(root, args, context){ return new SpeakerService(context).loadSpeakers(args.limit); }, talks(root, args, context){ Return new TalkService(context).loadTalks(args.sort); } }
  • 11. type Speaker { firstName: String! lastName: String! talks: [Talk] } Understanding Field Resolvers Speaker: { talks(root, args, context){ Return new TalkService(context).loadByIds(root.talkIds); } }
  • 12. A Thin Wrapper on Business Logic ● GraphQL is NOT your business logic layer ● As thin as possible on top of your business logic ● You can map to multiple data sources ○ Rest API, Database, Filestore, etc
  • 13. Developer Client Experience ● Ask for and receive exactly what you want, how you want it ● Limited API versioning concerns ● Easy to write efficient network requests ● API introspection (GraphiQL)
  • 14. Developer Client Experience ● Ask for and receive exactly what you want, how you want it ● Limited API versioning concerns ● Easy to write efficient network requests ● API introspection (GraphiQL)
  • 16. Serverless? ● Still run on servers, you just don’t care ● Moves your responsibility higher up the stack ● Billing at ms increments (micropayments!) ● Pairs very well with event driven models
  • 17. Why Serverless ● Reduced complexity of scaling ● High availability ● Economics / Total Cost of Ownership ● Rapid iteration, learn fast
  • 18. Developer Hints ● Your Functions as a Service (FaaS) provider should be irrelevant ● Rethink traditional requirements and approaches ● Can it be event driven?
  • 20. ● All the normal serverless wins (scalability, availability, etc) ● All the power of GraphQL for clients and systems ● Smooth out some rough edges of GraphQL ○ Resource Exhaustion Attacks ○ Complex Resolvers Why Serverless GraphQL
  • 21. ● Think DoS attack that’s easy to do by mistake ● Deeply nested request / pagination abuse ● Useful Optimization & Prevention ○ Enforce pagination & limits ○ Maximum depth checking ○ Request Batching & Caching Resource Exhaustion Attacks
  • 23. REA Mitigation (The Easy Way) ● Each graphql execution is allocated its own resources ● Set a reasonable resource allocation & timeout ● Web Application Firewalls to stop bad actors
  • 24. Query Metrics 179 Speakers & 130 Talks No Cache or Batching Requests: 359 Cache Only / Batch Only Requests: 132 / 3 Cache & Batching Requests: 2 Example Query query { speakers { firstName talks { title speakers { firstName } } } } ● Fresh cache for each invocation ● Hard part abstracted away from devs ● DataLoader https://github.com /facebook/dataloader Request Batching & Caching
  • 25. Complex Resolvers & Multi-Data Sources ● Multiple data sources and aggregation made easy ● More expensive queries, split to different lambda
  • 29. Schema Stitching with Links Souce: https://dev-blog.apollodata.com/graphql-schema-stitching-8af23354ac37 REQUEST RESPONSE
  • 30. Schema Stitching So What ● Still a newer concept and area in GraphQL ● Keep thinking in microservices ● Easily extend and add functionality to your services ● Composable services and products ○ Encourage reuse of services ○ Compose services into whole new offerings
  • 32. Don’t be that person...
  • 33. When not to use (force) it ● Non-problem rarely used legacy system ● Big data exports (async returns is fine) ● Internal buy in is key, if inertia is strongly against you, don’t force it, start small ● You can sneakily integrate downstream without forcing them to migrate
  • 34. Protect Downstream Systems ● You are only as strong as your weakest resources ● Serverless scales, your dependencies don’t ● Queues, caching, play nice
  • 35. Back to Basics ● Authorization ● Pagination (relay spec) ● Good documentation
  • 36. Getting Started GraphQL Dan Schafer - GraphQL at Facebook Talk (Pagination & Auth discussed) (via YouTube) Apollo Stack - http://dev.apollodata.com/ GraphQL Schema Cheat Sheet Serverless GraphQL Boilerplate Starter: https://github.com/serverless/serverless-graphql Graphcool Hybrid Faas Framework & GraphQL engine: https://www.graph.cool/ - Open Source with SaaS Offerings
  • 38. Watch the video with slide synchronization on InfoQ.com! https://www.infoq.com/presentations/ serverless-graphql