AWS 19 - AWS Intergration & Messaging SQS, SNS & Kinesis

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/23

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

24 Terms

1
New cards

Integration & Messaging between services in AWS

• Synchronous between applications can be problematic if there are sudden spikes of traffic

• What if you need to suddenly encode 1000 videos but usually it’s 10?

• In that case, it’s better to decouple your applications,

• using SQS: queue model • using SNS: pub/sub model

• using Kinesis: real-time streaming model

• These services can scale independently from our application!

<p>• Synchronous between applications can be problematic if there are sudden spikes of traffic </p><p>• What if you need to suddenly encode 1000 videos but usually it’s 10? </p><p>• In that case, it’s better to decouple your applications, </p><p>• using SQS: queue model • using SNS: pub/sub model </p><p>• using Kinesis: real-time streaming model </p><p>• These services can scale independently from our application!</p>
2
New cards

AWS SQS

The best way to think of SQS is as a highly durable, scalable to-do list for your distributed applications.

  • Core Function: It provides a hosted queue for storing messages (tasks, jobs, data) as they travel between different parts of your application.

  • Decoupling: SQS is the ultimate tool for decoupling. Instead of one service calling another directly (synchronously), the first service just drops a message into the SQS queue and moves on. The second service picks up the message when it's ready.

  • Scalability & Resilience:

    • If a service suddenly gets swamped (like that $1000$ video-encode spike), the messages pile up safely in the queue. The processing service can then scale up (via Auto Scaling) to empty the queue.

    • If the processing service completely fails, the messages remain safely stored in SQS across multiple AWS servers, waiting to be picked up later, guaranteeing no data loss.

  • Fully Managed: AWS handles all the hard parts of traditional message systems, including hardware provisioning, maintenance, and scaling—it's essentially limitless.

SQS Queue Types:

  1. Standard Queue (Default): Offers maximum throughput and guarantees at least once message delivery (duplicates are possible but rare) and best-effort ordering.

  2. FIFO Queue (First-In, First-Out): Guarantees that messages are processed exactly once and in the exact order they were sent. This is crucial for things like financial transactions where sequence is non-negotiable.

<p>The best way to think of SQS is as a <strong>highly durable, scalable to-do list</strong> for your distributed applications.</p><ul><li><p><strong>Core Function:</strong> It provides a hosted <strong>queue</strong> for storing messages (tasks, jobs, data) as they travel between different parts of your application.</p></li><li><p><strong>Decoupling:</strong> SQS is the ultimate tool for decoupling. Instead of one service calling another directly (synchronously), the first service just drops a message into the SQS queue and moves on. The second service picks up the message when it's ready.</p></li><li><p><strong>Scalability &amp; Resilience:</strong></p><ul><li><p>If a service suddenly gets swamped (like that <span><span>$1000$</span></span> video-encode spike), the messages pile up safely in the queue. The processing service can then scale up (via Auto Scaling) to empty the queue.</p></li><li><p>If the processing service completely fails, the messages remain safely stored in SQS across multiple AWS servers, waiting to be picked up later, guaranteeing no data loss.</p></li></ul></li><li><p><strong>Fully Managed:</strong> AWS handles all the hard parts of traditional message systems, including hardware provisioning, maintenance, and scaling—it's essentially limitless.</p></li></ul><p></p><p>SQS Queue Types:</p><ol><li><p><strong>Standard Queue (Default):</strong> Offers maximum throughput and guarantees <strong>at least once</strong> message delivery (duplicates are possible but rare) and <strong>best-effort ordering</strong>.</p></li><li><p><strong>FIFO Queue (First-In, First-Out):</strong> Guarantees that messages are processed <strong>exactly once</strong> and in the <strong>exact order</strong> they were sent. This is crucial for things like financial transactions where sequence is non-negotiable.</p></li></ol><p></p>
3
New cards

SQS - Standard Queue - Producing messages

Standard Queue (Default): Offers maximum throughput and guarantees at least once message delivery (duplicates are possible but rare) and best-effort ordering.

• Oldest offering (over 10 years old)

• Fully managed service, used to decouple applications

• Attributes: • Unlimited throughput, unlimited number of messages in queue

• Default retention of messages: 4 days, maximum of 14 days

• Low latency (<10 ms o n publish and receive) • Limitation of 256KB per message sent

• Can have duplicate messages (at least once delivery, occasionally)

• Can have out of order messages (best effort ordering)

<p><strong>Standard Queue (Default):</strong> Offers maximum throughput and guarantees <strong>at least once</strong> message delivery (duplicates are possible but rare) and <strong>best-effort ordering</strong>.</p><p></p><p>• Oldest offering (over 10 years old) </p><p>• Fully managed service, used to decouple applications </p><p>• Attributes: • Unlimited throughput, unlimited number of messages in queue </p><p>• Default retention of messages: 4 days, maximum of 14 days </p><p>• Low latency (&lt;10 ms o n publish and receive) • Limitation of 256KB per message sent </p><p>• Can have duplicate messages (at least once delivery, occasionally) </p><p>• Can have out of order messages (best effort ordering)</p><p></p>
4
New cards

SQS - Standard Queue - Consuming messages & Multiple EC2 Instances Consumers

Multiple EC2 instances consumers
  • Consumers receive and process messages in parallel: Instead of one single machine being overwhelmed, multiple EC2 instances (the "consumers") are constantly pulling messages from the queue. This is the core principle of horizontal scaling for processing tasks.

  • At least once delivery: Since the queue is designed for massive scale and speed, it can't guarantee a message will be delivered exactly once. It promises at least one delivery, meaning that under rare conditions (like a consumer failing just before it deletes a message), the same message might be received and processed twice.

<img src="https://knowt-user-attachments.s3.amazonaws.com/1901296c-8163-4cdd-8711-89d64a452eb3.png" data-width="75%" data-align="center" alt="Multiple EC2 instances consumers"><ul><li><p><strong>Consumers receive and process messages in parallel:</strong> Instead of one single machine being overwhelmed, multiple EC2 instances (the "consumers") are constantly pulling messages from the queue. This is the core principle of horizontal scaling for processing tasks.</p></li><li><p><strong>At least once delivery:</strong> Since the queue is designed for massive scale and speed, it can't guarantee a message will be delivered <em>exactly</em> once. It promises <strong>at least one</strong> delivery, meaning that under rare conditions (like a consumer failing just before it deletes a message), the same message might be received and processed twice.</p></li></ul><p></p>
5
New cards
<p>SQS with Auto-Scaling Group (ASG)</p>

SQS with Auto-Scaling Group (ASG)

  1. The SQS Queue (The Waiting Line):

  • The SQS Queue receives incoming tasks (messages) from the producer application.

  • The EC2 Instances within the ASG constantly poll the queue, grabbing and processing these messages.

  • CloudWatch Metric (The Measurement):

    • AWS CloudWatch tracks the ApproximateNumberOfMessages in the SQS Queue. This is the key performance indicator (KPI) that tells you how much work is currently waiting.

  1. CloudWatch Alarm (The Trigger):

  • A CloudWatch Alarm is set to monitor this metric.

  • If the number of waiting messages crosses a certain threshold (a "breach," such as more than 100 messages waiting for five minutes), the alarm is triggered.

  1. Auto Scaling Group (The Workforce Manager):

  • The CloudWatch Alarm sends a "scale" signal directly to the Auto Scaling Group.

  • The ASG immediately launches new EC2 Instances (more consumers) to help empty the queue faster. When the queue length drops back down, the ASG will terminate the excess instances to save costs.

