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.
Upcoming SlideShare
What to Upload to SlideShare
What to Upload to SlideShare
Loading in …3
×
1 of 83

Serverless patterns

2

Share

Download to read offline

This talk is a quick journey into the reasoning and beauty of serverless approach to architecture. Let's go through the platform (vendor-based, container-based, function vs service vs job) and function (functionlith/lambdalith, fat function, single purpose function, step function, routing function, circuit breaker function etc.) patterns that serverless community has come up so far with and some more. It's going to be fun!

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Serverless patterns

  1. 1. 01
  2. 2. 02
  3. 3. Let's start! 03
  4. 4. What is serverless? 04
  5. 5. Look ma, no servers! 05
  6. 6. Serverless I do not want to care about the servers! “ 06
  7. 7. Serverless may also mean Containerless/Dockerless Orchestratorless/Kubernetesless • • 07
  8. 8. Serverless is not... Serverless != Costless Serverless != FaaS Serverless != Operationless • • • 08
  9. 9. Serverless = Servicefull 09
  10. 10. Serverless is... Event driven Usage closely attached to billing Defined control plane Built-in services and integration • • • • 10
  11. 11. Serverless is... a spectrum (not a boolean) an operational construct a billing model (pay as you go) an architecture style (split your monolith) • • • • 11
  12. 12. Idea to production 12
  13. 13. Note Every organization that I worked with in the last 3 years runs at least one function in production in the cloud. “ 13
  14. 14. Compute models L1: Hardware machines L2: Virtual machines and hypervisors L3: Containers and orchestrators L4: Functions and services • • • • 14
  15. 15. FaaS 15
  16. 16. Just code def handler_name(event, context): # implement logic return some_value 01. 02. 03. 16
  17. 17. Just code? 17
  18. 18. Built-in features Event system Logging and auditing Rate limits Auto-scaling Security controls Multiple versions Simplified deployment • • • • • • • 18
  19. 19. Bought-in services Database-as-a-service Storage-as-a-service Messaging-as-a-service Function-as-a-service • • • • 19
  20. 20. FaaS elements Function store Gateway (ingress, routing, certificates) Security Event bus GitOps experience • • • • • 20
  21. 21. Patterns 21
  22. 22. Strangler pattern You can always optimize and migrate slowly! 22
  23. 23. Platform 23
  24. 24. Pattern: Cloud platform AWS GCP Azure IBM Cloud • • • • 24
  25. 25. Pattern: Multi-vendor integration Cloudflare (Workers), Mailgun, MongoDB Atlas Amplitude, Aglolia, Akamai IFTTT, Google Sheets, Zeit (Vercel) Glitch, Firebase • • • • 25
  26. 26. Pattern: Hosted platform Custom built (Docker or Kubernetes-based) Kubeless OpenFaaS OpenWhisk • • • • 26
  27. 27. Event 27
  28. 28. Pattern: event-as-a-service 28
  29. 29. Pattern: event-as-a-service HTTP call (browser call, web hook) Database event (DynamoDB, Firebase) Storage event (S3, GS) Queue/topic message (SQS, PubSub) Scheduled event (AWS Scheduled tasks, Google Scheduler) E-mail (Mailgun) • • • • • • 29
  30. 30. Deployment 30
  31. 31. Source: Lambda Trilogy 31
  32. 32. Pattern: Single-purpose function 32
  33. 33. Single-purpose function Small function that does one thing, does it only and does it well! 33
  34. 34. Lambdalith (functionlith) 34
  35. 35. Lambdalith Function implements several features, most likely responds to various endpoints. It may be a fully-blown web server. 35
  36. 36. Function vs Service 36
  37. 37. Function vs Service F: Fast to start, invoked on demand, uses limited resources, is not guarateed to preserve state. S: Always there (at least one instance), may have some long-living internal cache, background proceses, usually takes longer to start. 37
  38. 38. Function vs Container 38
  39. 39. AWS Fargate 39
  40. 40. On-prem/Custom OpenFaaS Kubeless KNative • • • 40
  41. 41. Pattern: Fat function 41
  42. 42. Pattern: Fat function One code base, many (deployed) functions. 42
  43. 43. Pattern: Routing function 43
  44. 44. Pattern: Routing function Function is calling other functions (through event bus or through direct calls). 44
  45. 45. Pattern: Routing function 45
  46. 46. Pattern: Gateway Routing logic is delegated to a higher level service e.g. API Gateway or Event Bridge. 46
  47. 47. Pattern: Step-functions 47
  48. 48. Pattern: Configuration discovery 48
  49. 49. Pattern: Configuration discovery C1: Baked into a function C2: Configuration manager (AWS SSM Parameter store/Secret Manager, Secrethub.io, ConfigMap) C3: Bucket (AWS S3, Google Cloud Storage) C4: DNS • • • • 49
  50. 50. Pattern: Optimizing cold-start Optimizing cold-start times. 50
  51. 51. Anti-pattern: Over-optimizing cold-start Over-optimizing cold-start times. 51
  52. 52. Testing 52
  53. 53. Pattern: simulated function environment AWS SAM Local Google Functions Framework • • 53
  54. 54. Pattern: mocked cloud services Use code orgnization techniques to abstract/stub/mock your dependencies inside function logic. 54
  55. 55. Pattern: log stream Standard output is your friend, take care of it. 55
  56. 56. Pattern: tracing id FaaS environments contain extra context (like request id) that can be passed to 56
  57. 57. AWS Lambda context 57
  58. 58. Pattern: callback chat channel 58
  59. 59. Pattern: callback chat channel Important business logic events can be sent to chat (debugging) channel. 59
  60. 60. Example: Callback channel 60
  61. 61. Database 61
  62. 62. Pattern: database-as-a-service D0: Custom server(s) with database software D1: Custom container(s) with database and persistent (Kubernetes, Helm, Kubedb) D2: Database server as a service (AWS RDS, MongoDB Atlas) D3: Scalable database as a service (AWS DynamoDB, Azure Cosmos, Google Firebase) • • • • 62
  63. 63. Pattern: database-in-a-function Dataset is small enough (upto 100MBs) It is mostly read-only It changes infrequently (re-deploy) It does not affect cold start too much (upto 30 seconds) • • • • 63
  64. 64. dev.tube 64
  65. 65. Peak time 65
  66. 66. Architecture Node.js/Typescript/Express/Vue.js GCP/Firebase GitHub • • • 66
  67. 67. Architecture 67
  68. 68. Price optimization Data is inside a function! HA database attached to public internet traffic is expensive! Load balancer is expensive! f1.micro with nginx was cheaper. Indexer runs once a day with some heuristics to not over-use YouTube API quota. • • • 68
  69. 69. Security 69
  70. 70. Security issues What if my hardware is vulnerable? (Meltdown and Spectre) What if my hypervisor is vulernable? What if my operating system is vulernable? (Heartbleed) What if my container engine is vulnerable? (CVE-2019-5736) What if my application is vulnerable? • • • • • 70
  71. 71. Risk: injection attacks Replay attack? SQL injection? XSS? Input must be validated. 71
  72. 72. Pattern: request signing Function expects that all incoming requests are signed (e.g. HMAC) to check that message content didn't change in transit. 72
  73. 73. Risk: denial-of-payment Someone called your function so many times, you have to sell your house! 73
  74. 74. Pattern: rate limiting API Gateway Limited concurrency • • 74
  75. 75. Anti-pattern: recursive function call7575
  76. 76. Risk: public function No authentication? Seriously? 76
  77. 77. Pattern: security token Function expects known security token to be passed as a proof of trusted invoker. 77
  78. 78. Pattern: platform authentication Function can only be invoked by authenticated user (AWS Cognito, Google IAM user). 78
  79. 79. Conclusion It is servicefull! It is code! It is a mix of Dev and Ops! • • • 79
  80. 80. Thank you! 80
  81. 81. 81
  82. 82. Links I https://serverless.com/ https://cdkpatterns.com/ https://aws.amazon.com/blogs/architecture/updates-to-serverless- architectural-patterns-and-best-practices/ • • • 82
  83. 83. Links II https://www.jeremydaly.com/serverless-microservice-patterns-for-aws/ https://www.youtube.com/watch?v=tHD3i06Z6gU https://www.youtube.com/watch?v=vuWiB3vNiHc • • • 83

×