Advertisement
Advertisement

More Related Content

Advertisement
Advertisement

Beware the potholes

  1. MIND THE POTHOLES MIND THE POTHOLES
  2. Yan Cui http://theburningmonk.com @theburningmonk AWS user for 10 years
  3. http://bit.ly/yubl-serverless
  4. Yan Cui http://theburningmonk.com @theburningmonk Developer Advocate @
  5. Yan Cui http://theburningmonk.com @theburningmonk Independent Consultant
  6. What do you mean by ‘serverless’?
  7. “Serverless”
  8. Gojko Adzic It is serverless the same way WiFi is wireless. http://bit.ly/2yQgwwb
  9. Serverless means… don’t pay for it if no-one uses it don’t need to worry about scaling don’t need to provision and manage servers
  10. in other words, it’s a lot like taking a cab
  11. Ownership Fuel Navigate To get there! Focus on getting there!
  12. HW Ownership OS Runtime & Scale Code Focus on getting there! Physical Servers Virtual Machines Containers Serverless
  13. Nano Services Self Managed Cost Paradigm ChangeAsync Dynamic agile env
  14. “why are we failing at this?”
  15. hidden dangers
  16. monolith microservices serverless
  17. monolith microservices serverless observability distributed systems bounded context
  18. monolith microservices serverless observability distributed systems bounded context
  19. monolith microservices serverless observability distributed systems bounded context event driven
  20. monolith serverless missing learnings from microservices
  21. monolith serverless missing learnings from microservices poor decisions
  22. #1 not letting go of legacy thinking
  23. “we’re doing serverless, but why aren’t thing going faster?”
  24. Socio Technical
  25. there are no silver bullets
  26. centralised team Team A Team B Team C Team D …
  27. “but the developers don’t understand AWS and how our infrastructure is set up”
  28. “but the developers don’t understand AWS and how our infrastructure is set up” let’s solve this problem instead!
  29. what got you here won’t get you there
  30. if (path == “/user” && method == “GET”) { return getUser(…); } else if (path == “/user” && method == “DELETE”) { return deleteUser(…); } else if (path == “/user” && method == “POST”) { return createUser(…); } else if …. Monolithic Functions
  31. GET /user POST /user DELETE /user Single-Purposed Functions
  32. author: yan.cui feature: user-api user-api-dev Monolithic Single-Purposed author: yan.cui feature: user-api user-api-dev-get-user author: yan.cui feature: user-api user-api-dev-create-user author: yan.cui feature: user-api user-api-dev-delete-user
  33. author: yan.cui feature: user-api user-api-dev Monolithic Single-Purposed author: yan.cui feature: user-api user-api-dev-get-user author: yan.cui feature: user-api user-api-dev-create-user author: yan.cui feature: user-api user-api-dev-delete-user find related functions by prefix
  34. author: yan.cui feature: user-api user-api-dev Monolithic Single-Purposed author: yan.cui feature: user-api user-api-dev-get-user author: yan.cui feature: user-api user-api-dev-create-user author: yan.cui feature: user-api user-api-dev-delete-user discoverability (without having to dig into the code)
  35. author: yan.cui feature: user-api user-api-dev Monolithic Single-Purposed author: yan.cui feature: user-api user-api-dev-get-user author: yan.cui feature: user-api user-api-dev-create-user author: yan.cui feature: user-api user-api-dev-delete-user what does it do?
  36. author: yan.cui feature: user-api user-api-dev Monolithic Single-Purposed author: yan.cui feature: user-api user-api-dev-get-user author: yan.cui feature: user-api user-api-dev-create-user author: yan.cui feature: user-api user-api-dev-delete-user dynamodb:GetItem dynamodb:PutItem dynamodb:DeleteItem
  37. author: yan.cui feature: user-api user-api-dev Monolithic Single-Purposed author: yan.cui feature: user-api user-api-dev-get-user author: yan.cui feature: user-api user-api-dev-create-user author: yan.cui feature: user-api user-api-dev-delete-user dynamodb:GetItem dynamodb:PutItem dynamodb:DeleteItem no least privilege…
  38. author: yan.cui feature: user-api user-api-dev Monolithic Single-Purposed author: yan.cui feature: user-api user-api-dev-get-user author: yan.cui feature: user-api user-api-dev-create-user author: yan.cui feature: user-api user-api-dev-delete-user require(x) require(y) require(z)
  39. author: yan.cui feature: user-api user-api-dev Monolithic Single-Purposed author: yan.cui feature: user-api user-api-dev-get-user author: yan.cui feature: user-api user-api-dev-create-user author: yan.cui feature: user-api user-api-dev-delete-user require(x) require(y) require(z)
  40. more dependecies equals slower cold start
  41. author: yan.cui feature: user-api user-api-dev Monolithic Single-Purposed author: yan.cui feature: user-api user-api-dev-get-user author: yan.cui feature: user-api user-api-dev-create-user author: yan.cui feature: user-api user-api-dev-delete-user require(x) require(y) require(z) worse cold start performance
  42. keep functions simple, and single-purposed
  43. #2 one account that rules them all
  44. mind the shared limits
  45. no. of DynamoDB tables no. of API Gateway regional APIs no. of API Gateway edge-optimized APIs no. of Kinesis shards no. of IAM roles no. of S3 buckets no. of CloudFormation stacks no. of SNS subscription filters no. of SSM parameters … Resource Limits
  46. DynamoDB read & write API Gateway requests/second Lambda concurrent executions SSM parameter ops/second … Throughput Limits
  47. One account per Team per Environment
  48. compartmentalise security breaches
  49. #3 do first, research later
  50. https://einaregilsson.com/serverless-15-percent-slower-and-eight-times-more-expensive/
  51. the platforms need to do better at educating users on how to choose between different services
  52. SNS vs SQS vs Kinesis vs MKS? the platforms need to do better at educating users on how to choose between different services
  53. ordering replay events Kinesis SQS SNS by shard none (standard) global (FIFO) none up to 7 days none none mode retry batched batched (up to 10) singular retried until success retry + DLQ retry + DLQ concurrency 1 per shard auto-scaled fan-out!!! subscribers many one-to-one many
  54. https://medium.com/theburningmonk-com/all-my-posts-on-serverless-aws-lambda-43c17a147f91
  55. https://www.jeremydaly.com/newsletter/
  56. #4 not using a deployment toolkit
  57. https://lumigo.io/blog/comparison-of-lambda-deployment-frameworks/
  58. don’t write your own deployment framework
  59. #5 console-driven development
  60. #6 one repo per function
  61. github repo github repo github repo github repo github repo github repo github repo github repo github repo
  62. github repo github repo github repo github repo github repo github repo github repo github repo github repo
  63. monorepo?
  64. github repo
  65. https://lumigo.io/blog/mono-repo-vs-one-per-service/
  66. one repo per service?
  67. github repo github repo github repo github repo user-api timeline-api relationship-api search-api
  68. CI/CD pipeline per service
  69. functions are deployed together, as a stack
  70. unencrypted secrets in env vars #7
  71. secrets should NEVER be in plain text in env variables
  72. SSM Parameter Store Secret 1 Secret 2 IAM Environment: SECRET_1: … SECRET_2: … Environment: SECRET_1: … SECRET_2: …
  73. SSM Parameter Store Secret 1 Secret 2 IAM Environment: SECRET_1: … SECRET_2: … Environment: SECRET_1: … SECRET_2: … yay!
  74. SSM Parameter Store Secret 1 Secret 2 IAM fetch at cold start, cache, invalidate every x mins
  75. https://github.com/middyjs/middy
  76. SSM Parameter Store Secret 1 Secret 2 IAM switch to Higher Throughput if you need more than 40 ops/s
  77. not following least privilege principle #8
  78. missing DLQs #9
  79. async sync S3 SNS SES CloudFormation CloudWatch Logs CloudWatch Events Scheduled Events CodeCommit AWS Config http://amzn.to/2v7Kc3b Cognito Alexa Lex API Gateway pulling DynamoDB Stream Kinesis Stream SQS
  80. async sync S3 SNS SES CloudFormation CloudWatch Logs CloudWatch Events Scheduled Events CodeCommit AWS Config http://amzn.to/2vs2lIg Cognito Alexa Lex API Gateway pulling DynamoDB Stream Kinesis Stream SQS Lambda handles retries (twice, then DLQ)
  81. configure DLQ for async functions so you don’t lose failed events
  82. too much/too little concurrency #10
  83. “Lambda generates too much load for the downstream system”
  84. one invocation per message SNS Lambda
  85. Downstream System SNS Lambda
  86. ordering replay events Kinesis SQS SNS by shard none (standard) global (FIFO) none up to 7 days none none mode retry batched batched (up to 10) singular retried until success retry + DLQ retry + DLQ concurrency 1 per shard auto-scaled fan-out!!! subscribers many one-to-one many
  87. if you want… maximum throughput SNS precise control over throughput Kinesis
  88. if you want… maximum throughput SNS precise control over throughput Kinesis how quickly it scales out
  89. if you want… maximum throughput SNS precise control over throughput Kinesis how quickly it scales out SQS DynamoDB Streams
  90. ordering replay events Kinesis SQS SNS by shard none (standard) global (FIFO) none up to 7 days none none mode retry batched batched (up to 10) singular retried until success retry + DLQ retry + DLQ concurrency 1 per shard auto-scaled fan-out!!! subscribers many one-to-one many
  91. cold starts #11
  92. “cold starts only happen to the first request”
  93. function invocationconcurrent execution i.e. a container
  94. function invocationconcurrent execution i.e. a container class instance method call
  95. Lambda scales the number of concurrent executions based on traffic
  96. existing “containers” are reused where possible
  97. time invocation
  98. time invocation invocation
  99. time invocation invocation
  100. time invocation invocation invocation invocation
  101. time invocation invocation invocation invocation invocation invocation
  102. time invocation invocation invocation invocation invocation invocation
  103. time invocation invocation invocation invocation invocation invocation invocation
  104. time invocation invocation invocation invocation invocation invocation invocation invocation
  105. time invocation invocation invocation invocation invocation invocation invocation invocation
  106. time invocation invocation invocation invocation invocation invocation invocation invocation
  107. time invocation invocation ping invocation invocation invocation ping ping
  108. Lambda warmers don’t work when you have > 1 concurrent executions
  109. FREQUENCY DURATION
  110. FREQUENCY DURATION dictated by user traffic, out of your control
  111. cold starts is generally not an issue if you have a steady traffic pattern
  112. time req/s
  113. time req/s El Classico
  114. time req/s lunch dinner
  115. FREQUENCY DURATION optimize this!
  116. minimise the duration of cold starts so they fall within acceptable latency range
  117. RDS connection handling #12
  118. default RDS configs are bad for Lambda
  119. default RDS configs are bad for Lambda idle connections are not closed too many connections per “container” max open connection is too low
  120. https://www.jeremydaly.com/manage-rds-connections-aws-lambda/
  121. set “wait_timeout” and “interactive_timeout” to 10 mins (default is 8 hours!)
  122. increase “max_connections” setting
  123. set client socket pool size to 1
  124. (lack of) observability #13
  125. happened system repaireduser impact reduce MTTR
  126. Identify & Resolve Issues Understanding costs Visibility
  127. Identify & Resolve Issues Understanding costs Visibility
  128. happened system repaireduser impact MTTDiscovery
  129. “What alerts should I have?”
  130. It depends on what you’re building…
  131. But, this is a good starting point
  132. Lambda error rate % throttle count DLR error count iterator age regional concurrency
  133. Lambda error rate % throttle count DLR error count iterator age regional concurrency API Gateway p90/95/99 latency success rate % 4xx rate % 5xx rate %
  134. API Gateway p90/95/99 latency success rate % 4xx rate % 5xx rate % SQS message age Lambda error rate % throttle count DLR error count iterator age regional concurrency
  135. API Gateway p90/95/99 latency success rate % 4xx rate % 5xx rate % SQS message age Step Functions failed count throttle count timed out count Lambda error rate % throttle count DLR error count iterator age regional concurrency
  136. SQS message age Step Functions failed count throttle count timed out count API Gateway p90/95/99 latency success rate % 4xx rate % 5xx rate % Lambda error rate % throttle count DLR error count iterator age regional concurrency
  137. “Can’t you codify these?”
  138. 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
  139. @theburningmonk theburningmonk.com github.com/theburningmonk
Advertisement