<ol><li><p><strong>The SQS Queue (The Waiting Line):</strong></p></li></ol><ul><li><p>The SQS Queue receives incoming tasks (messages) from the producer application.</p></li><li><p>The <strong>EC2 Instances</strong> within the ASG constantly <strong>poll</strong> the queue, grabbing and processing these messages.</p></li></ul><ul><li><p><strong>CloudWatch Metric (The Measurement):</strong></p><ul><li><p>AWS CloudWatch tracks the <code>ApproximateNumberOfMessages</code> in the SQS Queue. This is the key performance indicator (KPI) that tells you how much work is currently waiting.</p></li></ul></li></ul><ol start="2"><li><p><strong>CloudWatch Alarm (The Trigger):</strong></p></li></ol><ul><li><p>A CloudWatch Alarm is set to monitor this metric.</p></li><li><p>If the number of waiting messages crosses a certain threshold (a "breach," such as more than 100 messages waiting for five minutes), the alarm is triggered.</p></li></ul><ol start="3"><li><p><strong>Auto Scaling Group (The Workforce Manager):</strong></p></li></ol><ul><li><p>The CloudWatch Alarm sends a "scale" signal directly to the Auto Scaling Group.</p></li><li><p>The ASG immediately launches new <strong>EC2 Instances</strong> (more consumers) to help empty the queue faster. When the queue length drops back down, the ASG will terminate the excess instances to save costs.</p></li></ul><img src="https://knowt-user-attachments.s3.amazonaws.com/024ca247-2a40-4ea2-8dc3-279f416450b2.png" data-width="50%" data-align="center" alt=""><p></p>
6
New cards

SQS Queue Access Policies

While AWS IAM Roles and User Policies handle access for principals within your own account, SQS Queue Policies are essential for controlling cross-account and cross-service communication.

Policy Use Case

Explanation

Real-World Example

Cross-Account Access

Allows an AWS account different from the one the queue is in to send or receive messages.

A development account sends test messages to a QA account's queue.

Cross-Service Access

Allows another AWS service (like SNS or EventBridge) to push messages into your SQS queue.

You must use a Queue Policy to allow an Amazon SNS Topic to publish notifications to your SQS queue.

IP-Based Filtering

Restricts which IP addresses or VPC endpoints are allowed to interact with the queue.

Limits message consumption only to EC2 instances running within a specific VPC for security.

Denial (Least Privilege)

Explicitly denies an action to certain principals, even if they might have a broad Allow from another IAM policy.

Prevent a specific testing role from accidentally deleting messages (SQS:DeleteMessage) from a production queue.

In most microservice architectures, you will use a Queue Policy to grant permission to an SNS Topic to write messages to the queue. Without t his specific policy, the service-to-service communication will fail.

