This document discusses AWS AppSync, a managed service for building real-time and offline data apps using GraphQL. It addresses challenges like varying device data needs, offline usage, and building scalable data apps. AppSync provides real-time data collaboration, an offline programming model with automatic syncing, and security features. Example use cases include dashboards, games, and chat apps. GraphQL is introduced as an alternative to traditional REST APIs that allows clients to request specific data fields. Pricing examples are provided to illustrate AppSync's cost structure.
Build Data Driven Apps with Real-time and Offline Capabilities
1. Build Data Driven Apps with Real-time and
Offline Capabilities
Pahud Hsieh(謝洪恩)
Solutions Architect
Level 200
2. Agenda
• Overview
• What challenges does AppSync address?
• Use cases
• GraphQL
• Details
• Pricing
3. What is AWS AppSync?
• Managed service for application data using GraphQL with
real-time capabilities and an offline programming model
- Connect to resources in your account
- Make your data services in real time or offline
- Use AWS services with GraphQL
- Automatic sync, conflict resolution in the cloud
- Enterprise-level security features
4. • Build real-time, collaborative
mobile and web apps
• Handles offline scenarios
common to mobile apps
• Automatically resolves data
conflicts
• Helps keep data secure
• Quickly prototype and build apps
from multiple data sources
• Fully-managed GraphQL service
with benefits
AWS AppSync (available in public preview at re:Invent 2017)
Customers can request access at https://aws.amazon.com/appsync/
6. Developer Challenges With App Data
Data requirements
vary across devices
and become harder
when multiple users
share data
Users want instant
access to data
Building scalable
data-driven apps
without learning
distributed systems
concepts is hard
Users want to
continue using their
apps even with low
or no connectivity
7. Build Powerful Data Driven Apps
With AppSync
Real-time
Collaboration
Offline
Programming
Model with
Sync
Get Only the
Data You Need
Own Your Data Fine-grained
Access Control
8. Apps You Can Build With AppSync
Real-time Apps
- Dashboard
- Leaderboard
- Field service apps
Chat Apps Apps with Complex
Data Structures
and Types
Geo Apps
11. I have a web and mobile app, and a
data source
Data
API Gateway Lambda
Using API Gateway and Lambda is one
approach for performing DB operations
12. What is GraphQL?
• Open, declarative data-fetching specification
• != Graph database
• Use NoSQL, Relational, HTTP, etc.
Traditional data-fetching GraphQL
/posts
/postInfo
/postJustTitle
/postsByAuthor
/postNameStartsWithX
/commentsOnPost
13. How does GraphQL work?
{
"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
14. What are the GraphQL benefits?
• Rapid prototyping and iteration
• Introspection
• Co-location of data requirements & application views
- Implementations aren’t encoded in the server
• Data behavior control
- Batching, request/response and real-time
• Bandwidth optimization (N+1 problem)
15. Can you do … with GraphQL?
• Realtime? YES
• Batching? YES
• Pagination? YES
• Relations? YES
• Aggregations? YES
• Search? YES
• Offline? YES
17. GraphQL Subscriptions
• 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”
}]
18. Client experience and configuration
• Offline is a write-through “Store”
- Persistent storage mediums back the client “normalized
cache”
- Local Storage for web
- SQLite on hybrid/native platforms
• SQLite database can be preloaded
- Hydrate after installing from AppStore
• Offline client can be configured
- Wifi only vs. wifi & carrier
• Queries automatically persist offline
• Mutations are an “optimistic write”
- Control offline UI updates with “optimistic response”
- Update views/lists when editing/adding data offline
19. Offline mutations
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
20. Conflict Resolution and synchronization
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:
22. Service Cost per month
• Free Tier lasts for first 12 months
• Don’t forget to add Data Transfer + Database
• Always review the AWS Pricing Page for latest pricing
Free Tier Standard Cost
Queries 250,000 $4 / million
Real-time Updates 250,000 $2 / million
Real-time Connection-minutes 600,000 $0.08 / million
* US Pricing, as of December 1, 2017
23. Pricing Example (all numbers per month)
• Chat application with 2,500 users
• Average user connects for 1,500 minutes
• Sends 1,000 and Receives 1,000 messages
• 2.5M queries and 2.5M real-time updates
AppSync Query 2.5M x $4/million = $10.00
AppSync Real-time 2.5M x $2/million = $5.00
AppSync Minutes 2,500 x 1,500 x $0.08/million = $0.30
Data Transfer 1KB x 2.5M = 2.4GB x $0.09 = $0.21
DynamoDB Database Free Tier (as long as store < 25Gb)
Total $15.51