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

190 views

Published on

Recording of this talk is available at https://www.youtube.com/watch?v=pUmjxLKqhK4

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.

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

Published in: Technology
  • 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/courses
  28. 28. realworldserverless.com
  29. 29. @theburningmonk theburningmonk.com What is GraphQL?
  30. 30. @theburningmonk theburningmonk.com schema
  31. 31. @theburningmonk theburningmonk.com schema server
  32. 32. @theburningmonk theburningmonk.com schema server data sources DynamoDB RDS ElasticSearch
  33. 33. @theburningmonk theburningmonk.com What is AppSync?
  34. 34. @theburningmonk theburningmonk.com schema server data sources DynamoDB RDS ElasticSearch AppSync Lambda
  35. 35. @theburningmonk theburningmonk.com AppSync
  36. 36. @theburningmonk theburningmonk.com AppSync Profile
  37. 37. @theburningmonk theburningmonk.com AppSync Profile
  38. 38. @theburningmonk theburningmonk.com AppSync Profile Sport
  39. 39. @theburningmonk theburningmonk.com AppSync Profile Sport paginated!
  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
  43. 43. @theburningmonk theburningmonk.com AppSync Profile Sport paginated! Activities very flexible!
  44. 44. @theburningmonk theburningmonk.com AppSync Profile Sport paginated! Activities very flexible! over-fetching can lead to issues with performance and cost
  45. 45. @theburningmonk theburningmonk.com AppSync Profile Sport paginated! Activities enable caching on specific resolvers
  46. 46. @theburningmonk theburningmonk.com AppSync Profile Sport paginated! Activities PublicProfile !== Profile
  47. 47. @theburningmonk theburningmonk.com
  48. 48. @theburningmonk theburningmonk.com
  49. 49. @theburningmonk theburningmonk.com AWS AppSync scalable & multi-az out of the box
  50. 50. @theburningmonk theburningmonk.com AWS AppSync scalable & multi-az out of the box pay as you use ($4.00 per Million)
  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 $)
  52. 52. @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
  53. 53. @theburningmonk theburningmonk.com
  54. 54. @theburningmonk theburningmonk.com which resolver is the problem?
  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
  60. 60. @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
  61. 61. https://theburningmonk.com/2020/04/appsync-how-to-error-on-dynamodb-conditional-check-failures
  62. 62. https://theburningmonk.com/2020/04/appsync-skipping-nullable-nested-resolvers
  63. 63. @theburningmonk theburningmonk.com Why not single-table?
  64. 64. @theburningmonk theburningmonk.com Why not single-table? best performance best cost best scalability
  65. 65. @theburningmonk theburningmonk.com Sometimes, good enough is good enough
  66. 66. @theburningmonk theburningmonk.com Design your system as if it’ll be run by idiots. Because one day it’ll be.
  67. 67. @theburningmonk theburningmonk.com www.youtube.com/watch?v=6yqfmXiZTlM
  68. 68. @theburningmonk theburningmonk.com www.dynamodbbook.com
  69. 69. @theburningmonk theburningmonk.com Cognito User Pool with identity federation amplify-js
  70. 70. @theburningmonk theburningmonk.com Cognito User Pool are configured using CloudFormation NOT Amplify CLI
  71. 71. @theburningmonk theburningmonk.com already have required expertise with AWS and Cognito Why not amplify CLI?
  72. 72. @theburningmonk theburningmonk.com uncertainty: Amplify is evolving quickly Why not amplify CLI?
  73. 73. @theburningmonk theburningmonk.com great for bootstrapping but question marks about how well it copes with changes Why not amplify CLI?
  74. 74. @theburningmonk theburningmonk.com not all the decisions it makes are good decisions, e.g. using DynamoDB scans for list operations Why not amplify CLI?
  75. 75. @theburningmonk theburningmonk.com DynamoDB access pattern is a sensitive topic with potentially huge scalability and cost implications. Why not amplify CLI?
  76. 76. @theburningmonk theburningmonk.com Cognito User Pool amplify-js
  77. 77. @theburningmonk theburningmonk.com creates a university admin user
  78. 78. @theburningmonk theburningmonk.com
  79. 79. @theburningmonk theburningmonk.com
  80. 80. @theburningmonk theburningmonk.com
  81. 81. @theburningmonk theburningmonk.com
  82. 82. @theburningmonk theburningmonk.com
  83. 83. @theburningmonk theburningmonk.com
  84. 84. @theburningmonk theburningmonk.com
  85. 85. @theburningmonk theburningmonk.com
  86. 86. @theburningmonk theburningmonk.com any logged in user can perform this operation
  87. 87. @theburningmonk theburningmonk.com Serverless framework
  88. 88. @theburningmonk theburningmonk.com Serverless framework mature, strong community support
  89. 89. @theburningmonk theburningmonk.com Serverless framework mature, strong community support extensible & customizable through plugins rich ecosystem of community plugins
  90. 90. @theburningmonk theburningmonk.com Serverless framework mature, strong community support extensible & customizable through plugins rich ecosystem of community plugins already familiar with it
  91. 91. @theburningmonk theburningmonk.com Serverless framework one repo one CloudFormation stack one serverless.yml one command to deploy > sls deploy
  92. 92. @theburningmonk theburningmonk.com Serverless framework
  93. 93. @theburningmonk theburningmonk.com Serverless framework
  94. 94. @theburningmonk theburningmonk.com Serverless framework
  95. 95. @theburningmonk theburningmonk.com Serverless framework
  96. 96. @theburningmonk theburningmonk.com Serverless framework
  97. 97. @theburningmonk theburningmonk.com Serverless framework
  98. 98. @theburningmonk theburningmonk.com Serverless framework
  99. 99. @theburningmonk theburningmonk.com
  100. 100. @theburningmonk theburningmonk.com Serverless framework
  101. 101. @theburningmonk theburningmonk.com Serverless framework custom splitting logic FTW!
  102. 102. @theburningmonk theburningmonk.com Serverless framework
  103. 103. @theburningmonk theburningmonk.com Serverless framework DynamoDB, S3, etc.
  104. 104. @theburningmonk theburningmonk.com Cognito User Pool AppSync DynamoDB Lambda S3 Firehose AthenaAlgolia CloudFront S3 Lambda Algolia
  105. 105. @theburningmonk theburningmonk.com Serverless framework DynamoDB, S3, etc.
  106. 106. @theburningmonk theburningmonk.com Serverless framework AppSync API, resolvers, Lambda functions, etc.
  107. 107. @theburningmonk theburningmonk.com Serverless framework !Ref and !GetAtt works as normal
  108. 108. @theburningmonk theburningmonk.com
  109. 109. @theburningmonk theburningmonk.com
  110. 110. @theburningmonk theburningmonk.com Step 1 Step 2 npm ci npm run sls -- deploy
  111. 111. @theburningmonk theburningmonk.com Step 1 Step 2 npm ci npm run sls -- deploy needs AWS credentials
  112. 112. @theburningmonk theburningmonk.com How to secure CI/CD pipeline?
  113. 113. @theburningmonk theburningmonk.com Ops Dev Staging Prod
  114. 114. @theburningmonk theburningmonk.com Ops Dev Staging Prod ci_user NO local permissions
  115. 115. @theburningmonk theburningmonk.com Ops Dev Staging Prod ci_user deploy_role deploy_role deploy_role sts:assumeRole
  116. 116. @theburningmonk theburningmonk.com Ops Dev Staging Prod ci_user deploy_role deploy_role deploy_role Entity Trust Relationship
  117. 117. @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
  118. 118. @theburningmonk theburningmonk.com
  119. 119. 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
  120. 120. test integration with other services (e.g. DynamoDB, Algolia) by executing function locally, but talk to the real DynamoDB & Algolia for Lambda
  121. 121. E2E test - execute user stories against deployed GraphQL endpoints
  122. 122. debugging failed E2E tests is a rehearsal for debugging real production issues
  123. 123. @theburningmonk theburningmonk.com AWS Organization productionstagingdevshared root OU OU OU OU Users Audit Dev Staging Production
  124. 124. @theburningmonk theburningmonk.com org-formation infrastructure-as-code CloudFormation-like YML syntax template landing zones
  125. 125. @theburningmonk theburningmonk.com org-formation
  126. 126. @theburningmonk theburningmonk.com org-formation
  127. 127. @theburningmonk theburningmonk.com org-formation
  128. 128. @theburningmonk theburningmonk.com org-formation
  129. 129. @theburningmonk theburningmonk.com org-formation
  130. 130. @theburningmonk theburningmonk.com org-formation > org-formation update
  131. 131. @theburningmonk theburningmonk.com org-formation
  132. 132. @theburningmonk theburningmonk.com
  133. 133. @theburningmonk theburningmonk.com
  134. 134. @theburningmonk theburningmonk.com
  135. 135. @theburningmonk theburningmonk.com org-formation > org-formation perform-tasks
  136. 136. @theburningmonk theburningmonk.com org-formation https://github.com/OlafConijn/AwsOrganizationFormation
  137. 137. @theburningmonk theburningmonk.com Serverless framework AppSync org-formation
  138. 138. speed of development scale to millions of users minimal up-keep cost efficient
  139. 139. @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
  140. 140. speed of development scale to millions of users minimal up-keep cost efficient
  141. 141. speed of development scale to millions of users minimal up-keep cost efficient
  142. 142. @theburningmonk theburningmonk.com
  143. 143. speed of development scale to millions of users minimal up-keep cost efficient
  144. 144. speed of development scale to millions of users minimal up-keep cost efficient
  145. 145. 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
  146. 146. @theburningmonk theburningmonk.com lambdabestpractice.com
  147. 147. @theburningmonk theburningmonk.com github.com/theburningmonk

×