<p>While AWS IAM Roles and User Policies handle access for principals <em>within your own account</em>, SQS Queue Policies are essential for controlling <strong>cross-account</strong> and <strong>cross-service</strong> communication.</p><table style="min-width: 75px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><td colspan="1" rowspan="1" style="animation: 0s ease 0s 1 normal none running none; appearance: none; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(239, 239, 239); border: 1px solid; inset: auto; clear: none; clip: auto; columns: auto; contain: none; container: none; content: normal; cursor: auto; cx: 0px; cy: 0px; d: none; direction: ltr; display: table-cell; fill: rgb(0, 0, 0); filter: none; flex: 0 1 auto; float: none; gap: normal; hyphens: manual; interactivity: auto; isolation: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; marker: none; mask: none; offset: normal; opacity: 1; order: 0; orphans: 2; outline: rgb(27, 28, 29) none 0px; overlay: none; padding: 8px 12px; page: auto; perspective: none; position: static; quotes: auto; r: 0px; resize: none; rotate: none; rx: auto; ry: auto; scale: none; speak: normal; stroke: none; transform: none; transition: all; translate: none; visibility: visible; widows: 2; x: 0px; y: 0px; zoom: 1; margin-top: 0px !important;"><p><strong>Policy Use Case</strong></p></td><td colspan="1" rowspan="1" style="animation: 0s ease 0s 1 normal none running none; appearance: none; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(239, 239, 239); border: 1px solid; inset: auto; clear: none; clip: auto; columns: auto; contain: none; container: none; content: normal; cursor: auto; cx: 0px; cy: 0px; d: none; direction: ltr; display: table-cell; fill: rgb(0, 0, 0); filter: none; flex: 0 1 auto; float: none; gap: normal; hyphens: manual; interactivity: auto; isolation: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; marker: none; mask: none; offset: normal; opacity: 1; order: 0; orphans: 2; outline: rgb(27, 28, 29) none 0px; overlay: none; padding: 8px 12px; page: auto; perspective: none; position: static; quotes: auto; r: 0px; resize: none; rotate: none; rx: auto; ry: auto; scale: none; speak: normal; stroke: none; transform: none; transition: all; translate: none; visibility: visible; widows: 2; x: 0px; y: 0px; zoom: 1; margin-top: 0px !important;"><p><strong>Explanation</strong></p></td><td colspan="1" rowspan="1" style="animation: 0s ease 0s 1 normal none running none; appearance: none; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(239, 239, 239); border: 1px solid; inset: auto; clear: none; clip: auto; columns: auto; contain: none; container: none; content: normal; cursor: auto; cx: 0px; cy: 0px; d: none; direction: ltr; display: table-cell; fill: rgb(0, 0, 0); filter: none; flex: 0 1 auto; float: none; gap: normal; hyphens: manual; interactivity: auto; isolation: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; marker: none; mask: none; offset: normal; opacity: 1; order: 0; orphans: 2; outline: rgb(27, 28, 29) none 0px; overlay: none; padding: 8px 12px; page: auto; perspective: none; position: static; quotes: auto; r: 0px; resize: none; rotate: none; rx: auto; ry: auto; scale: none; speak: normal; stroke: none; transform: none; transition: all; translate: none; visibility: visible; widows: 2; x: 0px; y: 0px; zoom: 1; margin-top: 0px !important;"><p><strong>Real-World Example</strong></p></td></tr><tr><td colspan="1" rowspan="1" style="animation: 0s ease 0s 1 normal none running none; appearance: none; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); border: 1px solid; inset: auto; clear: none; clip: auto; columns: auto; contain: none; container: none; content: normal; cursor: auto; cx: 0px; cy: 0px; d: none; direction: ltr; display: table-cell; fill: rgb(0, 0, 0); filter: none; flex: 0 1 auto; float: none; gap: normal; hyphens: manual; interactivity: auto; isolation: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; marker: none; mask: none; offset: normal; opacity: 1; order: 0; orphans: 2; outline: rgb(27, 28, 29) none 0px; overlay: none; padding: 8px 12px; page: auto; perspective: none; position: static; quotes: auto; r: 0px; resize: none; rotate: none; rx: auto; ry: auto; scale: none; speak: normal; stroke: none; transform: none; transition: all; translate: none; visibility: visible; widows: 2; x: 0px; y: 0px; zoom: 1; margin-top: 0px !important;"><p><strong>Cross-Account Access</strong></p></td><td colspan="1" rowspan="1" style="animation: 0s ease 0s 1 normal none running none; appearance: none; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); border: 1px solid; inset: auto; clear: none; clip: auto; columns: auto; contain: none; container: none; content: normal; cursor: auto; cx: 0px; cy: 0px; d: none; direction: ltr; display: table-cell; fill: rgb(0, 0, 0); filter: none; flex: 0 1 auto; float: none; gap: normal; hyphens: manual; interactivity: auto; isolation: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; marker: none; mask: none; offset: normal; opacity: 1; order: 0; orphans: 2; outline: rgb(27, 28, 29) none 0px; overlay: none; padding: 8px 12px; page: auto; perspective: none; position: static; quotes: auto; r: 0px; resize: none; rotate: none; rx: auto; ry: auto; scale: none; speak: normal; stroke: none; transform: none; transition: all; translate: none; visibility: visible; widows: 2; x: 0px; y: 0px; zoom: 1; margin-top: 0px !important;"><p>Allows an AWS account <em>different</em> from the one the queue is in to send or receive messages.</p></td><td colspan="1" rowspan="1" style="animation: 0s ease 0s 1 normal none running none; appearance: none; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); border: 1px solid; inset: auto; clear: none; clip: auto; columns: auto; contain: none; container: none; content: normal; cursor: auto; cx: 0px; cy: 0px; d: none; direction: ltr; display: table-cell; fill: rgb(0, 0, 0); filter: none; flex: 0 1 auto; float: none; gap: normal; hyphens: manual; interactivity: auto; isolation: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; marker: none; mask: none; offset: normal; opacity: 1; order: 0; orphans: 2; outline: rgb(27, 28, 29) none 0px; overlay: none; padding: 8px 12px; page: auto; perspective: none; position: static; quotes: auto; r: 0px; resize: none; rotate: none; rx: auto; ry: auto; scale: none; speak: normal; stroke: none; transform: none; transition: all; translate: none; visibility: visible; widows: 2; x: 0px; y: 0px; zoom: 1; margin-top: 0px !important;"><p>A development account sends test messages to a QA account's queue.</p></td></tr><tr><td colspan="1" rowspan="1" style="animation: 0s ease 0s 1 normal none running none; appearance: none; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); border: 1px solid; inset: auto; clear: none; clip: auto; columns: auto; contain: none; container: none; content: normal; cursor: auto; cx: 0px; cy: 0px; d: none; direction: ltr; display: table-cell; fill: rgb(0, 0, 0); filter: none; flex: 0 1 auto; float: none; gap: normal; hyphens: manual; interactivity: auto; isolation: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; marker: none; mask: none; offset: normal; opacity: 1; order: 0; orphans: 2; outline: rgb(27, 28, 29) none 0px; overlay: none; padding: 8px 12px; page: auto; perspective: none; position: static; quotes: auto; r: 0px; resize: none; rotate: none; rx: auto; ry: auto; scale: none; speak: normal; stroke: none; transform: none; transition: all; translate: none; visibility: visible; widows: 2; x: 0px; y: 0px; zoom: 1; margin-top: 0px !important;"><p><strong>Cross-Service Access</strong></p></td><td colspan="1" rowspan="1" style="animation: 0s ease 0s 1 normal none running none; appearance: none; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); border: 1px solid; inset: auto; clear: none; clip: auto; columns: auto; contain: none; container: none; content: normal; cursor: auto; cx: 0px; cy: 0px; d: none; direction: ltr; display: table-cell; fill: rgb(0, 0, 0); filter: none; flex: 0 1 auto; float: none; gap: normal; hyphens: manual; interactivity: auto; isolation: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; marker: none; mask: none; offset: normal; opacity: 1; order: 0; orphans: 2; outline: rgb(27, 28, 29) none 0px; overlay: none; padding: 8px 12px; page: auto; perspective: none; position: static; quotes: auto; r: 0px; resize: none; rotate: none; rx: auto; ry: auto; scale: none; speak: normal; stroke: none; transform: none; transition: all; translate: none; visibility: visible; widows: 2; x: 0px; y: 0px; zoom: 1; margin-top: 0px !important;"><p>Allows another AWS service (like SNS or EventBridge) to push messages <em>into</em> your SQS queue.</p></td><td colspan="1" rowspan="1" style="animation: 0s ease 0s 1 normal none running none; appearance: none; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); border: 1px solid; inset: auto; clear: none; clip: auto; columns: auto; contain: none; container: none; content: normal; cursor: auto; cx: 0px; cy: 0px; d: none; direction: ltr; display: table-cell; fill: rgb(0, 0, 0); filter: none; flex: 0 1 auto; float: none; gap: normal; hyphens: manual; interactivity: auto; isolation: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; marker: none; mask: none; offset: normal; opacity: 1; order: 0; orphans: 2; outline: rgb(27, 28, 29) none 0px; overlay: none; padding: 8px 12px; page: auto; perspective: none; position: static; quotes: auto; r: 0px; resize: none; rotate: none; rx: auto; ry: auto; scale: none; speak: normal; stroke: none; transform: none; transition: all; translate: none; visibility: visible; widows: 2; x: 0px; y: 0px; zoom: 1; margin-top: 0px !important;"><p>You must use a Queue Policy to allow an <strong>Amazon SNS Topic</strong> to publish notifications to your SQS queue.</p></td></tr><tr><td colspan="1" rowspan="1" style="animation: 0s ease 0s 1 normal none running none; appearance: none; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); border: 1px solid; inset: auto; clear: none; clip: auto; columns: auto; contain: none; container: none; content: normal; cursor: auto; cx: 0px; cy: 0px; d: none; direction: ltr; display: table-cell; fill: rgb(0, 0, 0); filter: none; flex: 0 1 auto; float: none; gap: normal; hyphens: manual; interactivity: auto; isolation: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; marker: none; mask: none; offset: normal; opacity: 1; order: 0; orphans: 2; outline: rgb(27, 28, 29) none 0px; overlay: none; padding: 8px 12px; page: auto; perspective: none; position: static; quotes: auto; r: 0px; resize: none; rotate: none; rx: auto; ry: auto; scale: none; speak: normal; stroke: none; transform: none; transition: all; translate: none; visibility: visible; widows: 2; x: 0px; y: 0px; zoom: 1; margin-top: 0px !important;"><p><strong>IP-Based Filtering</strong></p></td><td colspan="1" rowspan="1" style="animation: 0s ease 0s 1 normal none running none; appearance: none; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); border: 1px solid; inset: auto; clear: none; clip: auto; columns: auto; contain: none; container: none; content: normal; cursor: auto; cx: 0px; cy: 0px; d: none; direction: ltr; display: table-cell; fill: rgb(0, 0, 0); filter: none; flex: 0 1 auto; float: none; gap: normal; hyphens: manual; interactivity: auto; isolation: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; marker: none; mask: none; offset: normal; opacity: 1; order: 0; orphans: 2; outline: rgb(27, 28, 29) none 0px; overlay: none; padding: 8px 12px; page: auto; perspective: none; position: static; quotes: auto; r: 0px; resize: none; rotate: none; rx: auto; ry: auto; scale: none; speak: normal; stroke: none; transform: none; transition: all; translate: none; visibility: visible; widows: 2; x: 0px; y: 0px; zoom: 1; margin-top: 0px !important;"><p>Restricts which IP addresses or VPC endpoints are allowed to interact with the queue.</p></td><td colspan="1" rowspan="1" style="animation: 0s ease 0s 1 normal none running none; appearance: none; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); border: 1px solid; inset: auto; clear: none; clip: auto; columns: auto; contain: none; container: none; content: normal; cursor: auto; cx: 0px; cy: 0px; d: none; direction: ltr; display: table-cell; fill: rgb(0, 0, 0); filter: none; flex: 0 1 auto; float: none; gap: normal; hyphens: manual; interactivity: auto; isolation: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; marker: none; mask: none; offset: normal; opacity: 1; order: 0; orphans: 2; outline: rgb(27, 28, 29) none 0px; overlay: none; padding: 8px 12px; page: auto; perspective: none; position: static; quotes: auto; r: 0px; resize: none; rotate: none; rx: auto; ry: auto; scale: none; speak: normal; stroke: none; transform: none; transition: all; translate: none; visibility: visible; widows: 2; x: 0px; y: 0px; zoom: 1; margin-top: 0px !important;"><p>Limits message consumption only to EC2 instances running within a specific VPC for security.</p></td></tr><tr><td colspan="1" rowspan="1" style="animation: 0s ease 0s 1 normal none running none; appearance: none; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); border: 1px solid; inset: auto; clear: none; clip: auto; columns: auto; contain: none; container: none; content: normal; cursor: auto; cx: 0px; cy: 0px; d: none; direction: ltr; display: table-cell; fill: rgb(0, 0, 0); filter: none; flex: 0 1 auto; float: none; gap: normal; hyphens: manual; interactivity: auto; isolation: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; marker: none; mask: none; offset: normal; opacity: 1; order: 0; orphans: 2; outline: rgb(27, 28, 29) none 0px; overlay: none; padding: 8px 12px; page: auto; perspective: none; position: static; quotes: auto; r: 0px; resize: none; rotate: none; rx: auto; ry: auto; scale: none; speak: normal; stroke: none; transform: none; transition: all; translate: none; visibility: visible; widows: 2; x: 0px; y: 0px; zoom: 1; margin-top: 0px !important;"><p><strong>Denial (Least Privilege)</strong></p></td><td colspan="1" rowspan="1" style="animation: 0s ease 0s 1 normal none running none; appearance: none; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); border: 1px solid; inset: auto; clear: none; clip: auto; columns: auto; contain: none; container: none; content: normal; cursor: auto; cx: 0px; cy: 0px; d: none; direction: ltr; display: table-cell; fill: rgb(0, 0, 0); filter: none; flex: 0 1 auto; float: none; gap: normal; hyphens: manual; interactivity: auto; isolation: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; marker: none; mask: none; offset: normal; opacity: 1; order: 0; orphans: 2; outline: rgb(27, 28, 29) none 0px; overlay: none; padding: 8px 12px; page: auto; perspective: none; position: static; quotes: auto; r: 0px; resize: none; rotate: none; rx: auto; ry: auto; scale: none; speak: normal; stroke: none; transform: none; transition: all; translate: none; visibility: visible; widows: 2; x: 0px; y: 0px; zoom: 1; margin-top: 0px !important;"><p>Explicitly denies an action to certain principals, even if they might have a broad <code>Allow</code> from another IAM policy.</p></td><td colspan="1" rowspan="1" style="animation: 0s ease 0s 1 normal none running none; appearance: none; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); border: 1px solid; inset: auto; clear: none; clip: auto; columns: auto; contain: none; container: none; content: normal; cursor: auto; cx: 0px; cy: 0px; d: none; direction: ltr; display: table-cell; fill: rgb(0, 0, 0); filter: none; flex: 0 1 auto; float: none; gap: normal; hyphens: manual; interactivity: auto; isolation: auto; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; marker: none; mask: none; offset: normal; opacity: 1; order: 0; orphans: 2; outline: rgb(27, 28, 29) none 0px; overlay: none; padding: 8px 12px; page: auto; perspective: none; position: static; quotes: auto; r: 0px; resize: none; rotate: none; rx: auto; ry: auto; scale: none; speak: normal; stroke: none; transform: none; transition: all; translate: none; visibility: visible; widows: 2; x: 0px; y: 0px; zoom: 1; margin-top: 0px !important;"><p>Prevent a specific testing role from accidentally deleting messages (<code>SQS:DeleteMessage</code>) from a production queue.</p></td></tr></tbody></table><p>In most microservice architectures, you will use a Queue Policy to grant permission to an SNS Topic to write messages to the queue. Without t his specific policy, the service-to-service communication will fail.</p>
7
New cards

