Slide 1

Slide 1 text

© 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

Slide 2

Slide 2 text

© 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

Slide 3

Slide 3 text

© 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

Slide 4

Slide 4 text

© 2021, Amazon Web Services, Inc. or its affiliates. Event-driven compute Functions as a service Serverless FaaS

Slide 5

Slide 5 text

© 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.

Slide 6

Slide 6 text

© 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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

© 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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

© 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

Slide 14

Slide 14 text

© 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

Slide 15

Slide 15 text

© 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

Slide 16

Slide 16 text

© 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

Slide 17

Slide 17 text

© 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

Slide 18

Slide 18 text

© 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

Slide 19

Slide 19 text

© 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

Slide 20

Slide 20 text

© 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

Slide 21

Slide 21 text

© 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

Slide 22

Slide 22 text

© 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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

© 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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

© 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.

Slide 28

Slide 28 text

© 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

Slide 29

Slide 29 text

© 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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

© 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

Slide 32

Slide 32 text

© 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.

Slide 33

Slide 33 text

© 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

Slide 34

Slide 34 text

© 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

Slide 35

Slide 35 text

© 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)

Slide 36

Slide 36 text

© 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

Slide 37

Slide 37 text

© 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

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

© 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)

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

© 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

Slide 43

Slide 43 text

© 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

Slide 44

Slide 44 text

© 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

Slide 45

Slide 45 text

© 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

Slide 46

Slide 46 text

© 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)

Slide 47

Slide 47 text

© 2021, Amazon Web Services, Inc. or its affiliates. © 2021, Amazon Web Services, Inc. or its affiliates. Combining messaging patterns

Slide 48

Slide 48 text

© 2021, Amazon Web Services, Inc. or its affiliates. Topic-queue-chaining

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

© 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

Slide 51

Slide 51 text

© 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

Slide 52

Slide 52 text

© 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

Slide 53

Slide 53 text

© 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)

Slide 54

Slide 54 text

© 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

Slide 55

Slide 55 text

© 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

Slide 56

Slide 56 text

© 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

Slide 57

Slide 57 text

© 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

Slide 58

Slide 58 text

© 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

Slide 59

Slide 59 text

© 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

Slide 60

Slide 60 text

© 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

Slide 61

Slide 61 text

© 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

Slide 62

Slide 62 text

© 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

Slide 63

Slide 63 text

© 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

Slide 64

Slide 64 text

© 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

Slide 65

Slide 65 text

© 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

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

© 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

Slide 68

Slide 68 text

© 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

Slide 69

Slide 69 text

© 2021, Amazon Web Services, Inc. or its affiliates. Saga orchestration

Slide 70

Slide 70 text

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

Slide 71

Slide 71 text

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

Slide 72

Slide 72 text

© 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

Slide 73

Slide 73 text

© 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

Slide 74

Slide 74 text

© 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

Slide 75

Slide 75 text

© 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

Slide 76

Slide 76 text

© 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

Slide 77

Slide 77 text

© 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

Slide 78

Slide 78 text

© 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

Slide 79

Slide 79 text

© 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

Slide 80

Slide 80 text

© 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?

Slide 81

Slide 81 text

© 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

Slide 82

Slide 82 text

© 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!

Slide 83

Slide 83 text

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

Slide 84

Slide 84 text

© 2021, Amazon Web Services, Inc. or its affiliates. Serverless Patterns Collection

Slide 85

Slide 85 text

© 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