Building a social network
in under 4 weeks with
Serverless and
GraphQL
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
bootstrapped startup: severe constraints on time & money
speed of development
speed of development
scale to millions of users
speed of development
scale to millions of users
minimal up-keep
speed of development
scale to millions of users
minimal up-keep
cost efficient
@theburningmonk theburningmonk.com
1 fulltime FE developer (mobile app)
1 fulltime FE developer (CMS)
1 partime BE developer (me)
~7 weeks
~3 weeks
~4 weeks
@theburningmonk theburningmonk.com
S3CloudFront
@theburningmonk theburningmonk.com
Cognito User Pool
S3CloudFront
@theburningmonk theburningmonk.com
Cognito User Pool AppSync
S3CloudFront DynamoDB
Lambda
@theburningmonk theburningmonk.com
Cognito User Pool AppSync
DynamoDB
Lambda
S3CloudFront
@theburningmonk theburningmonk.com
Cognito User Pool AppSync
DynamoDB
Lambda
S3
Algolia
CloudFront
@theburningmonk theburningmonk.com
Cognito User Pool AppSync
DynamoDB
Lambda
S3 AlgoliaCloudFront Lambda
Algolia
@theburningmonk theburningmonk.com
Cognito User Pool AppSync
DynamoDB
Lambda
S3
Firehose
Algolia
CloudFront
S3
Lambda Algolia
@theburningmonk theburningmonk.com
Cognito User Pool AppSync
DynamoDB
Lambda
S3
Firehose
AthenaAlgolia
CloudFront
S3
Lambda Algolia
@theburningmonk theburningmonk.com
Cognito User Pool AppSync
DynamoDB
Lambda
S3
Firehose
AthenaAlgolia
CloudFront
S3
Lambda Algolia
@theburningmonk theburningmonk.com
AWS Organization
productionstagingdevshared
root
OU OU OU OU
@theburningmonk theburningmonk.com
AWS Organization
productionstagingdevshared
root
OU OU OU OU
Users
Audit
Dev Staging Production
@theburningmonk theburningmonk.com
AWS Organization
productionstagingdevshared
root
OU OU OU OU
Users
Audit
Dev Staging Production
SCPs
@theburningmonk theburningmonk.com
1 fulltime FE developer (mobile app)
1 fulltime FE developer (CMS)
1 partime BE developer (me)
~7 weeks
~3 weeks
~4 weeks
Yan Cui
http://theburningmonk.com
@theburningmonk
AWS user for 10 years
http://bit.ly/yubl-serverless
Yan Cui
http://theburningmonk.com
@theburningmonk
Developer Advocate @
Yan Cui
http://theburningmonk.com
@theburningmonk
Independent Consultant
advisetraining delivery
theburningmonk.com/courses
theburningmonk.com/courses
realworldserverless.com
@theburningmonk theburningmonk.com
What is GraphQL?
@theburningmonk theburningmonk.com
schema
@theburningmonk theburningmonk.com
schema server
@theburningmonk theburningmonk.com
schema server data sources
DynamoDB
RDS
ElasticSearch
@theburningmonk theburningmonk.com
What is AppSync?
@theburningmonk theburningmonk.com
schema server data sources
DynamoDB
RDS
ElasticSearch
AppSync
Lambda
@theburningmonk theburningmonk.com
AppSync
@theburningmonk theburningmonk.com
AppSync
Profile
@theburningmonk theburningmonk.com
AppSync
Profile
@theburningmonk theburningmonk.com
AppSync
Profile
Sport
@theburningmonk theburningmonk.com
AppSync
Profile
Sport
paginated!
@theburningmonk theburningmonk.com
AppSync
Profile
Sport
paginated! Activities
@theburningmonk theburningmonk.com
AppSync
Profile
Sport
paginated! Activities
@theburningmonk theburningmonk.com
AppSync
Profile
Sport
paginated! Activities
@theburningmonk theburningmonk.com
AppSync
Profile
Sport
paginated! Activities
very flexible!
@theburningmonk theburningmonk.com
AppSync
Profile
Sport
paginated! Activities
very flexible!
over-fetching can lead to issues
with performance and cost
@theburningmonk theburningmonk.com
AppSync
Profile
Sport
paginated! Activities
enable caching on
specific resolvers
@theburningmonk theburningmonk.com
AppSync
Profile
Sport
paginated! Activities
PublicProfile !== Profile
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
AWS AppSync
scalable & multi-az out of the box
@theburningmonk theburningmonk.com
AWS AppSync
scalable & multi-az out of the box
pay as you use ($4.00 per Million)
@theburningmonk theburningmonk.com
AWS AppSync
scalable & multi-az out of the box
pay as you use ($4.00 per Million)
built-in caching (extra $)
@theburningmonk theburningmonk.com
AWS AppSync
scalable & multi-az out of the box
pay as you use ($4.00 per Million)
built-in caching (extra $)
built-in metrics through CloudWatch
built-in logging through CloudWatch Logs
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
which resolver is
the problem?
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
AWS AppSync
scalable & multi-az out of the box
pay as you use ($4.00 per Million)
built-in caching (extra $)
built-in metrics through CloudWatch
built-in logging through CloudWatch Logs
no servers to manage
@theburningmonk theburningmonk.com
Why not single-table?
@theburningmonk theburningmonk.com
Use single-table design techniques,
but why force yourself to 1 table?
@theburningmonk theburningmonk.com
CloudFormation can only update 1 GSI at a time
@theburningmonk theburningmonk.com
Access pattern changes are painful
@theburningmonk theburningmonk.com
AppSync stitches related DynamoDB reads just fine
@theburningmonk theburningmonk.com
Using single-table === writing more custom VTL
@theburningmonk theburningmonk.com
What about the cost saving?
@theburningmonk theburningmonk.com
Sensible caching will save you far more than
single-table design ever will
@theburningmonk theburningmonk.com
average 99%
cache hit rate
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
Sometimes, good enough is good enough
@theburningmonk theburningmonk.com
Design your system as if it’ll be run by idiots.
Because one day it’ll be.
@theburningmonk theburningmonk.com
Cognito User Pool
with identity federation
amplify-js
@theburningmonk theburningmonk.com
Cognito User Pool are configured using CloudFormation
NOT Amplify CLI
@theburningmonk theburningmonk.com
already have required expertise with AWS and Cognito
Why not amplify CLI?
@theburningmonk theburningmonk.com
great for bootstrapping but question marks
about how well it copes with changes
Why not amplify CLI?
@theburningmonk theburningmonk.com
not all the decisions it makes are good decisions,
e.g. using DynamoDB scans for list operations
Why not amplify CLI?
@theburningmonk theburningmonk.com
DynamoDB access pattern is a sensitive topic with
potentially huge scalability and cost implications.
Why not amplify CLI?
@theburningmonk theburningmonk.com
Hides too much important details.
Why not amplify CLI?
@theburningmonk theburningmonk.com
Cognito User Pool
amplify-js
@theburningmonk theburningmonk.com
creates a university
admin user
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
any logged in user can
perform this operation
@theburningmonk theburningmonk.com
Serverless
framework
@theburningmonk theburningmonk.com
Serverless
framework
mature, strong community support
@theburningmonk theburningmonk.com
Serverless
framework
mature, strong community support
extensible & customizable through plugins
rich ecosystem of community plugins
@theburningmonk theburningmonk.com
Serverless
framework
mature, strong community support
extensible & customizable through plugins
rich ecosystem of community plugins
already familiar with it
@theburningmonk theburningmonk.com
Serverless
framework
one repo
one CloudFormation stack
one serverless.yml
one command to deploy
> sls deploy
@theburningmonk theburningmonk.com
Serverless
framework
@theburningmonk theburningmonk.com
Serverless
framework
@theburningmonk theburningmonk.com
Serverless
framework
@theburningmonk theburningmonk.com
Serverless
framework
@theburningmonk theburningmonk.com
Serverless
framework
@theburningmonk theburningmonk.com
Serverless
framework
@theburningmonk theburningmonk.com
Serverless
framework
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
Serverless
framework
@theburningmonk theburningmonk.com
Serverless
framework
custom splitting logic FTW!
@theburningmonk theburningmonk.com
Serverless
framework
@theburningmonk theburningmonk.com
Serverless
framework
@theburningmonk theburningmonk.com
Serverless
framework
@theburningmonk theburningmonk.com
Serverless
framework
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
Step 1
Step 2
npm ci
npm run sls -- deploy
@theburningmonk theburningmonk.com
not much point with local testing as they’re very
simple and has no dynamic behaviour, once you
figure out the “pattern” they just works
for AppSync resolvers
test integration with other services (e.g. DynamoDB,
Algolia) by executing function locally, but talk to the
real DynamoDB & Algolia
for Lambda
E2E test - execute user stories against
deployed GraphQL endpoints
debugging failed E2E tests is a rehearsal for
debugging real production issues
@theburningmonk theburningmonk.com
AWS Organization
productionstagingdevshared
root
OU OU OU OU
Users
Audit
Dev Staging Production
@theburningmonk theburningmonk.com
org-formation
infrastructure-as-code
CloudFormation-like YML syntax
template landing zones
@theburningmonk theburningmonk.com
org-formation
@theburningmonk theburningmonk.com
org-formation
@theburningmonk theburningmonk.com
org-formation
@theburningmonk theburningmonk.com
org-formation
@theburningmonk theburningmonk.com
org-formation
@theburningmonk theburningmonk.com
org-formation
> org-formation update
@theburningmonk theburningmonk.com
org-formation
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
org-formation
> org-formation perform-tasks
@theburningmonk theburningmonk.com
org-formation
https://github.com/OlafConijn/AwsOrganizationFormation
@theburningmonk theburningmonk.com
Serverless
framework
AppSync org-formation
speed of development
scale to millions of users
minimal up-keep
cost efficient
@theburningmonk theburningmonk.com
1 fulltime FE developer (mobile app)
1 fulltime FE developer (CMS)
1 partime BE developer (me)
~7 weeks
~3 weeks
~4 weeks
speed of development
scale to millions of users
minimal up-keep
cost efficient
speed of development
scale to millions of users
minimal up-keep
cost efficient
@theburningmonk theburningmonk.com
speed of development
scale to millions of users
minimal up-keep
cost efficient
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
speed of development
scale to millions of users
minimal up-keep
cost efficient
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
midnight in Belgium
more Lambda cold starts
https://theburningmonk.com/hire-me
AdviseTraining Delivery
“Fundamentally, Yan has improved our team by increasing our
ability to derive value from AWS and Lambda in particular.”
Nick Blair
Tech Lead
Learn GraphQL and AppSync by building a
Twitter clone with these technologies
appsyncmasterclass.com
@theburningmonk
theburningmonk.com
github.com/theburningmonk

Building a social network in under 4 weeks with Serverless and GraphQL