Message Visibility Timeout

The Message Visibility Timeout is a temporary invisibility setting applied to a message once it has been retrieved by a consumer. Its main job is to prevent duplicate processing.

. If a message is not processed within the visibility timeout, it will be processed twice

. A consumer could call the ChangeMessageVisibility API to get more time

. If visibility timeout is high (hours), and consumer crashes, re-processing will take time

. If visibility timeout is too low (seconds), we may get duplicates

<p>The <strong>Message Visibility Timeout</strong> is a temporary invisibility setting applied to a message once it has been retrieved by a consumer. Its main job is to prevent duplicate processing.</p><p></p><p>. If a message is not processed within the visibility timeout, it will be processed twice</p><p>. A consumer could call the ChangeMessageVisibility API to get more time</p><p>. If visibility timeout is high (hours), and consumer crashes, re-processing will take time</p><p>. If visibility timeout is too low (seconds), we may get duplicates</p>
8
New cards

AWS SQS - Dead Letter Queue (DLQ)

  • If a consumer fails to process a message within the Visibility Timeout, the message goes back to the queue!

. We can set a threshold of how many times a message can go back to the queue

. After the MaximumReceives threshold is exceeded, the message goes into a dead letter queue (DLQ)

· Useful for debugging!

. DLQ of a FIFO queue must also be a FIFO queue

. DLQ of a Standard queue must also be a Standard queue

  • Make sure to process the messages in the DLQ before they expire:

    • Good to set a retention of 14 days in the DLQ

<ul><li><p>If a consumer fails to process a message within the Visibility Timeout, the message goes back to the queue!</p></li></ul><p>. We can set a threshold of how many times a message can go back to the queue</p><p>. After the MaximumReceives threshold is exceeded, the message goes into a dead letter queue (DLQ)</p><p>· Useful for debugging!</p><p>. DLQ of a FIFO queue must also be a FIFO queue</p><p>. DLQ of a Standard queue must also be a Standard queue</p><ul><li><p>Make sure to process the messages in the DLQ before they expire:</p><ul><li><p>Good to set a retention of 14 days in the DLQ</p></li></ul></li></ul><img src="https://knowt-user-attachments.s3.amazonaws.com/0fc2b3e6-e4b2-46b2-b0f1-098093882112.png" data-width="75%" data-align="center" alt=""><p></p>
9
New cards

