Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Advanced Serverless Messaging Patterns - Server...

Julian Wood
September 28, 2021

Advanced Serverless Messaging Patterns - ServerlessDays Paris

Using the right messaging patterns between your services can help with durability, availability, and reducing custom code. This talk shows how to use AWS services to build robust messaging patterns into the foundation of your application architecture. Introduce fan-out, queuing, and decoupling between your services and combine multiple services to create powerful architectures that make your workloads scale.

Julian Wood

September 28, 2021
Tweet

More Decks by Julian Wood

Other Decks in Technology

Transcript

  1. © 2021, Amazon Web Services, Inc. or its affiliates. ©

    2021, Amazon Web Services, Inc. or its affiliates. Advanced Serverless Messaging Patterns Julian Wood Senior Developer Advocate – AWS Serverless @julian_wood ServerlessDays Paris 2021 @julian_wood
  2. © 2021, Amazon Web Services, Inc. or its affiliates. About

    me Julian Wood Senior Developer Advocate – AWS Serverless @julian_wood [email protected] Recovering server-more infrastructure engineer Enterprises and startups You can’t scare me – I have twin girls! From Cape Town via London
  3. © 2021, Amazon Web Services, Inc. or its affiliates. ©

    2021, Amazon Web Services, Inc. or its affiliates. Messaging Overload Alert WARNING!!! Slides are available at: s12d.com/SDaysParis21
  4. © 2021, Amazon Web Services, Inc. or its affiliates. Event-driven

    compute Functions as a service Serverless FaaS
  5. © 2021, Amazon Web Services, Inc. or its affiliates. What

    is messaging? 5 “Loosely coupled systems” The looser they are coupled, the bigger they will scale, the more fault-tolerant they will be, the less dependencies they will have, the faster you will innovate.
  6. © 2021, Amazon Web Services, Inc. or its affiliates. If

    your application is cloud- native, or large-scale, or distributed, and doesn’t include a messaging component, that’s probably a bug. Tim Bray General-purpose, internet-software geek
  7. © 2021, Amazon Web Services, Inc. or its affiliates. The

    microservices “iceberg” Common question: “Should every service of mine talk to another using an API?” Maybe not!: Most microservices are internal only for a given product supporting their customer facing features. They may only need to pass messages to each other that are simple events and not need a full fledged interactive API. Public interface Internal services
  8. © 2021, Amazon Web Services, Inc. or its affiliates. Public

    interface Focusing below the water line Internal services
  9. © 2021, Amazon Web Services, Inc. or its affiliates. What

    does messaging provide? Scalability Resilience Availability
  10. © 2021, Amazon Web Services, Inc. or its affiliates. ©

    2021, Amazon Web Services, Inc. or its affiliates. Microservice messaging patterns
  11. © 2021, Amazon Web Services, Inc. or its affiliates. Messaging

    patterns Point-to-point (queue) Publish/subscribe (topic)
  12. © 2021, Amazon Web Services, Inc. or its affiliates. Messaging

    patterns Point-to-point (queue) Publish/subscribe (topic) Receiver(s) Sender B C B C Consumed by single receiver (scaled out) Easy to scale Flatten peak loads Queue
  13. © 2021, Amazon Web Services, Inc. or its affiliates. Messaging

    patterns Point-to-point (queue) Publish/subscribe (topic) Subscribers Publisher B C B C B C B C Consumed by single receiver (scaled out) Easy to scale Flatten peak loads Consumed by multiple subscribers Topic Receiver(s) Sender B C B C Queue
  14. © 2021, Amazon Web Services, Inc. or its affiliates. Messaging

    patterns Point-to-point (queue) Publish/subscribe (topic) Receiver(s) Sender Subscribers Publisher B C B C B C B C B C B C AWS service for queue functionality Amazon Simple Queue Service (SQS) Serverless and cloud native AWS service for topic functionality Amazon Simple Notification Service (SNS) Serverless and cloud native Amazon SQS Amazon SNS
  15. © 2021, Amazon Web Services, Inc. or its affiliates. Messaging

    patterns Point-to-point (queue) Publish/subscribe (topic) Receiver(s) Sender Subscribers Publisher B C B C B C B C B C B C AWS service for queue functionality Amazon Simple Queue Service (SQS) Serverless and cloud native AWS service for topic functionality Amazon Simple Notification Service (SNS) Serverless and cloud native Amazon SQS Amazon SNS AWS Lambda AWS Lambda
  16. © 2021, Amazon Web Services, Inc. or its affiliates. Messaging

    patterns Point-to-point (queue) Publish/subscribe (topic) Receiver(s) Sender Subscribers Publisher B C B C B C B C B C B C AWS service for queue functionality Amazon Simple Queue Service (SQS) Serverless and cloud native AWS service for topic functionality Amazon Simple Notification Service (SNS) Serverless and cloud native Amazon SQS Amazon SNS AWS Lambda AWS Lambda
  17. © 2021, Amazon Web Services, Inc. or its affiliates. Messaging

    patterns Point-to-point (queue) Publish/subscribe (topic) Receiver(s) Sender Subscribers Publisher B C B C B C B C B C B C AWS service for queue functionality Amazon Simple Queue Service (SQS) Serverless and cloud native AWS service for topic functionality Amazon Simple Notification Service (SNS) Serverless and cloud native Amazon SQS Amazon SNS AWS Lambda AWS Lambda AWS Lambda AWS Lambda
  18. © 2021, Amazon Web Services, Inc. or its affiliates. Messaging

    patterns Publish/subscribe (event bus) Targets B C B Bus Publishers Route to targets based on filter rules C C
  19. © 2021, Amazon Web Services, Inc. or its affiliates. Messaging

    patterns Publish/subscribe (event bus) Targets Custom events B C C AWS services SaaS apps AWS service for event bus functionality Amazon EventBridge Serverless and cloud native Amazon Eventbridge Publishers Route to targets based on filter rules Content-based routing C B
  20. © 2021, Amazon Web Services, Inc. or its affiliates. Messaging

    patterns AWS Lambda Amazon Kinesis Data Firehose AWS Step Functions API destination Publish/subscribe (event bus) Targets Custom events B C C AWS services SaaS apps AWS service for event bus functionality Amazon EventBridge Serverless and cloud native Amazon Eventbridge Publishers Route to targets based on filter rules Content-based routing C B
  21. © 2021, Amazon Web Services, Inc. or its affiliates. Messaging

    services Amazon EventBridge Event Bus Fully managed Build event-driven applications at scale for AWS services, your own applications, and SaaS providers Amazon SNS Pub/Sub Fully managed High-throughput, push-based, many-to-many messaging between distributed systems Amazon SQS Queues Fully managed Message queuing service to decouple and scale distributed systems. Amazon Kinesis Streams Fully managed Collect, process, and analyse real-time, streaming data
  22. Lambda execution model Asynchronous (event) Stream (poll-based) Synchronous (push) Amazon

    DynamoDB Amazon SNS /order Amazon S3 reqs Amazon Kinesis changes AWS Lambda service function Amazon API Gateway Lambda function Lambda function
  23. © 2021, Amazon Web Services, Inc. or its affiliates. 1.

    Lambda directly invoked via invoke API SDK clients Lambda API API provided by the Lambda service Used by all other services that invoke Lambda across all models Supports sync and async Can pass any event payload structure you want Client included in every SDK Synchronous via AWS console Lambda function
  24. © 2021, Amazon Web Services, Inc. or its affiliates. ©

    2021, Amazon Web Services, Inc. or its affiliates. Comparing services
  25. © 2021, Amazon Web Services, Inc. or its affiliates. Comparing

    messaging services Pricing Persistence Retries Durability Scale/Concurrency controls Consumption models
  26. © 2021, Amazon Web Services, Inc. or its affiliates. Scaling/Concurrency

    controls Service Scaling controls Lambda API Concurrency is point in time, not TPS, can go from 0 up through maximum for account per Region and is shared for all functions in a Region. By default no per function concurrency throttle is set. SNS Service automatically scales, use Lambda Per Function Concurrency setting to control downstream consumption. EventBridge Service automatically scales, use Lambda Per Function Concurrency setting to control downstream consumption. 400-2400 events/sec. Can request limit increases to 100Ks TPS. SQS Service automatically scales, use Lambda trigger Batch size setting and Per Function Concurrency setting to control downstream consumption. Kinesis Streams Shards in a stream: One shard provides ingest capacity of 1MB/sec or 1000 records/sec, up to 2MB/sec of data output.
  27. © 2021, Amazon Web Services, Inc. or its affiliates. Scaling/Concurrency

    controls Service Scaling controls Lambda API Concurrency is point in time, not TPS, can go from 0 up through maximum for account per Region and is shared for all functions in a Region. By default no per function concurrency throttle is set. SNS Service automatically scales, use Lambda Per Function Concurrency setting to control downstream consumption. EventBridge Service automatically scales, use Lambda Per Function Concurrency setting to control downstream consumption. 400-2400 events/sec. Can request limit increases to 100Ks TPS. SQS Service automatically scales, use Lambda trigger Batch size setting and Per Function Concurrency setting to control downstream consumption. Kinesis Streams Shards in a stream: One shard provides ingest capacity of 1MB/sec or 1000 records/sec, up to 2MB/sec of data output. Use Lambda concurrency Lambda concurrency + batch size Manage number of shards
  28. © 2021, Amazon Web Services, Inc. or its affiliates. Managing

    concurrency for a Lambda function Reserved concurrency • Guarantees the maximum number of concurrent function invocations • No other function can use that concurrency • “Stop switch” – set per function concurrency to zero Provisioned concurrency • Initializes a requested number of execution environments • Enables your functions to scale without fluctuations in latency
  29. © 2021, Amazon Web Services, Inc. or its affiliates. Concurrency

    across models SNS/EventBridge/API No event store Queue based (SQS) Stream based (Kinesis)
  30. © 2021, Amazon Web Services, Inc. or its affiliates. Durability

    Service Durability of requests “in flight” Lambda API Lambda API is built to be highly available but offers no durability of requests, client would need to handle failures/retries. SNS *SNS provides durable storage of all messages that it receives. Upon receiving a publish request, SNS stores multiple copies (to disk) of the message across multiple Availability Zones before acknowledging receipt of the request to the sender. EventBridge *EventBridge provides durable storage of all events that it receives. EventBridge stores multiple copies (to disk) of the message across multiple Availability Zones before acknowledging receipt of the request to the sender. SQS *Amazon SQS stores all message queues and messages within a single, highly- available AWS Region with multiple redundant Availability Zones (AZs), so that no single computer, network, or AZ failure can make messages inaccessible. Kinesis Streams *Amazon Kinesis Data Streams synchronously replicates data across three availability zones, providing high availability and data durability
  31. © 2021, Amazon Web Services, Inc. or its affiliates. Durability

    Service Durability of requests “in flight” Lambda API Lambda API is built to be highly available but offers no durability of requests, client would need to handle failures/retries. SNS *SNS provides durable storage of all messages that it receives. Upon receiving a publish request, SNS stores multiple copies (to disk) of the message across multiple Availability Zones before acknowledging receipt of the request to the sender. EventBridge *EventBridge provides durable storage of all events that it receives. EventBridge stores multiple copies (to disk) of the message across multiple Availability Zones before acknowledging receipt of the request to the sender. SQS *Amazon SQS stores all message queues and messages within a single, highly- available AWS Region with multiple redundant Availability Zones (AZs), so that no single computer, network, or AZ failure can make messages inaccessible. Kinesis Streams *Amazon Kinesis Data Streams synchronously replicates data across three availability zones, providing high availability and data durability Short version: Data is replicated across multiple Availability Zones for all 4 of these services.
  32. © 2021, Amazon Web Services, Inc. or its affiliates. Persistence

    Service Persistence of requests “in flight” Lambda API No formal persistence model SNS No formal persistence model beyond delivery retry logic that extends up through potentially 23 days when sending to Lambda and SQS EventBridge No formal persistence model beyond delivery retry logic that extends up through potentially 24 hours. Event replay allows reprocessing past events. SQS By default messages are stored for 4 days. This can be modified to as little as 60 seconds up to 14 days by configuring a queue’s MessageRetentionPeriod attribute Kinesis Streams By default data is stored for 24 hours. You can increase this up to 168 hours (7 days). Extended data retention costs $0.02 per Shard Hour above 24 hours
  33. © 2021, Amazon Web Services, Inc. or its affiliates. Persistence

    Service Persistence of requests “in flight” Lambda API No formal persistence model SNS No formal persistence model beyond delivery retry logic that extends up through potentially 23 days when sending to Lambda and SQS EventBridge No formal persistence model beyond delivery retry logic that extends up through potentially 24 hours SQS By default messages are stored for 4 days. This can be modified to as little as 60 seconds up to 14 days by configuring a queue’s MessageRetentionPeriod attribute Kinesis Streams By default data is stored for 24 hours. You can increase this up to 168 hours (7 days). Extended data retention costs $0.02 per Shard Hour above 24 hours Short version: No formal persistence Short version: Data is persisted for x
  34. © 2021, Amazon Web Services, Inc. or its affiliates. Consumption

    Service Invocation model Guidance Lambda API Can be sync or async from client to a single invocation For complicated Lambda to Lambda workflows use AWS Step Functions SNS Async to Lambda. SNS can ”fanout” to multiple subscribing Lambda functions the same message Use Message Filtering to control which messages go to which subscribers. Use Message delivery status to track failures EventBridge Async to Lambda. Sources=130 direct AWS event sources, CloudTrail mutating API calls & 25+ SaaS partners. Route to 17 targets. Single EventBridge rule can route to multiple targets in parallel. Use rules to filter events to control which events go to which targets. Use FailedInvocations metric to track failures SQS Lambda service polls messages from queue and invokes Lambda on your behalf. Scales polling based on inflight messages. Can call message delete from within your code or let the service handle it via successful Lambda function execution Kinesis Streams Lambda service polls messages from streams and invokes Lambda on your behalf. Can run multiple applications to consume the same stream for different needs or use enhanced fan-out to for up to five isolated consumers per stream at 2MB/second/shard. Use the Amazon Kinesis Client Library. Configure batch size so that your function has enough time to complete processing of records (which might be batches on ingest as well)
  35. © 2021, Amazon Web Services, Inc. or its affiliates. Consumption

    Service Invocation model Guidance Lambda API Can be sync or async from client to a single invocation For complicated Lambda to Lambda workflows use AWS Step Functions SNS Async to Lambda. SNS can ”fanout” to multiple subscribing Lambda functions the same message Use Message Filtering to control which messages go to which subscribers. Use Message delivery status to track failures EventBridge Async to Lambda. Sources=130 direct AWS event sources, CloudTrail mutating API calls & 25+ SaaS partners. Route to 17 targets. Single EventBridge rule can route to multiple targets in parallel. Use rules to filter events to control which events go to which targets. Use FailedInvocations metric to track failures SQS Lambda service polls messages from queue and invokes Lambda on your behalf. Scales polling based on inflight messages. Can call message delete from within your code or let the service handle it via successful Lambda function execution Kinesis Streams Lambda service polls messages from streams and invokes Lambda on your behalf. Can run multiple applications to consume the same stream for different needs or use enhanced fan-out to for up to five isolated consumers per stream at 2MB/second/shard. Use the AWS Kinesis Client Library. Configure batch size so that your function has enough time to complete processing of records (which might be batches on ingest as well) sync async poll sync async poll
  36. © 2021, Amazon Web Services, Inc. or its affiliates. Messaging-payload

    size limits AWS Lambda Sync: 6 MB Async: 256 KB Amazon SQS 256 KB Amazon SNS 256 KB (SMS) 1,600 b AWS Step Functions 32 KB Amazon API Gateway REST/HTTP: 10 MB WebSockets: 128 KB (32-MB frames) Amazon EventBridge 256 KB
  37. Retry/failure handling Service Retry/failure capabilities Lambda API Retry/failure logic is

    client dependent for synchronous invocations. For asynchronous, invocations are retried twice by Lambda service (configurable between zero and two with maximum event age 60 seconds – 6 hours). SNS If Lambda is not available, SNS will retry 3 times without delay, 2 times at 1 seconds apart, then 10 times with exponential backoff from 1 second to 20 seconds, and finally 100,000 times every 20 seconds for a total 100,015 attempts over more than 23 days before the message is discarded from SNS. EventBridge Retry with exponential back off for up to 24 hours for a specific invocation, except in scenarios where your target resource is constrained SQS Messages remain in the queue until deleted. They are prevented by being accessed by other consumers during a period of time known as the “visibility timeout”. Successful Lambda invocations will cause deletions of messages automatically. If an invocation fails or doesn’t delete a message during the visibility timeout window it is made available again for other consumers. Kinesis Streams When using the Kinesis Client Library (KCL) it maintains a checkpoint/cursor of processed records and will retry records from the same shard in order until the cursor shows completion. Can use Bisect On Function Error for retries
  38. Retry/failure handling Service Retry/failure capabilities Lambda API Retry/failure logic is

    client dependent for synchronous invocations. For asynchronous, invocations are retried twice by Lambda service (configurable between zero and two with maximum event age 60 seconds – 6 hours). SNS If Lambda is not available, SNS will retry 3 times without delay, 2 times at 1 seconds apart, then 10 times with exponential backoff from 1 second to 20 seconds, and finally 100,000 times every 20 seconds for a total 100,015 attempts over more than 23 days before the message is discarded from SNS. EventBridge Retry with exponential back off for up to 24 hours for a specific invocation, except in scenarios where your target resource is constrained SQS Messages remain in the queue until deleted. They are prevented by being accessed by other consumers during a period of time known as the “visibility timeout”. Successful Lambda invocations will cause deletions of messages automatically. If an invocation fails or doesn’t delete a message during the visibility timeout window it is made available again for other consumers. Kinesis Streams When using the Kinesis Client Library (KCL) it maintains a checkpoint/cursor of processed records and will retry records from the same shard in order until the cursor shows completion. Can use Bisect On Function Error for retries Sync = client dependent Async = 0-2 retries, max event age 60s-6h Retry with exponential backoff, up to 23 days Retry with exponential backoff, up to 24 hours Messages remain in queue until deleted or age beyond visibility timout Retry until completion, can bisect batch
  39. © 2021, Amazon Web Services, Inc. or its affiliates. Lambda

    Async Error Handling “When an invocation event exceeds the maximum age or fails all retry attempts (default=2), Lambda discards it. To retain a copy of discarded events, configure a failed-event destination.” • Retry attempts – The number of times Lambda retries when the function returns an error, between 0 and 2. • Maximum age of event – The maximum amount of time Lambda retains an event in the asynchronous event queue, up to 6 hours. “To send records of asynchronous invocations to another service, add a destination to your function.” Turn this on! (for async use-cases)
  40. Lambda Destinations for Asynchronous Invocations Lambda function Amazon SNS Amazon

    S3 Amazon CloudFormation Amazon CloudWatch Logs Amazon EventBridge Amazon SES AWS CodeCommit AWS Config "DestinationConfig": { "onSuccess" : { "Destination": “arn" }, "onFailure" : { "Destination": “arn" }, } Amazon SNS Amazon SQS AWS Lambda Amazon EventBridge Routes execution result to downstream service OnFailure alternative = Lambda Dead Letter Queues (DLQ) to SNS or SQS
  41. © 2021, Amazon Web Services, Inc. or its affiliates. Amazon

    EventBridge dead letter queues EventBridge now supports DLQ and custom retry policy (maximum # of retries or the maximum event age of the event) via customer managed Amazon SQS queue Don’t lose events and understand root cause P-E2 S-E2 P-E1 S-E1 Blue service context E1 rule E2 rule E2 target DLQ E1 target DLQ (in another account) Possible root causes? • Permissions not correct • Service availability • Deleted resource • Throttling • Cross account loop • Invalid parameters Purple service context Blue service team Purple service team
  42. © 2021, Amazon Web Services, Inc. or its affiliates. Pricing

    Service Model Cost Per Mil Factor Other Lambda API Per request $0.20* SNS Per request $0.50* Each 64KB chunk of delivered data is billed as 1 request No charge for deliveries to Lambda EventBridge Per event $1.00* Each 64 KB chunk of a payload is billed as 1 event no charge for events published by AWS services. No charge for deliveries to Lambda SQS Per request $0.40* Each 64 KB chunk of a payload is billed as 1 request A single request can have from 1 to 10 messages Kinesis Streams Per Shard hour & per request PUT Payload Units Shard per Hour = $0.015 PUT Payload Units $0.014 Each 25KB chunk of a payload (PUT Payload Units) are billed as 1 request Enhanced Fanout and Extended Data Retention (beyond 24 hours) cost extra * First 1 Million requests are free per month
  43. © 2021, Amazon Web Services, Inc. or its affiliates. Pricing

    Service Model Cost Per Mil Factor Other Lambda API Per request $0.20* SNS Per request $0.50* Each 64KB chunk of delivered data is billed as 1 request No charge for deliveries to Lambda EventBridge Per event $1.00* Each 64 KB chunk of a payload is billed as 1 event no charge for events published by AWS services. No charge for deliveries to Lambda SQS Per request $0.40* Each 64 KB chunk of a payload is billed as 1 request A single request can have from 1 to 10 messages Kinesis Streams Per Shard hour & per request PUT Payload Units Shard per Hour = $0.015 PUT Payload Units $0.014 Each 25KB chunk of a payload (PUT Payload Units) are billed as 1 request Enhanced Fanout and Extended Data Retention (beyond 24 hours) cost extra * First 1 Million requests are free per month * First 1 Million requests are free per month
  44. © 2021, Amazon Web Services, Inc. or its affiliates. Amazon

    EventBridge Amazon SNS Sources More than 130 AWS services 37 SaaS integrations Custom applications 30 AWS services Custom applications Targets 35 AWS services 2 AWS services + 4 web & mobile endpoints Fan Out 5 targets per rule 400-2400 events/sec (soft, can be up to 100Ks) 750-4500 invocations / sec (soft) Supports millions of subscribers per topic Filtering Rules apply to entire event body Advanced filtering rules, has input transformation, schema registry/discovery Filters apply only to message attributes (10 per message) Content-based filtering done in code Latency Median of 560ms Median of 25ms Price AWS event sources are free $1.00/million custom or SaaS events Free to deliver events to any AWS target $0.50/million messages to a topic Deliveries to AWS services (SQS, Lambda) are free. $0.50/million for mobile push, $0.60/million for HTTP/S, $20/million for email, SMS deliveries vary by Region
  45. © 2021, Amazon Web Services, Inc. or its affiliates. When

    to use X or EventBridge CloudWatch Events = replace with EventBridge ❌ only AWS services as sources, only uses default event bus. no SaaS integrations SNS ✔ for high throughput (millions TPS), millions of subscribers, very low latency ❌ only limited targets, no ordering, filtering only on attributes, may need multiple topics Kinesis ✔ for real-time processing at large scale, routing and storing, guarantees order ❌ limited consumers per stream, not serverless (doesn’t scale automatically, not usage based pricing) SQS ✔ need resiliency, ordering guarantees (FIFO queues), buffer downstream services ❌ no filtering, no ordering (standard queues)
  46. © 2021, Amazon Web Services, Inc. or its affiliates. ©

    2021, Amazon Web Services, Inc. or its affiliates. Combining messaging patterns
  47. © 2021, Amazon Web Services, Inc. or its affiliates. Topic-queue-chaining

    Amazon SNS -> Amazon SQS Publisher B C B C B C Queue Queue Topic
  48. © 2021, Amazon Web Services, Inc. or its affiliates. Topic-queue-chaining

    Amazon SNS -> Amazon SQS -> Receiver Application 1 B C Publisher B C B C B C Queue Queue Topic
  49. © 2021, Amazon Web Services, Inc. or its affiliates. Topic-queue-chaining

    Amazon SNS -> Amazon SQS -> Receiver (Lambda) Allows fan-out and receiver scale-out at the same time Receivers C Application 1 B C Queue Queue Publisher B C B C B C Application 2 B Topic
  50. © 2021, Amazon Web Services, Inc. or its affiliates. Scatter-gather

    How do you distribute a request across potentially interested/relevant parties and capture their individual responses? Election or parallel processing scenarios (i.e., search for best response or accumulate responses)
  51. © 2021, Amazon Web Services, Inc. or its affiliates. Scatter-gather

    Amazon SNS Requester Responders How do you distribute a request across potentially interested/relevant parties and capture their individual responses? Election or parallel processing scenarios (i.e., search for best response or accumulate responses) Topic
  52. © 2021, Amazon Web Services, Inc. or its affiliates. Scatter-gather

    Amazon SNS -> Amazon SQS B1 B2 B3 Requester Responders How do you distribute a request across potentially interested/relevant parties and capture their individual responses? Election or parallel processing scenarios (i.e., search for best response or accumulate responses) Topic Queue
  53. © 2021, Amazon Web Services, Inc. or its affiliates. Scatter-gather

    Amazon SNS -> Amazon SQS - > Aggregator/Processor B1 B2 B3 Aggregator Processor B1 B2 B3 Requester Responders How do you distribute a request across potentially interested/relevant parties and capture their individual responses? Election or parallel processing scenarios (i.e., search for best response or accumulate responses) Topic Queue
  54. © 2021, Amazon Web Services, Inc. or its affiliates. Amazon

    EventBridge Custom events B C AWS services SaaS apps Amazon Eventbridge Publishers Event-topic-chaining Route to targets based on filter rules Content-based routing
  55. © 2021, Amazon Web Services, Inc. or its affiliates. Amazon

    EventBridge -> Amazon SNS Custom events B C AWS services SaaS apps Amazon Eventbridge Publishers B Event-topic-chaining Amazon SNS Targets Fan-out to multiple subscribers Route to targets based on filter rules Content-based routing
  56. © 2021, Amazon Web Services, Inc. or its affiliates. Amazon

    EventBridge -> Amazon SNS -> Subscribers Custom events B C AWS services SaaS apps Amazon Eventbridge Publishers B Event-topic-chaining Subscribers B B B Amazon SNS Targets Fan-out to multiple subscribers Route to targets based on filter rules Content-based routing
  57. © 2021, Amazon Web Services, Inc. or its affiliates. AWS

    Lambda Amazon EventBridge -> Amazon SNS -> Subscribers (AWS Lambda) Custom events B C AWS services SaaS apps Publishers B Event-topic-chaining Subscribers B B B Fan-out to multiple subscribers Route to targets based on filter rules Content-based routing Amazon Eventbridge Amazon SNS Targets
  58. © 2021, Amazon Web Services, Inc. or its affiliates. AWS

    account B – us-west-2 AWS account A – us-east-1 AWS Lambda Amazon EventBridge -> Amazon SNS -> Subscribers (AWS Lambda in separate account) Custom events B C AWS services SaaS apps Publishers B Event-topic-chaining Subscribers B B B Amazon Eventbridge Amazon SNS Targets
  59. © 2021, Amazon Web Services, Inc. or its affiliates. Amazon

    EventBridge Custom events B C AWS services SaaS apps Publishers Event-queue-chaining Route to targets based on filter rules Amazon Eventbridge
  60. © 2021, Amazon Web Services, Inc. or its affiliates. Amazon

    EventBridge -> Amazon SQS Custom events B C AWS services SaaS apps Publishers B Event-queue-chaining Route to targets based on filter rules Amazon Eventbridge C Amazon SQS Amazon SQS B Queue and store messaging for processing
  61. © 2021, Amazon Web Services, Inc. or its affiliates. Amazon

    EventBridge -> Amazon SQS -> Receivers (AWS Lambda) Custom events B C AWS services SaaS apps Publishers B Event-queue-chaining Route to targets based on filter rules Amazon Eventbridge C B C Amazon SQS B Amazon SQS B Queue and store messaging for processing
  62. © 2021, Amazon Web Services, Inc. or its affiliates. Microservice

    B Amazon EventBridge -> Amazon SQS -> Receivers (AWS Lambda) -> Downstream resources Custom events B C AWS services SaaS apps Publishers B Event-queue-chaining Route to targets based on filter rules Amazon Eventbridge C B C Amazon SQS B Amazon SQS B Queue and store messaging for processing Protect downstream resources Microservice A Amazon RDS
  63. © 2021, Amazon Web Services, Inc. or its affiliates. Pipes

    and filters Event source Result target
  64. © 2021, Amazon Web Services, Inc. or its affiliates. Pipes

    and filters Event triggers chain of processing steps (filters) Pipe Filter Step 1 Event source Result target
  65. © 2021, Amazon Web Services, Inc. or its affiliates. Pipes

    and filters Event triggers chain of processing steps (filters) Knowledge of destination for next steps is wired into each filter Filter Pipe Pipe . . . Filter Step 2 Step N B B C Pipe Filter Step 1 Event source Result target
  66. © 2021, Amazon Web Services, Inc. or its affiliates. Saga

    orchestration Event source Result target
  67. © 2021, Amazon Web Services, Inc. or its affiliates. Saga

    orchestration Event triggers orchestrated workflow Orchestrator Event source Result target
  68. © 2021, Amazon Web Services, Inc. or its affiliates. Saga

    orchestration Event triggers orchestrated workflow Workflow externalized into orchestrator component, including potential rollback Event source Result target Orchestrator
  69. © 2021, Amazon Web Services, Inc. or its affiliates. Saga

    orchestration Event triggers orchestrated workflow Workflow externalized into orchestrator component, including potential rollback Workflow participants remain as loosely coupled as possible Processor Step 1 Event source Result target Orchestrator • Transactions
  70. © 2021, Amazon Web Services, Inc. or its affiliates. Saga

    orchestration Event triggers orchestrated workflow Workflow externalized into orchestrator component, including potential rollback Workflow participants remain as loosely coupled as possible Processor Step 2 Processor Step 1 Event source Result target Orchestrator • Transactions • Branching
  71. © 2021, Amazon Web Services, Inc. or its affiliates. Saga

    orchestration . . . Event triggers orchestrated workflow Workflow externalized into orchestrator component, including potential rollback Workflow participants remain as loosely coupled as possible Processor Step 2 Processor Step 1 Event source Result target Orchestrator • Transactions • Branching • Retries
  72. © 2021, Amazon Web Services, Inc. or its affiliates. Saga

    orchestration Processor Step N–1 . . . Event triggers orchestrated workflow Workflow externalized into orchestrator component, including potential rollback Workflow participants remain as loosely coupled as possible Processor Step 2 Processor Step 1 Event source Result target Orchestrator • Transactions • Branching • Retries • Parallel processing
  73. © 2021, Amazon Web Services, Inc. or its affiliates. Saga

    orchestration Processor Step N Processor Step N–1 . . . Event triggers orchestrated workflow Workflow externalized into orchestrator component, including potential rollback Workflow participants remain as loosely coupled as possible Processor Step 2 Processor Step 1 Event source Result target Orchestrator • Transactions • Branching • Retries • Parallel processing
  74. © 2021, Amazon Web Services, Inc. or its affiliates. Saga

    orchestration AWS service for saga orchestration (serverless) AWS Step Functions Processor Step N Processor Step N–1 . . . Processor Step 2 Processor Step 1 Event source Result target Orchestrator • Transactions • Branching • Retries • Parallel processing
  75. © 2021, Amazon Web Services, Inc. or its affiliates. AWS

    Step Functions + Lambda “Serverless” workflow management with zero administration: • Coordinate microservices using visual workflows • Automatically triggers and tracks each step • Can handle custom failure messages from Lambda code Choice Start ExtractImageMetadata CheckJobStatus Amazon Rekognition ImageTypeCheck NotSupportedImageType End Thumbnail AddRekognizedTags Tasks Failure capture Parallel tasks
  76. © 2021, Amazon Web Services, Inc. or its affiliates. Things

    to think about… What invocation resource is the right one for you? How “real time” do you need? •How synchronous is your synchronous workload? •Can you poll for updates after an async invocation? Does order matter? Do multiple services need to feed off of the same data? What will break if your Lambda function has bad code? Think about the downstream! •What happens when a downstream service fails? •Is there the potential to overwhelm a database or other service?
  77. © 2021, Amazon Web Services, Inc. or its affiliates. Things

    to think about… What invocation resource is the right one for you? • All of these services require little care and feeding in terms of management • All are HIPAA eligible and PCI compliant • All support fine grained permissions via AWS IAM • All have a pay as you go model without commitments
  78. © 2021, Amazon Web Services, Inc. or its affiliates. Summary

    There are many ways to get data between microservices! • Kinesis, SNS, SQS, EventBridge, and the Lambda API are just a few of the ways. Orchestrate with Step Functions. • You *might* need an API that you create yourself. • Think through the factor comparisons on scale, durability, persistence, consumption models, retries, and pricing. • You will probably end up needing more than one and potentially end up using each of these in some part of your infrastructure. • Evaluate and test using AWS SAM CLI. • Serverless pricing models make testing new ideas low cost and easy to get started with!
  79. © 2021, Amazon Web Services, Inc. or its affiliates. ©

    2021, Amazon Web Services, Inc. or its affiliates. 83 Serverlessland.com Serverlessland.com
  80. © 2021, Amazon Web Services, Inc. or its affiliates. Merci!

    © 2021, Amazon Web Services, Inc. or its affiliates. 85 @julian_wood Slides available at: s12d.com/SDaysParis21 @julian_wood