SlideShare a Scribd company logo
1 of 33
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Heitor Lessa
Specialist Solutions Architect, Amazon Web Services
Building Real-time Serverless Backends
with GraphQL
@heitor_lessa
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Why do we need real-time and offline
capabilities in the first place?
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Brief intro to Serverless
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Build and run
applications
without thinking about
servers
… pay per request not
for idle
“ Scales with usage
Never pay for idle
High availability
built-in
No servers
to provision
or manage
A serverless world…
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Lambda is for all application types
Analytics
Operational management
Live Dashboards
Data workflows
Content management
ETL workflows
Interactive Backends
Mobile and web apps
Webhooks and Bots
Autonomous IT
Policy engines
Infrastructure management
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Building blocks for serverless applications
AWS Lambda
Amazon DynamoDB
Amazon SNS
Amazon API Gateway Amazon SQS Amazon Kinesis
Amazon S3
Orchestration and State Management
API Management and Real-time Backend Messaging and Queues Analytics
Monitoring and Debugging
Compute Storage Database
AWS X-RayAWS Step Functions Amazon Cognito
User Management and IdP
AWS AppSync Amazon Athena
AWS Lambda@Edge
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Building blocks for serverless applications
AWS Lambda
Amazon DynamoDB
Amazon SNS
Amazon API Gateway Amazon SQS Amazon Kinesis
Amazon S3
Orchestration and State Management
API Management and Real-time Backend Messaging and Queues Analytics
Monitoring and Debugging
Compute Storage Database
AWS X-RayAWS Step Functions Amazon Cognito
User Management and IdP
AWS AppSync Amazon Athena
AWS Lambda@Edge
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Has anyone said GraphQL?
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
GraphQL APIs
Open, declarative data-fetching specification
!= Graph database
Use NoSQL, Relational, HTTP, etc.
Traditional data-fetching GraphQL
/posts
/postInfo
/postJustTitle
/postsByAuthor
/postNameStartsWithX
/commentsOnPost
/posts
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
GraphQL Spec - Schema
{
"id": "1",
"name": "Get Milk",
“priority": "1"
},
{
"id": “2",
"name": “Go to gym",
“priority": “5"
},…
type Query {
getTodos: [Todo]
}
type Todo {
id: ID!
name: String
description: String
priority: Int
duedate: String
}
query {
getTodos {
id
name
priority
}
}
Model data with
application schema
Client requests what it
needs
Only that data is
returned
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
GraphQL Spec - Types
Schema
type Event {
id: ID!
name: String
where: String
when: String
description: String
comments: [Comment]
}
type Comment {
commentId: String!
eventId: ID!
content: String!
createdAt: String!
}
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
GraphQL Spec - Mutation
Schema
Mutation
type Mutation {
createEvent(
name: String!,
when: String!,
where: String!,
description: String!
): Event
deleteEvent(id: ID!): Event
commentOnEvent(
eventId: ID!,
content: String!,
createdAt: String!
): Comment
}
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
GraphQL Spec - Query
Schema
Mutation
Query
type Query {
getEvent(id: ID!): Event
listEvents(
limit: Int,
nextToken: String
): EventConnection
}
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
GraphQL Spec - Subscription
Schema
Mutation
Query
Subscription type Subscription {
onComments(eventId: String!): Comment
@aws_subscribe(mutations: ["commentOnEvent"])
}
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
GraphQL Spec - Subscription
Schema
Mutation
Query
Subscription type Subscription {
onComments(eventId: String!): Comment
@aws_subscribe(mutations: ["commentOnEvent"])
}
type Mutation {
…
commentOnEvent(
eventId: ID!,
content: String!,
createdAt: String!
): Comment
}
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
GraphQL - Summary
Schema
Mutation
Query
Subscription
Realtime? YES
Batching? YES
Pagination? YES
Relations? YES
Aggregations? YES
Search? YES
Offline? YES
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS AppSync – Intro
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
What is AWS AppSync?
AWS AppSync is a managed service for
application data using GraphQL with real-time
capabilities and an offline programming model.
Real-time
Collaboration
Offline Programming
Model with Sync
Flexible Database
Options
Fine-grained
Access Control
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
How does AWS AppSync work?
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS AppSync and GraphQL Subscription
Near Realtime updates of data
Event based mode, triggered by Mutations
- Scalable model, designed as a platform for common use-cases
Can be used with ANY data source in AppSync
- Lambda, DynamoDB, Elasticsearch
mutation addPost(
id: 123
title: ”New post!”
author: ”Nadia”)
{
id
title
author
}
data: [{
id: 123,
title: ”New Post!”
author: ”Nadia”
}]
MQTT over Websockets
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS AppSync – Data Sources, Auth and more
DynamoDB
Table
Lambda
Function Elasticsearch
Service
GraphQL
Schema
Upload
Schema
GraphQL
Query
Mutation
Subscription
Real-time
Offline
AppSync
API
Cognito
User Pool
Legacy
Application
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
How does AppSync connect to my data sources?
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS AppSync – Debug Resolver Flow
Amazon CloudWatch logs
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
What about Offline access?
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Offline patterns – Application Considerations
• Local Storage (R/W)
• Order of Operations
• Network State Management
• UI Updates
• Conflict Resolution
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AppSync – Debug Resolver Flow
Jane
Version : 2 Updated Document
Jane
Version : 2 Updated Document
Version : 3 Updated Document
Version : 1 New Document
Time
John
John
Jane goes offline
Jane comes back online
Version : 4 Updated Document
John
Jane
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS AppSync – Conflict Resolution
Conflict resolution in the cloud
1. Server wins
2. Silent reject
3. Custom logic (AWS Lambda)
- Optimistic version check
- Extend with your own checks
Optional
• Client callback for Conflict Resolution is
still available as a fallback
{
"version" : "2017-02-28",
"operation" : "PutItem",
"key" : {
"id" : { "S" : "1" }
},
"condition" : {
"expression" : "attribute_not_exists(id)"
}
}
Example: Check that an ID doesn’t already exist:
"condition" : {
"expression" : "someExpression"
"conditionalCheckFailedHandler" : {
"strategy" : "Custom",
"lambdaArn" : "arn:..."
}
}
Run Lambda if version wrong:
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Offline best practices
• Mutations offline – what UIs actually need to be optimistic?
• Use Subscriptions appropriately
• Large payloads/paginated data: Queries
• Frequent updating deltas: Subscriptions
• Be kind to your customer’s battery & CPU!
• Don’t overcomplicate Conflict Resolution
• Data model appropriately, many app actions simply append to a list
• For custom cases, use a AWS Lambda and keep client logic light (race
conditions)
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Resources
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Additional Resources
aws.amazon.com/appsync/resources
aws-samples/
aws-mobile-appsync-chat-starter-angular
awslabs/
aws-appsync-codegen
dabit3/
vue-graphql-appsync
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Demo
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Please complete the session survey in the
summit mobile app