AWS SQS - Delay Queue

An SQS Delay Queue (or the DelaySeconds setting) is used to intentionally postpone when a message is first made available to a consumer.

Common Use Cases for Delay Queues:

  • Rate Limiting: If an external API you call can only handle 10 requests per second, you can set a delay on your SQS queue to throttle the rate at which your consumers receive tasks.

  • Initial Consistency: In distributed systems, you might need a brief delay to ensure a newly written record in a database is fully replicated before a consumer tries to read it.

  • Batch Processing Warm-up: Delaying the start of a large processing job until a specific time or until related resources are spun up.

<p>An SQS <strong>Delay Queue</strong> (or the <strong>DelaySeconds</strong> setting) is used to intentionally postpone when a message is first made available to a consumer.</p><p><strong>Common Use Cases for Delay Queues:</strong></p><ul><li><p><strong>Rate Limiting:</strong> If an external API you call can only handle 10 requests per second, you can set a delay on your SQS queue to throttle the rate at which your consumers receive tasks.</p></li><li><p><strong>Initial Consistency:</strong> In distributed systems, you might need a brief delay to ensure a newly written record in a database is fully replicated before a consumer tries to read it.</p></li><li><p><strong>Batch Processing Warm-up:</strong> Delaying the start of a large processing job until a specific time or until related resources are spun up.</p></li></ul><p></p>
10
New cards
<p>AWS SQS - Long polling &amp; SQS Extended Client</p>

AWS SQS - Long polling & SQS Extended Client

knowt flashcard image

SQS Extended Client:

  • It's a Library, Not a Service: It's an open-source client library for languages like Java and Python, not an AWS service you provision. It acts as an abstraction layer over the standard SQS and S3 APIs.

  • The S3 Dance: The library handles the entire lifecycle: uploading the large file to S3 on the producer side, and downloading and deleting it from S3 on the consumer side (once the SQS message is successfully deleted).

  • Why Use It? It lets developers send large media, complex documents, or large log files via SQS without having to write the boilerplate code for managing S3 upload/download/cleanup themselves.

<img src="https://knowt-user-attachments.s3.amazonaws.com/5b5316c4-d562-4649-845c-fc43058c9769.png" data-width="75%" data-align="center" alt="knowt flashcard image"><p>SQS Extended Client:</p><ul><li><p><strong>It's a Library, Not a Service:</strong> It's an open-source client library for languages like Java and Python, not an AWS service you provision. It acts as an abstraction layer over the standard SQS and S3 APIs.</p></li><li><p><strong>The S3 Dance:</strong> The library handles the entire lifecycle: uploading the large file to S3 on the producer side, and downloading and deleting it from S3 on the consumer side (once the SQS message is successfully deleted).</p></li><li><p><strong>Why Use It?</strong> It lets developers send large media, complex documents, or large log files via SQS without having to write the boilerplate code for managing S3 upload/download/cleanup themselves.</p></li></ul><p></p>
11
New cards

AWS SQS - Must know API

SQS - Must know API

. CreateQueue (MessageRetentionPeriod), DeleteQueue

. PurgeQueue: delete all the messages in queue

· SendMessage (DelaySeconds), ReceiveMessage, DeleteMessage

. MaxNumberOfMessages: default I, max 10 (for ReceiveMessage API)

. ReceiveMessageWaitTimeSeconds: Long Polling

. ChangeMessageVisibility: change the message timeout

. Batch APIs for SendMessage, DeleteMessage, ChangeMessageVisibility helps decrease your costs

<p>SQS - Must know API</p><p>. CreateQueue (MessageRetentionPeriod), DeleteQueue</p><p>. PurgeQueue: delete all the messages in queue</p><p>· SendMessage (DelaySeconds), ReceiveMessage, DeleteMessage</p><p>. MaxNumberOfMessages: default I, max 10 (for ReceiveMessage API)</p><p>. ReceiveMessageWaitTimeSeconds: Long Polling</p><p>. ChangeMessageVisibility: change the message timeout</p><p>. Batch APIs for SendMessage, DeleteMessage, ChangeMessageVisibility helps decrease your costs</p>
12
New cards

AWS SQS - FIFO Queue

Unlike Standard queue which sends messages to the consumers randomly

<p>Unlike Standard queue which sends messages to the consumers randomly </p>
13
New cards

AWS SQS - FIFO Queues Advanced - Deduplication

Deduplication is the process of eliminating redundant or identical copies of data.

In the context of AWS messaging services, particularly Amazon SQS, it has a very specific meaning:

Context

Deduplication Goal

How it Works

General Storage (e.g., S3)

Saves space and cost by ensuring only one unique copy of a file or data block is stored.

If 10,000 users upload the exact same image file, the storage system only keeps one copy and points all users to it.

SQS (FIFO Queues)

Ensures a message is processed Exactly-Once.

The message producer provides a unique Deduplication ID (or the content itself is used). If a second message with the exact same ID is sent within a 5-minute window, SQS rejects the duplicate message.

Why SQS Needs Deduplication?

The SQS Standard Queue guarantees "At Least Once Delivery," meaning you might occasionally get duplicate messages (for instance, if a consumer receives a message but crashes before deleting it).

The SQS FIFO Queue uses the Deduplication feature to solve this problem, ensuring the message is processed only once, which is vital for use cases like financial transactions and order processing.

<p><strong>Deduplication</strong> is the process of eliminating redundant or identical copies of data.</p><p>In the context of AWS messaging services, particularly <strong>Amazon SQS</strong>, it has a very specific meaning:</p><table style="min-width: 75px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>Context</strong></p></td><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>Deduplication Goal</strong></p></td><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>How it Works</strong></p></td></tr><tr><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>General Storage (e.g., S3)</strong></p></td><td colspan="1" rowspan="1" style="border: 1px solid;"><p>Saves space and cost by ensuring only one unique copy of a file or data block is stored.</p></td><td colspan="1" rowspan="1" style="border: 1px solid;"><p>If 10,000 users upload the exact same image file, the storage system only keeps one copy and points all users to it.</p></td></tr><tr><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>SQS (FIFO Queues)</strong></p></td><td colspan="1" rowspan="1" style="border: 1px solid;"><p>Ensures a message is processed <strong>Exactly-Once</strong>.</p></td><td colspan="1" rowspan="1" style="border: 1px solid;"><p>The message producer provides a unique <strong>Deduplication ID</strong> (or the content itself is used). If a second message with the exact same ID is sent within a 5-minute window, SQS rejects the duplicate message.</p></td></tr></tbody></table><p><strong>Why SQS Needs Deduplication?</strong></p><p>The <strong>SQS Standard Queue</strong> guarantees <strong>"At Least Once Delivery,"</strong> meaning you might occasionally get duplicate messages (for instance, if a consumer receives a message but crashes before deleting it).</p><p>The <strong>SQS FIFO Queue</strong> uses the Deduplication feature to solve this problem, ensuring the message is processed only once, which is vital for use cases like financial transactions and order processing.</p>
14
New cards
<p>AWS SQS - FIFO Queues Advanced -  Message Grouping</p>

