Build a social network in 4 weeks with Serverless and GraphQL

Yan Cui
Yan CuiSpeaker at Self
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
Build a social network in 4 weeks with Serverless and GraphQL
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
Build a social network in 4 weeks with Serverless and GraphQL
Yan Cui
http://theburningmonk.com
@theburningmonk
AWS user for 10 years
http://bit.ly/yubl-serverless
Yan Cui
http://theburningmonk.com
@theburningmonk
Developer Advocate @
Build a social network in 4 weeks with Serverless and GraphQL
Yan Cui
http://theburningmonk.com
@theburningmonk
Independent Consultant
advisetraining delivery
theburningmonk.com/courses
theburningmonk.com/workshops
in your
company
flexible datesHelsinki, Aug 20-21 London, Sep 24-25 Berlin, Oct 8-9
4-week virtual workshop, May 4 - May 29
Amsterdam, Jul 7-8
@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
https://theburningmonk.com/2020/04/appsync-how-to-error-on-dynamodb-conditional-check-failures
https://theburningmonk.com/2020/04/appsync-skipping-nullable-nested-resolvers
@theburningmonk theburningmonk.com
Why not single-table?
@theburningmonk theburningmonk.com
Why not single-table?
best performance
best cost
best scalability
@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
www.youtube.com/watch?v=6yqfmXiZTlM
@theburningmonk theburningmonk.com
www.dynamodbbook.com
@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
uncertainty: Amplify is evolving quickly
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
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
DynamoDB, S3, etc.
@theburningmonk theburningmonk.com
Cognito User Pool AppSync
DynamoDB
Lambda
S3
Firehose
AthenaAlgolia
CloudFront
S3
Lambda Algolia
@theburningmonk theburningmonk.com
Serverless
framework
DynamoDB, S3, etc.
@theburningmonk theburningmonk.com
Serverless
framework
AppSync API, resolvers,
Lambda functions, etc.
@theburningmonk theburningmonk.com
Serverless
framework
!Ref and !GetAtt works as normal
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
@theburningmonk theburningmonk.com
Step 1
Step 2
npm ci
npm run sls -- deploy
@theburningmonk theburningmonk.com
Step 1
Step 2
npm ci
npm run sls -- deploy
needs AWS credentials
@theburningmonk theburningmonk.com
How to secure CI/CD pipeline?
@theburningmonk theburningmonk.com
Ops Dev Staging Prod
@theburningmonk theburningmonk.com
Ops Dev Staging Prod
ci_user
NO local
permissions
@theburningmonk theburningmonk.com
Ops Dev Staging Prod
ci_user deploy_role deploy_role deploy_role
sts:assumeRole
@theburningmonk theburningmonk.com
Ops Dev Staging Prod
ci_user deploy_role deploy_role deploy_role
Entity Trust Relationship
@theburningmonk theburningmonk.com
Ops Dev Staging Prod
ci_user deploy_role deploy_role deploy_role
permissive - e.g. admin -
roles that are only
assumable by ci_user
@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
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
speed of development
scale to millions of users
minimal up-keep
cost efficient
Build a social network in 4 weeks with Serverless and GraphQL
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
@theburningmonk theburningmonk.com
Production-Ready Serverless
in your
company
flexible datesHelsinki, Aug 20-21 London, Sep 24-25 Berlin, Oct 8-9Amsterdam, Jul 7-8
4-week virtual workshop, May 4 - May 29
@theburningmonk theburningmonk.com
theburningmonk.com/workshops
slsdays-belgium-may2020
€100 off all my workshops
@theburningmonk theburningmonk.com
lambdabestpractice.com bit.ly/complete-guide-to-aws-step-functions
20% off my courses
slsdays-belgium-may2020
@theburningmonk
theburningmonk.com
github.com/theburningmonk
1 of 129

More Related Content

What's hot(20)

Building Secure Services using ContainersBuilding Secure Services using Containers
Building Secure Services using Containers
Amazon Web Services505 views
Aws container webinar day 1Aws container webinar day 1
Aws container webinar day 1
HoseokSeo7167 views
Introduzione ad Amazon EKSIntroduzione ad Amazon EKS
Introduzione ad Amazon EKS
Amazon Web Services750 views
T4 – Understanding aws securityT4 – Understanding aws security
T4 – Understanding aws security
Amazon Web Services1.2K views
DevSecOps: Let's Write Security Unit TestsDevSecOps: Let's Write Security Unit Tests
DevSecOps: Let's Write Security Unit Tests
Puma Security, LLC903 views
Cloud Security: Attacking The Metadata ServiceCloud Security: Attacking The Metadata Service
Cloud Security: Attacking The Metadata Service
Puma Security, LLC1.1K views

Similar to Build a social network in 4 weeks with Serverless and GraphQL(20)

Deploying and Testing MicroservicesDeploying and Testing Microservices
Deploying and Testing Microservices
Thoughtworks5.5K views
Serverless gives you wingsServerless gives you wings
Serverless gives you wings
Yan Cui1.6K views
Scale, baby, scale!Scale, baby, scale!
Scale, baby, scale!
Julien SIMON964 views
DevOps - Moving to DevOps the Amazon WayDevOps - Moving to DevOps the Amazon Way
DevOps - Moving to DevOps the Amazon Way
Amazon Web Services704 views
Born in the Cloud, Built like a StartupBorn in the Cloud, Built like a Startup
Born in the Cloud, Built like a Startup
Amazon Web Services1.1K views
AWS Startup Insights Kuala LumpurAWS Startup Insights Kuala Lumpur
AWS Startup Insights Kuala Lumpur
Amazon Web Services5.1K views

Recently uploaded(20)

Web Dev - 1 PPT.pdfWeb Dev - 1 PPT.pdf
Web Dev - 1 PPT.pdf
gdsczhcet48 views
Java Platform Approach 1.0 - Picnic MeetupJava Platform Approach 1.0 - Picnic Meetup
Java Platform Approach 1.0 - Picnic Meetup
Rick Ossendrijver23 views
The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)
CSUC - Consorci de Serveis Universitaris de Catalunya51 views
CXL at OCPCXL at OCP
CXL at OCP
CXL Forum183 views

Build a social network in 4 weeks with Serverless and GraphQL