More Related Content

What's hot

What's hot (20)

Amazon CI-CD Practices for Software Development Teams
Amazon CI-CD Practices for Software Development Teams Amazon CI-CD Practices for Software Development Teams
Amazon CI-CD Practices for Software Development Teams
 
AWS Systems Manage: Bridging Operational Models
AWS Systems Manage: Bridging Operational Models AWS Systems Manage: Bridging Operational Models
AWS Systems Manage: Bridging Operational Models
 
The Future of Enterprise Applications is Serverless (ENT314-R1) - AWS re:Inve...
The Future of Enterprise Applications is Serverless (ENT314-R1) - AWS re:Inve...The Future of Enterprise Applications is Serverless (ENT314-R1) - AWS re:Inve...
The Future of Enterprise Applications is Serverless (ENT314-R1) - AWS re:Inve...
 
Building Real-time Serverless Backends with GraphQL
Building Real-time Serverless Backends with GraphQLBuilding Real-time Serverless Backends with GraphQL
Building Real-time Serverless Backends with GraphQL
 
Serverless:It All Started in Vegas (DVC306) - AWS re:Invent 2018
Serverless:It All Started in Vegas (DVC306) - AWS re:Invent 2018Serverless:It All Started in Vegas (DVC306) - AWS re:Invent 2018
Serverless:It All Started in Vegas (DVC306) - AWS re:Invent 2018
 
Build Enterprise-Grade Serverless Apps
Build Enterprise-Grade Serverless Apps Build Enterprise-Grade Serverless Apps
Build Enterprise-Grade Serverless Apps
 
SRV316 Serverless Data Processing at Scale: An Amazon.com Case Study
 SRV316 Serverless Data Processing at Scale: An Amazon.com Case Study SRV316 Serverless Data Processing at Scale: An Amazon.com Case Study