AWS SQS - FIFO Queues Advanced - Message Grouping

SQS FIFO Message Grouping Explained

Think of it like a meticulous, digital post office that only delivers letters in the exact order they arrived... unless you've marked them with a special group ID.

  • The Golden Rule (for strict ordering):

    • If you set the MessageGroupID to the same value for every message in the queue, then all messages are processed in strict FIFO order, but you can only have one consumer working on the queue. Slow, but perfectly sequential!

  • The Clever Hack (for parallel, yet ordered, processing):

    • To speed things up while keeping some order, you use different MessageGroupID values.

    • In-Group Order: Messages sharing the same MessageGroupID (like A1, A2, A3) will be processed in order, one after the other. It's their own mini-FIFO line.

    • Parallel Processing: Since each unique MessageGroupID forms its own independent sequence, multiple consumers can process different groups simultaneously (e.g., Consumer "A" processes group A while Consumer "B" processes group B). * The Catch: Ordering across different groups is NOT guaranteed. Group "A" might finish before Group "C" even if the first message in "C" arrived earlier. You only get ordering within a specific group.

In short: The MessageGroupID is your ticket to a bit of parallel processing without completely losing your mind (or your required sequence of events).

<p>SQS FIFO Message Grouping Explained</p><p></p><p>Think of it like a meticulous, digital post office that only delivers letters in the exact order they arrived... <em>unless</em> you've marked them with a special group ID.</p><ul><li><p><strong>The Golden Rule (for strict ordering):</strong></p><ul><li><p>If you set the <code>MessageGroupID</code> to the <strong>same value</strong> for <em>every</em> message in the queue, then all messages are processed in strict FIFO order, but you can only have <strong>one consumer</strong> working on the queue. Slow, but perfectly sequential!</p></li></ul></li><li><p><strong>The Clever Hack (for parallel, yet ordered, processing):</strong></p><ul><li><p>To speed things up while keeping <em>some</em> order, you use <strong>different </strong><code>MessageGroupID</code><strong> values</strong>.</p></li><li><p><strong>In-Group Order:</strong> Messages sharing the <strong>same </strong><code>MessageGroupID</code> (like A1, A2, A3) will be processed in order, one after the other. It's their own mini-FIFO line.</p></li><li><p><strong>Parallel Processing:</strong> Since each unique <code>MessageGroupID</code> forms its own independent sequence, <strong>multiple consumers</strong> can process different groups simultaneously (e.g., Consumer "A" processes group A while Consumer "B" processes group B). * <strong>The Catch:</strong> <strong>Ordering across different groups is NOT guaranteed.</strong> Group "A" might finish before Group "C" even if the first message in "C" arrived earlier. You only get ordering <em>within</em> a specific group.</p></li></ul></li></ul><p><strong>In short:</strong> The <code>MessageGroupID</code> is your ticket to a bit of parallel processing without completely losing your mind (or your required sequence of events).</p>
15
New cards
<p>AWS SNS</p>

AWS SNS

SNS's Deep Integration with AWS Services (Fan-out) so many AWS services can send data directly to SNS for notifications

The main reason SNS is so integrated is that its subscribers can be many different things simultaneously. A single message published to an SNS Topic can be instantly fanned out to all of the following destinations:

Subscriber Type

Integration Use Case

Amazon SQS Queue

Decoupling & Durability: This is the most common pair! SNS broadcasts the message, and SQS catches it. This is essential for reliability, as SQS keeps the message safe until a consumer is ready to process it.

AWS Lambda

Real-Time Processing: SNS can directly trigger a Lambda function, which runs your custom code immediately upon receiving the message.

HTTP/S Endpoint

External Communication: Sends the notification directly to an external server or an application hosted outside of AWS (via a webhook).

AWS EventBridge

Advanced Routing: SNS can publish to EventBridge for more complex filtering and routing to many other services.

AWS CloudWatch

Alerts & Alarms: CloudWatch often uses an SNS Topic as the final action when a metric threshold (like high CPU) is breached, sending alerts to administrators.

End Users (A2P)

Direct Notification: Messages can be sent directly to end-users via Email or SMS/Mobile Push Notifications.

<p>SNS's Deep Integration with AWS Services (Fan-out) so many AWS services can send data directly to SNS for notifications</p><p></p><p>The main reason SNS is so integrated is that its subscribers can be many different things simultaneously. A single message published to an SNS Topic can be instantly fanned out to all of the following destinations:</p><table style="min-width: 50px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>Subscriber Type</strong></p></td><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>Integration Use Case</strong></p></td></tr><tr><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>Amazon SQS Queue</strong></p></td><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>Decoupling &amp; Durability:</strong> This is the most common pair! SNS broadcasts the message, and SQS catches it. This is essential for reliability, as SQS keeps the message safe until a consumer is ready to process it.</p></td></tr><tr><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>AWS Lambda</strong></p></td><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>Real-Time Processing:</strong> SNS can directly trigger a Lambda function, which runs your custom code immediately upon receiving the message.</p></td></tr><tr><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>HTTP/S Endpoint</strong></p></td><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>External Communication:</strong> Sends the notification directly to an external server or an application hosted outside of AWS (via a webhook).</p></td></tr><tr><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>AWS EventBridge</strong></p></td><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>Advanced Routing:</strong> SNS can publish to EventBridge for more complex filtering and routing to many other services.</p></td></tr><tr><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>AWS CloudWatch</strong></p></td><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>Alerts &amp; Alarms:</strong> CloudWatch often uses an SNS Topic as the final action when a metric threshold (like high CPU) is breached, sending alerts to administrators.</p></td></tr><tr><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>End Users (A2P)</strong></p></td><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>Direct Notification:</strong> Messages can be sent directly to end-users via <strong>Email</strong> or <strong>SMS/Mobile Push Notifications</strong>.</p></td></tr></tbody></table><p></p>
16
New cards
<p>AWS SNS - How to public</p>

AWS SNS - How to public

Topic Publish (Using the AWS SDK)

This is the standard, flexible method used for Application-to-Application (A2A) messaging and general notifications.

  • Create a topic: You first establish a named central channel (the "topic") within the SNS service (e.g., Order_Confirmation_Events).

  • Create a subscription (or many): You register one or more recipients to listen to that topic. These subscribers can be SQS queues, Lambda functions, email addresses, or HTTP endpoints.

  • Publish to the topic: A publisher application (like your EC2 instance) sends a single message to the topic's name. SNS then automatically fans out that message to all registered subscribers

Direct Publish (For Mobile Apps SDK)

This method is specifically designed for sending notifications directly to a single mobile device or application, which falls under Application-to-Person (A2P) messaging.

  • Create a platform application: You register your mobile platform (e.g., Apple Push Notification Service (APNS) for iOS, Google Cloud Messaging (GCM) for Android) with SNS.

  • Create a platform endpoint: For each user's device, SNS creates a unique, encrypted address (an endpoint ARN) that represents that specific device on that platform.

  • Publish to the platform endpoint: You send a message directly to that unique device endpoint ARN.

  • Works with Google GCM, Apple APNS, Amazon ADM...: SNS translates your message into the specific format required by the respective platform (Apple, Google, etc.) and ensures the notification reaches the target device.

