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.

Serverless Microservice Patterns for AWS

1,186 views

Published on

Serverless gives us the power to focus on writing code without worrying about the provisioning and ongoing maintenance of the underlying compute resources. Cloud providers (like AWS) also give us a huge number of managed services that we can stitch together to create incredibly powerful and massively scalable serverless microservices. This talk focuses on common design patterns that can be used to implement serverless microservices in AWS.

Published in: Internet

Serverless Microservice Patterns for AWS

  1. 1. Serverless Microservice Patterns for AWS Jeremy Daly CTO, AlertMe.news @jeremy_daly
  2. 2. Jeremy Daly • CTO at AlertMe.news • Consultant that works with companies building in the cloud • 20+ year veteran of technology startups • Started migrating workloads to the cloud in 2009 • Blogger, open-source contributor, speaker • Publish Off-by-none, a weekly newsletter about serverless @jeremy_daly
  3. 3. Agenda • Serverless Microservices ⚡ • Communication Types ☎ • Serverless Microservice Patterns 🌀 • Serverless Microservice Best Practices 🏅 • Next steps 🤔 @jeremy_daly
  4. 4. Serverless Microservices ⚡ • Multiple functions and managed components per service • Functions are independently configurable and scalable • Functions can have separate IAM roles • Functions can use different runtimes • Functions are stateless ⚠ @jeremy_daly
  5. 5. Communication Types ☎ • Synchronous Communication ⏳ Services can be invoked by other services and must wait for a reply. This is considered a blocking request, because the invoking service cannot finish executing until a response is received. • Asynchronous Communication 🚀 This is a non-blocking request. A service can invoke (or trigger) another service directly or it can use another type of communication channel to queue information.The service typically only needs to wait for confirmation (ack) that the request was received. @jeremy_daly
  6. 6. Serverless Microservice Patterns WARNING: Poorly named patterns ahead
  7. 7. The SimpleWeb Service Client API Gateway Lambda DynamoDB @jeremy_daly
  8. 8. The Gatekeeper Client API Gateway DynamoDB IAM Policy DynamoDBCognito Authorization Service Lambda Lambda Authorizer @jeremy_daly
  9. 9. RDS The ScalableWebhook Client API Gateway SQS Queue SQS (DLQ) Lambda Lambda (throttled) ack “Asynchronous” Request Synchronous Request @jeremy_daly
  10. 10. The Internal API Client w/ AWS-SDK DynamoDBLambda SQS (DLQ) Client w/ AWS-SDK DynamoDBLambda “Asynchronous” Request ack The Internal Handoff Lambda invoke() InvocationType: “RequestResponse” Lambda invoke() InvocationType: “Event” Synchronous Request Serverless Microservice Avoid API Gateway with internal invocations Beware of synchronous chaining @jeremy_daly
  11. 11. The FIFOer Client w/ AWS-SDK DynamoDB SQS Queue (FIFO) SQS (DLQ) Lambda (concurrency of 1) ack “Asynchronous” Request CloudWatch Rule (trigger every minute) InvocationType: “Event” Be sure to avoid cascading effects (this is an exception) @jeremy_daly
  12. 12. The Strangler Client API Gateway DynamoDBLambda ELB Serverless Microservice Legacy App API Gateway adds latency and can be expensive HTTP_PROXY IntegrationType @jeremy_daly
  13. 13. ALB The (Better) Strangler Client DynamoDBLambda Serverless Microservice Legacy App ALBs don’t support Custom Authorizers, Usage Plans, API Keys, etc. Lambda TargetType @jeremy_daly Advanced Request Routing • HTTP headers and methods • Query parameters • Source IP
  14. 14. hit The Read Heavy Reporting Engine Client API Gateway RDSLambda Elasticache Key Points: • Make sureTTLs are set appropriately • Include the ability to invalidate cache • Create new RDS connections ONLY on misses @jeremy_daly
  15. 15. Lambda The Fan-Out / Fan-In Client DynamoDB LambdaWorker LambdaWorker LambdaWorker S3 Bucket OR Collect Results (Fan-In) Concurrent Executions of the SAME function “Asynchronous” Request SQS (DLQ) ack SQS (DLQ) @jeremy_daly
  16. 16. The Eventually Consistent Client API Gateway DynamoDB SQS (DLQ) Lambda Lambda (throttled) RDS DynamoDB Stream Serverless Microservice Key Points: • DynamoDB Streams work like Kinesis, batches are retried • You must manage your own Dead Letter Queue (DLQ) • Include a last_updated field to limit your SQL query Synchronous Request @jeremy_daly
  17. 17. Twilio API The Circuit Breaker Client API Gateway Lambda ElasticacheKey Points: • Cache your cache with warm functions • Use a reasonable failure count • Cost (and frustration) saver for synchronous requests Status Check CLOSED OPEN Increment Failure Count HALF OPEN “Everything fails all the time.” ~WernerVogels @jeremy_daly
  18. 18. The Notifier Key Points: • SNS has a “well-defined API” • Decouples downstream processes • Allows multiple subscribers with message filters Client SNS “Asynchronous” Request ack Serverless Microservice @jeremy_daly HTTP SMS Lambda SQS Email
  19. 19. @jeremy_daly The Event Fork “Asynchronous” Request ack SQS Queue LambdaSNS Topic DynamoDBClient API Gateway Lambda Event processing pipeline SQS Queue Lambda Kinesis Firehose Event Search & Analytics pipeline Elasticsearch S3 Dead Letter Bucket SQS Queue Lambda Kinesis Firehose Event Storage & Backup pipeline S3 Backup Bucket amount > $100 Key Points: • Common patterns that can be reused • Filters allow you to control pipeline data • SNS to SQS is “guaranteed” (100,010 retries)
  20. 20. Serverless Microservice Best Practices🏅 • Services should have their own private data • Services should be independently deployable • Utilize eventual consistency • Use asynchronous processes whenever possible • Keep services small, but valuable @jeremy_daly
  21. 21. Where do we go from here? 🤔 • Loose Coupling and High Cohesion • Function Composition • Orchestration versus Choreography • State Machines (AWS Step Functions) • Lambda Layers & Nested Applications @jeremy_daly
  22. 22. Things I’m working on… Blog: jeremydaly.com Newsletter: Offbynone.io Lambda API: LambdaAPI.com Podcast: ServerlessChats.com GitHub: github.com/jeremydaly Twitter: @jeremy_daly @jeremy_daly
  23. 23. ThankYou! Jeremy Daly jeremy@jeremydaly.com @jeremy_daly

×