SRV316 Serverless Data Processing at Scale: An Amazon.com Case Study
 
Building Customer-Centric Contact Centers in Financial Services
Building Customer-Centric Contact Centers in Financial Services Building Customer-Centric Contact Centers in Financial Services
Building Customer-Centric Contact Centers in Financial Services
 
Leadership Session: Learn about 10 Years' of Windows and .NET Innovation on A...
Leadership Session: Learn about 10 Years' of Windows and .NET Innovation on A...Leadership Session: Learn about 10 Years' of Windows and .NET Innovation on A...
Leadership Session: Learn about 10 Years' of Windows and .NET Innovation on A...
 
Secure your AWS Account and your Organization's Accounts
Secure your AWS Account and your Organization's Accounts Secure your AWS Account and your Organization's Accounts
Secure your AWS Account and your Organization's Accounts
 
Build a Game for Echo Buttons - an Alexa Gadget! (ALX405-R2) - AWS re:Invent ...
Build a Game for Echo Buttons - an Alexa Gadget! (ALX405-R2) - AWS re:Invent ...Build a Game for Echo Buttons - an Alexa Gadget! (ALX405-R2) - AWS re:Invent ...
Build a Game for Echo Buttons - an Alexa Gadget! (ALX405-R2) - AWS re:Invent ...
 
Serverless Architectural Patterns I AWS Dev Day 2018
Serverless Architectural Patterns I AWS Dev Day 2018Serverless Architectural Patterns I AWS Dev Day 2018
Serverless Architectural Patterns I AWS Dev Day 2018
 
Serverless State Management & Orchestration for Modern Apps (API302) - AWS re...
Serverless State Management & Orchestration for Modern Apps (API302) - AWS re...Serverless State Management & Orchestration for Modern Apps (API302) - AWS re...
Serverless State Management & Orchestration for Modern Apps (API302) - AWS re...
 
BDA310 Transcribe and Translate
BDA310 Transcribe and TranslateBDA310 Transcribe and Translate
BDA310 Transcribe and Translate
 
DEM04 Fearless: From Monolith to Serverless with Dynatrace
DEM04 Fearless: From Monolith to Serverless with DynatraceDEM04 Fearless: From Monolith to Serverless with Dynatrace
DEM04 Fearless: From Monolith to Serverless with Dynatrace
 
Build a Searchable Media Library & Moderate Content at Scale Using Machine Le...
Build a Searchable Media Library & Moderate Content at Scale Using Machine Le...Build a Searchable Media Library & Moderate Content at Scale Using Machine Le...
Build a Searchable Media Library & Moderate Content at Scale Using Machine Le...
 