<p><strong>Topic Publish (Using the AWS SDK)</strong></p><p>This is the standard, flexible method used for <strong>Application-to-Application (A2A)</strong> messaging and general notifications.</p><ul><li><p><strong>Create a topic:</strong> You first establish a named central channel (the "topic") within the SNS service (e.g., <code>Order_Confirmation_Events</code>).</p></li><li><p><strong>Create a subscription (or many):</strong> You register one or more recipients to listen to that topic. These subscribers can be SQS queues, Lambda functions, email addresses, or HTTP endpoints.</p></li><li><p><strong>Publish to the topic:</strong> A publisher application (like your EC2 instance) sends a single message to the topic's name. SNS then automatically <strong>fans out</strong> that message to <em>all</em> registered subscribers</p></li></ul><p></p><p><strong>Direct Publish (For Mobile Apps SDK)</strong></p><p>This method is specifically designed for sending notifications directly to a single mobile device or application, which falls under <strong>Application-to-Person (A2P)</strong> messaging.</p><ul><li><p><strong>Create a platform application:</strong> You register your mobile platform (e.g., Apple Push Notification Service (APNS) for iOS, Google Cloud Messaging (GCM) for Android) with SNS.</p></li><li><p><strong>Create a platform endpoint:</strong> For each user's device, SNS creates a unique, encrypted address (an <strong>endpoint ARN</strong>) that represents that specific device on that platform.</p></li><li><p><strong>Publish to the platform endpoint:</strong> You send a message directly to that unique device endpoint ARN.</p></li><li><p><strong>Works with Google GCM, Apple APNS, Amazon ADM...:</strong> SNS translates your message into the specific format required by the respective platform (Apple, Google, etc.) and ensures the notification reaches the target device.</p></li></ul><p></p>
17
New cards

SNS + SQS: Fan out pattern

Why This Combination Works

This hybrid push/pull pattern solves the major problems of distributed systems:

  • Decoupling & Parallelism: A single "Order Placed" event published to the SNS Topic is instantly replicated into the ShippingQueue, the AnalyticsQueue, and the BillingQueue. All three services can start working on their tasks at the exact same time.

  • Durability (No Data Loss): Since the message lands in SQS, it is stored redundantly until the specific service's consumer successfully processes it. If the Billing Service is down, its queue simply stores the message, guaranteeing no critical event is lost.

  • Independent Scaling: The Billing service can scale its consumers to handle 10 messages per second, while the Analytics service can scale to handle 100 messages per second, all using the same original event without affecting each other.

  • Message Filtering: You can attach a Subscription Filter Policy to an SQS queue so that it only receives a subset of the messages from the Topic (e.g., the Premium_Orders_Queue only receives messages with the attribute order_type: "premium").

<p>Why This Combination Works</p><p></p><p>This hybrid push/pull pattern solves the major problems of distributed systems:</p><ul><li><p><strong>Decoupling &amp; Parallelism:</strong> A single "Order Placed" event published to the SNS Topic is instantly replicated into the <code>ShippingQueue</code>, the <code>AnalyticsQueue</code>, and the <code>BillingQueue</code>. All three services can start working on their tasks <strong>at the exact same time</strong>.</p></li><li><p><strong>Durability (No Data Loss):</strong> Since the message lands in SQS, it is stored redundantly until the specific service's consumer successfully processes it. If the Billing Service is down, its queue simply stores the message, guaranteeing no critical event is lost.</p></li><li><p><strong>Independent Scaling:</strong> The Billing service can scale its consumers to handle 10 messages per second, while the Analytics service can scale to handle 100 messages per second, all using the same original event without affecting each other.</p></li><li><p><strong>Message Filtering:</strong> You can attach a <strong>Subscription Filter Policy</strong> to an SQS queue so that it only receives a subset of the messages from the Topic (e.g., the <code>Premium_Orders_Queue</code> only receives messages with the attribute <code>order_type: "premium"</code>).</p></li></ul><p></p>
18
New cards
<p>SNS + SQS: Fan out pattern examples and architecture solutions   </p>

SNS + SQS: Fan out pattern examples and architecture solutions

knowt flashcard image

<img src="https://knowt-user-attachments.s3.amazonaws.com/fee34387-3289-405e-8cf2-4d13177c0f2b.png" data-width="75%" data-align="center" alt="knowt flashcard image"><p></p>
19
New cards

AWS SNS - Message Filtering

SNS Message Filtering: Customized Broadcast

The filtering is defined by a Subscription Filter Policy, which is a JSON document attached to the subscription (not the Topic itself).

How It Works

When a message is published to the SNS Topic, the service does the following for every single subscriber:

  1. Check the Policy: SNS compares the incoming message's content against the JSON filter policy attached to that specific subscription.

  2. Filter/Deliver:

    • Match: If the message meets all conditions of the policy, SNS pushes the message to the subscriber (e.g., the SQS Queue).

    • No Match: If the message does not match, SNS filters it out and the subscriber never receives it.

Two Main Types of Filtering

Type

How the Filter Reads the Message

Common Use Case

Attribute-Based

The filter checks Message Attributes—small metadata key-value pairs that are sent alongside the main message body.

Filtering by categories: {"order_type": ["digital", "physical"]}, {"region": ["EU", "US"]}.

Payload-Based

The filter checks specific fields within the main JSON body of the message itself.

Filtering based on document content, such as a field in an S3 event notification: {"s3_object_key": [{"prefix": "invoices/"}]}.

Example Use Case: Order Processing Fan-out

Imagine a single ORDER_EVENTS SNS Topic:

  • Subscriber A (Email Service): Only needs messages where status: ["shipped", "delivered"]. The filter rejects all messages about payments or cancellations.

  • Subscriber B (Inventory Service): Only needs messages where type: ["physical_goods"]. The filter rejects messages about digital downloads.

<p><strong>SNS Message Filtering: Customized Broadcast</strong></p><p>The filtering is defined by a <strong>Subscription Filter Policy</strong>, which is a JSON document attached to the <em>subscription</em> (not the Topic itself).</p><p></p><p><strong>How It Works</strong></p><p>When a message is published to the SNS Topic, the service does the following for <em>every single subscriber</em>:</p><ol><li><p><strong>Check the Policy:</strong> SNS compares the incoming message's content against the JSON filter policy attached to that specific subscription.</p></li><li><p><strong>Filter/Deliver:</strong></p><ul><li><p><strong>Match:</strong> If the message meets all conditions of the policy, SNS <strong>pushes</strong> the message to the subscriber (e.g., the SQS Queue).</p></li><li><p><strong>No Match:</strong> If the message does not match, SNS <strong>filters it out</strong> and the subscriber never receives it.</p></li></ul></li></ol><p></p><p><strong>Two Main Types of Filtering</strong></p><table style="min-width: 75px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>Type</strong></p></td><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>How the Filter Reads the Message</strong></p></td><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>Common Use Case</strong></p></td></tr><tr><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>Attribute-Based</strong></p></td><td colspan="1" rowspan="1" style="border: 1px solid;"><p>The filter checks <strong>Message Attributes</strong>—small metadata key-value pairs that are sent alongside the main message body.</p></td><td colspan="1" rowspan="1" style="border: 1px solid;"><p>Filtering by categories: <code>{"order_type": ["digital", "physical"]}</code>, <code>{"region": ["EU", "US"]}</code>.</p></td></tr><tr><td colspan="1" rowspan="1" style="border: 1px solid;"><p><strong>Payload-Based</strong></p></td><td colspan="1" rowspan="1" style="border: 1px solid;"><p>The filter checks specific fields <strong>within the main JSON body</strong> of the message itself.</p></td><td colspan="1" rowspan="1" style="border: 1px solid;"><p>Filtering based on document content, such as a field in an S3 event notification: <code>{"s3_object_key": [{"prefix": "invoices/"}]}</code>.</p></td></tr></tbody></table><p></p><p><strong>Example Use Case: Order Processing Fan-out</strong></p><p>Imagine a single <code>ORDER_EVENTS</code> SNS Topic:</p><ul><li><p><strong>Subscriber A (Email Service):</strong> Only needs messages where <code>status: ["shipped", "delivered"]</code>. The filter rejects all messages about payments or cancellations.</p></li><li><p><strong>Subscriber B (Inventory Service):</strong> Only needs messages where <code>type: ["physical_goods"]</code>. The filter rejects messages about digital downloads.</p></li></ul><p></p>
20
New cards

