Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Build a social network in 4 weeks with Serverless and GraphQL

Serverless technologies drastically simplify the task of building modern, scalable APIs in the cloud, and GraphQL makes it easy for frontend teams to consume these APIs and to iterate quickly on your product idea. Together, they are a perfect combination for a product-focused, full-stack team to deliver customer values quickly.

In this talk, see how we built a new social network mobile app in under 4 weeks using Lambda, AppSync, DynamoDB and Algolia. How we approached CI/CD, testing, authentication and lessons we learnt along the way.

Recording: https://www.youtube.com/watch?v=evsz__BDprs

Real-world serverless podcast: https://realworldserverless.com
Learn Lambda best practices: https://lambdabestpractice.com
Blog: https://theburningmonk.com
Consulting services: https://theburningmonk.com/hire-me
Production-Ready Serverless workshop: https://productionreadyserverless.com

  • Be the first to comment

  • Be the first to like this

Build a social network in 4 weeks with Serverless and GraphQL

  1. 1. Building a social network in under 4 weeks with Serverless and GraphQL
  2. 2. @theburningmonk theburningmonk.com
  3. 3. @theburningmonk theburningmonk.com bootstrapped startup: severe constraints on time & money
  4. 4. speed of development
  5. 5. speed of development scale to millions of users
  6. 6. speed of development scale to millions of users minimal up-keep
  7. 7. speed of development scale to millions of users minimal up-keep cost efficient
  8. 8. @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
  9. 9. @theburningmonk theburningmonk.com S3CloudFront
  10. 10. @theburningmonk theburningmonk.com Cognito User Pool S3CloudFront
  11. 11. @theburningmonk theburningmonk.com Cognito User Pool AppSync S3CloudFront DynamoDB Lambda
  12. 12. @theburningmonk theburningmonk.com Cognito User Pool AppSync DynamoDB Lambda S3CloudFront
  13. 13. @theburningmonk theburningmonk.com Cognito User Pool AppSync DynamoDB Lambda S3 Algolia CloudFront
  14. 14. @theburningmonk theburningmonk.com Cognito User Pool AppSync DynamoDB Lambda S3 AlgoliaCloudFront Lambda Algolia
  15. 15. @theburningmonk theburningmonk.com Cognito User Pool AppSync DynamoDB Lambda S3 Firehose Algolia CloudFront S3 Lambda Algolia
  16. 16. @theburningmonk theburningmonk.com Cognito User Pool AppSync DynamoDB Lambda S3 Firehose AthenaAlgolia CloudFront S3 Lambda Algolia
  17. 17. @theburningmonk theburningmonk.com Cognito User Pool AppSync DynamoDB Lambda S3 Firehose AthenaAlgolia CloudFront S3 Lambda Algolia
  18. 18. @theburningmonk theburningmonk.com AWS Organization productionstagingdevshared root OU OU OU OU
  19. 19. @theburningmonk theburningmonk.com AWS Organization productionstagingdevshared root OU OU OU OU Users Audit Dev Staging Production
  20. 20. @theburningmonk theburningmonk.com AWS Organization productionstagingdevshared root OU OU OU OU Users Audit Dev Staging Production SCPs
  21. 21. @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
  22. 22. Yan Cui http://theburningmonk.com @theburningmonk AWS user for 10 years
  23. 23. http://bit.ly/yubl-serverless
  24. 24. Yan Cui http://theburningmonk.com @theburningmonk Developer Advocate @
  25. 25. Yan Cui http://theburningmonk.com @theburningmonk Independent Consultant advisetraining delivery
  26. 26. theburningmonk.com/courses
  27. 27. 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
  28. 28. @theburningmonk theburningmonk.com What is GraphQL?
  29. 29. @theburningmonk theburningmonk.com schema
  30. 30. @theburningmonk theburningmonk.com schema server
  31. 31. @theburningmonk theburningmonk.com schema server data sources DynamoDB RDS ElasticSearch
  32. 32. @theburningmonk theburningmonk.com What is AppSync?
  33. 33. @theburningmonk theburningmonk.com schema server data sources DynamoDB RDS ElasticSearch AppSync Lambda
  34. 34. @theburningmonk theburningmonk.com AppSync
  35. 35. @theburningmonk theburningmonk.com AppSync Profile
  36. 36. @theburningmonk theburningmonk.com AppSync Profile
  37. 37. @theburningmonk theburningmonk.com AppSync Profile Sport
  38. 38. @theburningmonk theburningmonk.com AppSync Profile Sport paginated!
  39. 39. @theburningmonk theburningmonk.com AppSync Profile Sport paginated! Activities
  40. 40. @theburningmonk theburningmonk.com AppSync Profile Sport paginated! Activities
  41. 41. @theburningmonk theburningmonk.com AppSync Profile Sport paginated! Activities
  42. 42. @theburningmonk theburningmonk.com AppSync Profile Sport paginated! Activities very flexible!
  43. 43. @theburningmonk theburningmonk.com AppSync Profile Sport paginated! Activities very flexible! over-fetching can lead to issues with performance and cost
  44. 44. @theburningmonk theburningmonk.com AppSync Profile Sport paginated! Activities enable caching on specific resolvers
  45. 45. @theburningmonk theburningmonk.com AppSync Profile Sport paginated! Activities PublicProfile !== Profile
  46. 46. @theburningmonk theburningmonk.com
  47. 47. @theburningmonk theburningmonk.com
  48. 48. @theburningmonk theburningmonk.com AWS AppSync scalable & multi-az out of the box
  49. 49. @theburningmonk theburningmonk.com AWS AppSync scalable & multi-az out of the box pay as you use ($4.00 per Million)
  50. 50. @theburningmonk theburningmonk.com AWS AppSync scalable & multi-az out of the box pay as you use ($4.00 per Million) built-in caching (extra $)
  51. 51. @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
  52. 52. @theburningmonk theburningmonk.com
  53. 53. @theburningmonk theburningmonk.com which resolver is the problem?
  54. 54. @theburningmonk theburningmonk.com
  55. 55. @theburningmonk theburningmonk.com
  56. 56. @theburningmonk theburningmonk.com
  57. 57. @theburningmonk theburningmonk.com
  58. 58. @theburningmonk theburningmonk.com
  59. 59. @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
  60. 60. https://theburningmonk.com/2020/04/appsync-how-to-error-on-dynamodb-conditional-check-failures
  61. 61. https://theburningmonk.com/2020/04/appsync-skipping-nullable-nested-resolvers
  62. 62. @theburningmonk theburningmonk.com Why not single-table?
  63. 63. @theburningmonk theburningmonk.com Why not single-table? best performance best cost best scalability
  64. 64. @theburningmonk theburningmonk.com Sometimes, good enough is good enough
  65. 65. @theburningmonk theburningmonk.com Design your system as if it’ll be run by idiots. Because one day it’ll be.
  66. 66. @theburningmonk theburningmonk.com www.youtube.com/watch?v=6yqfmXiZTlM
  67. 67. @theburningmonk theburningmonk.com www.dynamodbbook.com
  68. 68. @theburningmonk theburningmonk.com Cognito User Pool with identity federation amplify-js
  69. 69. @theburningmonk theburningmonk.com Cognito User Pool are configured using CloudFormation NOT Amplify CLI
  70. 70. @theburningmonk theburningmonk.com already have required expertise with AWS and Cognito Why not amplify CLI?
  71. 71. @theburningmonk theburningmonk.com uncertainty: Amplify is evolving quickly Why not amplify CLI?
  72. 72. @theburningmonk theburningmonk.com great for bootstrapping but question marks about how well it copes with changes Why not amplify CLI?
  73. 73. @theburningmonk theburningmonk.com not all the decisions it makes are good decisions, e.g. using DynamoDB scans for list operations Why not amplify CLI?
  74. 74. @theburningmonk theburningmonk.com DynamoDB access pattern is a sensitive topic with potentially huge scalability and cost implications. Why not amplify CLI?
  75. 75. @theburningmonk theburningmonk.com Serverless framework
  76. 76. @theburningmonk theburningmonk.com Serverless framework mature, strong community support
  77. 77. @theburningmonk theburningmonk.com Serverless framework mature, strong community support extensible & customizable through plugins rich ecosystem of community plugins
  78. 78. @theburningmonk theburningmonk.com Serverless framework mature, strong community support extensible & customizable through plugins rich ecosystem of community plugins already familiar with it
  79. 79. @theburningmonk theburningmonk.com Serverless framework one repo one CloudFormation stack one serverless.yml one command to deploy > sls deploy
  80. 80. @theburningmonk theburningmonk.com Serverless framework
  81. 81. @theburningmonk theburningmonk.com Serverless framework
  82. 82. @theburningmonk theburningmonk.com Serverless framework
  83. 83. @theburningmonk theburningmonk.com Serverless framework
  84. 84. @theburningmonk theburningmonk.com Serverless framework
  85. 85. @theburningmonk theburningmonk.com Serverless framework
  86. 86. @theburningmonk theburningmonk.com Serverless framework
  87. 87. @theburningmonk theburningmonk.com
  88. 88. @theburningmonk theburningmonk.com Serverless framework
  89. 89. @theburningmonk theburningmonk.com Serverless framework custom splitting logic FTW!
  90. 90. @theburningmonk theburningmonk.com Serverless framework
  91. 91. @theburningmonk theburningmonk.com Serverless framework DynamoDB, S3, etc.
  92. 92. @theburningmonk theburningmonk.com Cognito User Pool AppSync DynamoDB Lambda S3 Firehose AthenaAlgolia CloudFront S3 Lambda Algolia
  93. 93. @theburningmonk theburningmonk.com Serverless framework DynamoDB, S3, etc.
  94. 94. @theburningmonk theburningmonk.com Serverless framework AppSync API, resolvers, Lambda functions, etc.
  95. 95. @theburningmonk theburningmonk.com Serverless framework !Ref and !GetAtt works as normal
  96. 96. @theburningmonk theburningmonk.com
  97. 97. @theburningmonk theburningmonk.com
  98. 98. @theburningmonk theburningmonk.com Step 1 Step 2 npm ci npm run sls -- deploy
  99. 99. @theburningmonk theburningmonk.com Step 1 Step 2 npm ci npm run sls -- deploy needs AWS credentials
  100. 100. @theburningmonk theburningmonk.com How to secure CI/CD pipeline?
  101. 101. @theburningmonk theburningmonk.com Ops Dev Staging Prod
  102. 102. @theburningmonk theburningmonk.com Ops Dev Staging Prod ci_user NO local permissions
  103. 103. @theburningmonk theburningmonk.com Ops Dev Staging Prod ci_user deploy_role deploy_role deploy_role sts:assumeRole
  104. 104. @theburningmonk theburningmonk.com Ops Dev Staging Prod ci_user deploy_role deploy_role deploy_role Entity Trust Relationship
  105. 105. @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
  106. 106. @theburningmonk theburningmonk.com
  107. 107. 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
  108. 108. test integration with other services (e.g. DynamoDB, Algolia) by executing function locally, but talk to the real DynamoDB & Algolia for Lambda
  109. 109. E2E test - execute user stories against deployed GraphQL endpoints
  110. 110. debugging failed E2E tests is a rehearsal for debugging real production issues
  111. 111. @theburningmonk theburningmonk.com AWS Organization productionstagingdevshared root OU OU OU OU Users Audit Dev Staging Production
  112. 112. @theburningmonk theburningmonk.com org-formation infrastructure-as-code CloudFormation-like YML syntax template landing zones
  113. 113. @theburningmonk theburningmonk.com Serverless framework AppSync org-formation
  114. 114. speed of development scale to millions of users minimal up-keep cost efficient
  115. 115. @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
  116. 116. speed of development scale to millions of users minimal up-keep cost efficient
  117. 117. speed of development scale to millions of users minimal up-keep cost efficient
  118. 118. @theburningmonk theburningmonk.com
  119. 119. speed of development scale to millions of users minimal up-keep cost efficient
  120. 120. speed of development scale to millions of users minimal up-keep cost efficient
  121. 121. 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
  122. 122. @theburningmonk theburningmonk.com Production-Ready Serverless
  123. 123. 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
  124. 124. @theburningmonk theburningmonk.com lambdabestpractice.com bit.ly/complete-guide-to-aws-step-functions 20% off my courses slsdays-belgium-may2020
  125. 125. @theburningmonk theburningmonk.com github.com/theburningmonk

×