Deconstructing SaaS: Deep Dive into Building Multi-Tenant Solutions on AWS (A...
Deconstructing SaaS: Deep Dive into Building Multi-Tenant Solutions on AWS (A...Deconstructing SaaS: Deep Dive into Building Multi-Tenant Solutions on AWS (A...
Deconstructing SaaS: Deep Dive into Building Multi-Tenant Solutions on AWS (A...
 
Serverless Developer Experience I AWS Dev Day 2018
Serverless Developer Experience I AWS Dev Day 2018Serverless Developer Experience I AWS Dev Day 2018
Serverless Developer Experience I AWS Dev Day 2018
 
Enterprise DevOps: Patterns of Efficiency (ENT311-R1) - AWS re:Invent 2018
Enterprise DevOps: Patterns of Efficiency (ENT311-R1) - AWS re:Invent 2018Enterprise DevOps: Patterns of Efficiency (ENT311-R1) - AWS re:Invent 2018
Enterprise DevOps: Patterns of Efficiency (ENT311-R1) - AWS re:Invent 2018
 
How AQR Capital Uses AWS to Research New Investment Signals
How AQR Capital Uses AWS to Research New Investment Signals How AQR Capital Uses AWS to Research New Investment Signals
How AQR Capital Uses AWS to Research New Investment Signals
 

Similar to Building Real-time Serverless Backends

Similar to Building Real-time Serverless Backends (20)

Build a Serverless Application using GraphQL & AWS AppSync
Build a Serverless Application using GraphQL & AWS AppSyncBuild a Serverless Application using GraphQL & AWS AppSync
Build a Serverless Application using GraphQL & AWS AppSync
 
Introduction to GraphQL and AWS Appsync on AWS - iOS
Introduction to GraphQL and AWS Appsync on AWS - iOSIntroduction to GraphQL and AWS Appsync on AWS - iOS
Introduction to GraphQL and AWS Appsync on AWS - iOS
 
AppSync and GraphQL on iOS
AppSync and GraphQL on iOSAppSync and GraphQL on iOS
AppSync and GraphQL on iOS
 
Taking your Progressive Web App to the Next Level - AWS Summit Sydney 2018
Taking your Progressive Web App to the Next Level - AWS Summit Sydney 2018Taking your Progressive Web App to the Next Level - AWS Summit Sydney 2018
Taking your Progressive Web App to the Next Level - AWS Summit Sydney 2018
 
善用 GraphQL 與 AWS AppSync 讓您的 Progressive Web App (PWA) 加速進化 (Level 200)
善用  GraphQL 與 AWS AppSync 讓您的  Progressive Web App (PWA) 加速進化 (Level 200)善用  GraphQL 與 AWS AppSync 讓您的  Progressive Web App (PWA) 加速進化 (Level 200)
善用 GraphQL 與 AWS AppSync 讓您的 Progressive Web App (PWA) 加速進化 (Level 200)
 
Taking your Progressive Web App to the Next Level with GraphQL and AWS AppSync
Taking your Progressive Web App to the Next Level with GraphQL and AWS AppSyncTaking your Progressive Web App to the Next Level with GraphQL and AWS AppSync
Taking your Progressive Web App to the Next Level with GraphQL and AWS AppSync
 
Supercharging Applications with GraphQL and AWS AppSync
Supercharging Applications with GraphQL and AWS AppSyncSupercharging Applications with GraphQL and AWS AppSync
Supercharging Applications with GraphQL and AWS AppSync
 
Eliminate Migration Confusion: Speed Migration with Automated Tracking (ENT31...
Eliminate Migration Confusion: Speed Migration with Automated Tracking (ENT31...Eliminate Migration Confusion: Speed Migration with Automated Tracking (ENT31...
Eliminate Migration Confusion: Speed Migration with Automated Tracking (ENT31...
 
Introduzione a GraphQL
Introduzione a GraphQLIntroduzione a GraphQL
Introduzione a GraphQL
 
Take Mobile and Web Apps to the Next Level with AWS AppSync and AWS Amplify
Take Mobile and Web Apps to the Next Level with AWS AppSync and AWS Amplify Take Mobile and Web Apps to the Next Level with AWS AppSync and AWS Amplify
Take Mobile and Web Apps to the Next Level with AWS AppSync and AWS Amplify
 
Modern Applications Web Day | Impress Your Friends with Your First Serverless...
Modern Applications Web Day | Impress Your Friends with Your First Serverless...Modern Applications Web Day | Impress Your Friends with Your First Serverless...
Modern Applications Web Day | Impress Your Friends with Your First Serverless...
 
Authentication & Authorization in GraphQL with AWS AppSync (MOB402) - AWS re:...
Authentication & Authorization in GraphQL with AWS AppSync (MOB402) - AWS re:...Authentication & Authorization in GraphQL with AWS AppSync (MOB402) - AWS re:...
Authentication & Authorization in GraphQL with AWS AppSync (MOB402) - AWS re:...
 
Building mobile apps that can automatically scale globally to millions of use...
Building mobile apps that can automatically scale globally to millions of use...Building mobile apps that can automatically scale globally to millions of use...
Building mobile apps that can automatically scale globally to millions of use...
 
Driving Innovation with Serverless Applications (GPSBUS212) - AWS re:Invent 2018
Driving Innovation with Serverless Applications (GPSBUS212) - AWS re:Invent 2018Driving Innovation with Serverless Applications (GPSBUS212) - AWS re:Invent 2018
Driving Innovation with Serverless Applications (GPSBUS212) - AWS re:Invent 2018
 
Developing Serverless Application on AWS
Developing Serverless Application on AWSDeveloping Serverless Application on AWS
Developing Serverless Application on AWS
 
Building Serverless Applications with Amazon DynamoDB & AWS Lambda - Workshop...
Building Serverless Applications with Amazon DynamoDB & AWS Lambda - Workshop...Building Serverless Applications with Amazon DynamoDB & AWS Lambda - Workshop...
Building Serverless Applications with Amazon DynamoDB & AWS Lambda - Workshop...
 
Ten Tips And Tricks for Improving Your GraphQL API with AWS AppSync (MOB401) ...
Ten Tips And Tricks for Improving Your GraphQL API with AWS AppSync (MOB401) ...Ten Tips And Tricks for Improving Your GraphQL API with AWS AppSync (MOB401) ...
Ten Tips And Tricks for Improving Your GraphQL API with AWS AppSync (MOB401) ...
 
Building Serverless Enterprise Applications - SRV315 - Anaheim AWS Summit
Building Serverless Enterprise Applications - SRV315 - Anaheim AWS SummitBuilding Serverless Enterprise Applications - SRV315 - Anaheim AWS Summit
Building Serverless Enterprise Applications - SRV315 - Anaheim AWS Summit
 
Building your first GraphQL API with AWS AppSync
Building your first GraphQL API with AWS AppSyncBuilding your first GraphQL API with AWS AppSync
Building your first GraphQL API with AWS AppSync
 
Building your First GraphQL API with AWS AppSync
Building your First GraphQL API with AWS AppSyncBuilding your First GraphQL API with AWS AppSync
Building your First GraphQL API with AWS AppSync
 

More from Amazon Web Services

Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
Amazon Web Services
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
Amazon Web Services
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
Amazon Web Services
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
Amazon Web Services
 

More from Amazon Web Services (20)

Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
 
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
 
Esegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS FargateEsegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS Fargate
 
Costruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSCostruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWS
 
Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot
 
Open banking as a service
Open banking as a serviceOpen banking as a service
Open banking as a service
 
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
 
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
 
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows WorkloadsMicrosoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
 
Computer Vision con AWS
Computer Vision con AWSComputer Vision con AWS
Computer Vision con AWS
 
Database Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatareDatabase Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatare
 
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJSCrea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
 
API moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e webAPI moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e web
 
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatareDatabase Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
 
Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
 
Fundraising Essentials
Fundraising EssentialsFundraising Essentials
Fundraising Essentials
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
 
Introduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceIntroduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container Service
 

Building Real-time Serverless Backends

  • 1. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Heitor Lessa Specialist Solutions Architect, Amazon Web Services Building Real-time Serverless Backends with GraphQL @heitor_lessa
  • 2. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Why do we need real-time and offline capabilities in the first place?
  • 3. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Brief intro to Serverless
  • 4. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  • 5. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Build and run applications without thinking about servers … pay per request not for idle “ Scales with usage Never pay for idle High availability built-in No servers to provision or manage A serverless world…
  • 6. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Lambda is for all application types Analytics Operational management Live Dashboards Data workflows Content management ETL workflows Interactive Backends Mobile and web apps Webhooks and Bots Autonomous IT Policy engines Infrastructure management
  • 7. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Building blocks for serverless applications AWS Lambda Amazon DynamoDB Amazon SNS Amazon API Gateway Amazon SQS Amazon Kinesis Amazon S3 Orchestration and State Management API Management and Real-time Backend Messaging and Queues Analytics Monitoring and Debugging Compute Storage Database AWS X-RayAWS Step Functions Amazon Cognito User Management and IdP AWS AppSync Amazon Athena AWS Lambda@Edge
  • 8. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Building blocks for serverless applications AWS Lambda Amazon DynamoDB Amazon SNS Amazon API Gateway Amazon SQS Amazon Kinesis Amazon S3 Orchestration and State Management API Management and Real-time Backend Messaging and Queues Analytics Monitoring and Debugging Compute Storage Database AWS X-RayAWS Step Functions Amazon Cognito User Management and IdP AWS AppSync Amazon Athena AWS Lambda@Edge
  • 9. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Has anyone said GraphQL?
  • 10. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. GraphQL APIs Open, declarative data-fetching specification != Graph database Use NoSQL, Relational, HTTP, etc. Traditional data-fetching GraphQL /posts /postInfo /postJustTitle /postsByAuthor /postNameStartsWithX /commentsOnPost /posts
  • 11. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. GraphQL Spec - Schema { "id": "1", "name": "Get Milk", “priority": "1" }, { "id": “2", "name": “Go to gym", “priority": “5" },… type Query { getTodos: [Todo] } type Todo { id: ID! name: String description: String priority: Int duedate: String } query { getTodos { id name priority } } Model data with application schema Client requests what it needs Only that data is returned
  • 12. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. GraphQL Spec - Types Schema type Event { id: ID! name: String where: String when: String description: String comments: [Comment] } type Comment { commentId: String! eventId: ID! content: String! createdAt: String! }
  • 13. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. GraphQL Spec - Mutation Schema Mutation type Mutation { createEvent( name: String!, when: String!, where: String!, description: String! ): Event deleteEvent(id: ID!): Event commentOnEvent( eventId: ID!, content: String!, createdAt: String! ): Comment }
  • 14. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. GraphQL Spec - Query Schema Mutation Query type Query { getEvent(id: ID!): Event listEvents( limit: Int, nextToken: String ): EventConnection }
  • 15. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. GraphQL Spec - Subscription Schema Mutation Query Subscription type Subscription { onComments(eventId: String!): Comment @aws_subscribe(mutations: ["commentOnEvent"]) }
  • 16. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. GraphQL Spec - Subscription Schema Mutation Query Subscription type Subscription { onComments(eventId: String!): Comment @aws_subscribe(mutations: ["commentOnEvent"]) } type Mutation { … commentOnEvent( eventId: ID!, content: String!, createdAt: String! ): Comment }
  • 17. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. GraphQL - Summary Schema Mutation Query Subscription Realtime? YES Batching? YES Pagination? YES Relations? YES Aggregations? YES Search? YES Offline? YES
  • 18. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS AppSync – Intro
  • 19. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. What is AWS AppSync? AWS AppSync is a managed service for application data using GraphQL with real-time capabilities and an offline programming model. Real-time Collaboration Offline Programming Model with Sync Flexible Database Options Fine-grained Access Control
  • 20. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. How does AWS AppSync work?
  • 21. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS AppSync and GraphQL Subscription Near Realtime updates of data Event based mode, triggered by Mutations - Scalable model, designed as a platform for common use-cases Can be used with ANY data source in AppSync - Lambda, DynamoDB, Elasticsearch mutation addPost( id: 123 title: ”New post!” author: ”Nadia”) { id title author } data: [{ id: 123, title: ”New Post!” author: ”Nadia” }] MQTT over Websockets
  • 22. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS AppSync – Data Sources, Auth and more DynamoDB Table Lambda Function Elasticsearch Service GraphQL Schema Upload Schema GraphQL Query Mutation Subscription Real-time Offline AppSync API Cognito User Pool Legacy Application
  • 23. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. How does AppSync connect to my data sources?
  • 24. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS AppSync – Debug Resolver Flow Amazon CloudWatch logs
  • 25. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. What about Offline access?
  • 26. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Offline patterns – Application Considerations • Local Storage (R/W) • Order of Operations • Network State Management • UI Updates • Conflict Resolution
  • 27. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AppSync – Debug Resolver Flow Jane Version : 2 Updated Document Jane Version : 2 Updated Document Version : 3 Updated Document Version : 1 New Document Time John John Jane goes offline Jane comes back online Version : 4 Updated Document John Jane
  • 28. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS AppSync – Conflict Resolution Conflict resolution in the cloud 1. Server wins 2. Silent reject 3. Custom logic (AWS Lambda) - Optimistic version check - Extend with your own checks Optional • Client callback for Conflict Resolution is still available as a fallback { "version" : "2017-02-28", "operation" : "PutItem", "key" : { "id" : { "S" : "1" } }, "condition" : { "expression" : "attribute_not_exists(id)" } } Example: Check that an ID doesn’t already exist: "condition" : { "expression" : "someExpression" "conditionalCheckFailedHandler" : { "strategy" : "Custom", "lambdaArn" : "arn:..." } } Run Lambda if version wrong:
  • 29. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Offline best practices • Mutations offline – what UIs actually need to be optimistic? • Use Subscriptions appropriately • Large payloads/paginated data: Queries • Frequent updating deltas: Subscriptions • Be kind to your customer’s battery & CPU! • Don’t overcomplicate Conflict Resolution • Data model appropriately, many app actions simply append to a list • For custom cases, use a AWS Lambda and keep client logic light (race conditions)
  • 30. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Resources
  • 31. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Additional Resources aws.amazon.com/appsync/resources aws-samples/ aws-mobile-appsync-chat-starter-angular awslabs/ aws-appsync-codegen dabit3/ vue-graphql-appsync
  • 32. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Demo
  • 33. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Please complete the session survey in the summit mobile app