AWS Kinesis Data Streams (KDS)

KDS is used to collect and store streaming data in real-time 

Features of KDS:

· Retention between up to 365 days

· Ability to reprocess (replay) data by consumers

. Data can't be deleted from Kinesis (until it expires)

. Data up to IMB (typical use case is lot of "small" real-time data)

. Data ordering guarantee for data with the same "Partition ID"

. At-rest KMS encryption, in-flight HTTPS encryption

. Kinesis Producer Library (KPL) to write an optimized producer application

. Kinesis Client Library (KCL) to write an optimized consumer application

<p>KDS is used to collect and store streaming data in <strong>real-time&nbsp;</strong></p><p><strong>Features of KDS:</strong></p><p>· Retention between up to 365 days</p><p>· Ability to reprocess (replay) data by consumers</p><p>. Data can't be deleted from Kinesis (until it expires)</p><p>. Data up to IMB (typical use case is lot of "small" real-time data)</p><p>. Data ordering guarantee for data with the same "Partition ID"</p><p>. At-rest KMS encryption, in-flight HTTPS encryption</p><p>. Kinesis Producer Library (KPL) to write an optimized producer application</p><p>. Kinesis Client Library (KCL) to write an optimized consumer application</p>
21
New cards

AWS KDS - Capacity Modes

In Amazon Kinesis Data Streams, a shard is the fundamental unit of capacity and parallelism. Each shard handles a portion of the data stream's read and write throughput.

What Is a Shard?

  • A shard is a uniquely identified sequence of data records within a Kinesis stream.

  • Each stream is composed of one or more shards, and each shard acts like a container for incoming data records.

  • Shards enable parallel processing of data, allowing multiple consumers to read from different shards simultaneously.

📌 Why Shards Matter

  • Shards determine how much data your stream can handle and how fast consumers can process it.

  • They are crucial for scaling, performance tuning, and cost management in Kinesis Data Streams.

<p><strong>In Amazon Kinesis Data Streams, a <em>shard</em> is the fundamental unit of capacity and parallelism. Each shard handles a portion of the data stream's read and write throughput.</strong></p><p>What Is a Shard?</p><ul><li><p><strong>A shard is a uniquely identified sequence of data records</strong> within a Kinesis stream.</p></li><li><p>Each stream is composed of one or more shards, and each shard acts like a container for incoming data records.</p></li><li><p>Shards enable <strong>parallel processing</strong> of data, allowing multiple consumers to read from different shards simultaneously.</p></li></ul><p></p><p><span data-name="pushpin" data-type="emoji">📌</span> Why Shards Matter</p><ul><li><p>Shards determine <strong>how much data your stream can handle</strong> and <strong>how fast consumers can process it</strong>.</p></li><li><p>They are crucial for <strong>scaling</strong>, <strong>performance tuning</strong>, and <strong>cost management</strong> in Kinesis Data Streams.</p></li></ul><p></p>
22
New cards
<p>AWS Data Firehose</p>

AWS Data Firehose

Amazon Kinesis Data Firehose is a fully managed service for delivering real-time streaming data to various destinations without requiring custom applications or infrastructure management.

Here are the key details:

. Note: used to be called "Kinesis Data Firehose"

. Fully Managed Service

. Amazon Redshift / Amazon S3 / Amazon OpenSearch Service

. 3rd party: Splunk / MongoDB / Datadog / NewRelic / ...

. Custom HTTP Endpoint

. Automatic scaling, serverless, pay for what you use

. Near Real-Time with buffering capability based on size / time

. Supports CSV,JSON, Parquet, Avro, Raw Text, Binary data

. Conversions to Parquet / ORC, compressions with gzip / snappy

. Custom data transformations using AWS Lambda (ex: CSV to JSON)

<p>Amazon Kinesis Data Firehose is a fully managed service for delivering real-time streaming data to various destinations without requiring custom applications or infrastructure management.</p><p><strong>Here are the key details:</strong></p><p>. Note: used to be called "Kinesis Data Firehose"</p><p>. Fully Managed Service</p><p>. Amazon Redshift / Amazon S3 / Amazon OpenSearch Service</p><p>. 3rd party: Splunk / MongoDB / Datadog / NewRelic / ...</p><p>. Custom HTTP Endpoint</p><p>. Automatic scaling, serverless, pay for what you use</p><p>. Near Real-Time with buffering capability based on size / time</p><p>. Supports CSV,JSON, Parquet, Avro, Raw Text, Binary data</p><p>. Conversions to Parquet / ORC, compressions with gzip / snappy</p><p>. Custom data transformations using AWS Lambda (ex: CSV to JSON)</p><p></p>
23
New cards

Amazon Manager Services

Amazon Managed Services (AMS) is a suite of operational support offerings from AWS that helps enterprises manage and operate their cloud infrastructure more efficiently and securely.

Here’s a detailed breakdown of what AMS provides:

  • AMS helps enterprises operate AWS infrastructure by automating tasks like provisioning, monitoring, and patching.

  • It enforces best practices for security, compliance, and operational efficiency.

  • AMS provides 24/7 incident response and change management support.

  • It assists with cost optimization and scaling cloud operations.

  • Designed for large organizations needing robust governance and support.

<p><strong>Amazon Managed Services (AMS) is a suite of operational support offerings from AWS that helps enterprises manage and operate their cloud infrastructure more efficiently and securely.</strong></p><p>Here’s a detailed breakdown of what AMS provides:</p><ul><li><p>AMS helps enterprises operate AWS infrastructure by automating tasks like provisioning, monitoring, and patching.</p></li><li><p>It enforces best practices for security, compliance, and operational efficiency.</p></li><li><p>AMS provides 24/7 incident response and change management support.</p></li><li><p>It assists with cost optimization and scaling cloud operations.</p></li><li><p>Designed for large organizations needing robust governance and support.</p></li></ul><p></p>
24
New cards

SQS vs SNS vs Kinesis

knowt flashcard image