AWS Solutions Architect Exam  >  AWS Solutions Architect Notes  >  : Associate Level  >  Cheat Sheet: SQS & SNS — Decoupling Patterns

Cheat Sheet: SQS & SNS — Decoupling Patterns

1. Amazon SQS Overview

1.1 Core Concepts

ConceptDescription
SQSFully managed message queuing service for decoupling application components
Message RetentionDefault 4 days, configurable from 1 minute to 14 days
Message Size1 byte to 256 KB per message
Payload ExtensionUse S3 for messages >256 KB with SQS Extended Client Library
Queue LimitUnlimited number of messages in queue
DeliveryAt-least-once delivery (Standard), exactly-once processing (FIFO)

1.2 Standard Queue

FeatureDetails
ThroughputNearly unlimited transactions per second
OrderingBest-effort ordering, no guarantee
DeliveryAt-least-once delivery, occasional duplicates possible
Use CaseHigh throughput applications where order is not critical

1.3 FIFO Queue

FeatureDetails
Throughput300 messages/sec (3000 with batching)
High Throughput Mode3000 messages/sec (30,000 with batching)
OrderingStrict ordering preserved, first-in-first-out
DeliveryExactly-once processing, no duplicates
NamingQueue name must end with .fifo suffix
Message Group IDRequired tag to ensure ordering within group
Deduplication IDToken for 5-minute deduplication interval
Content-Based DeduplicationSHA-256 hash of message body for automatic deduplication

2. SQS Message Processing

2.1 Visibility Timeout

ParameterDetails
DefinitionPeriod when message is invisible to other consumers after being received
Default30 seconds
Range0 seconds to 12 hours
ChangeMessageVisibility APIExtend timeout if more processing time needed
Timeout ExpirationMessage becomes visible again if not deleted

2.2 Long Polling

ConceptDetails
PurposeReduce empty responses and API calls by waiting for messages
Wait Time1 to 20 seconds (ReceiveMessageWaitTimeSeconds)
BenefitDecreases costs, reduces empty receives
ConfigurationQueue-level or API-level (ReceiveMessage call)
Preferred OverShort polling (WaitTimeSeconds = 0)

2.3 Dead Letter Queue (DLQ)

AspectDetails
PurposeStore messages that fail processing after maximum receive count
MaximumReceivesThreshold after which message moves to DLQ
Queue Type MatchDLQ must be same type as source (Standard or FIFO)
RetentionSet DLQ retention longer than source queue for debugging
Redrive PolicyJSON configuration specifying DLQ ARN and MaximumReceives

2.4 Delay Queue

FeatureDetails
DefinitionPostpone delivery of messages to consumers
Range0 to 15 minutes
Default0 seconds (immediate delivery)
Queue-LevelDelaySeconds parameter affects all messages
Message-LevelOverride queue default with message timer (Standard only)

3. SQS APIs and Operations

3.1 Key APIs

API CallFunction
SendMessageAdd single message to queue
SendMessageBatchAdd up to 10 messages in single request
ReceiveMessagePoll messages (up to 10) from queue
DeleteMessageRemove message after successful processing
DeleteMessageBatchRemove up to 10 messages in single request
ChangeMessageVisibilityModify visibility timeout for received message
PurgeQueueDelete all messages in queue

3.2 Message Attributes

  • Metadata attached to message as name-value pairs
  • Do not count toward 256 KB message size limit
  • Types: String, Number, Binary
  • Maximum 10 attributes per message

4. Amazon SNS Overview

4.1 Core Concepts

ConceptDescription
SNSFully managed pub/sub messaging and mobile notifications service
PublisherApplication or service that sends messages to topic
TopicCommunication channel with access control and delivery policies
SubscriberEndpoint that receives messages from topic
Message SizeMaximum 256 KB per notification
Fan-Out PatternOne message to multiple subscribers simultaneously

4.2 Topic Types

TypeDetails
StandardBest-effort ordering, at-least-once delivery, high throughput
FIFOStrict ordering, exactly-once delivery, 300 msg/sec (3000 with batching)
FIFO NamingTopic name must end with .fifo suffix
FIFO SubscribersOnly SQS FIFO queues can subscribe to SNS FIFO topics

4.3 Subscription Protocols

ProtocolDetails
HTTP/HTTPSDeliver JSON-encoded message to web server endpoint
EmailSend message to registered email address
Email-JSONSend JSON-formatted message to email
SQSDeliver message to SQS queue
LambdaInvoke Lambda function with message payload
SMSSend text message to phone number
Platform Application EndpointMobile push notifications (APNs, FCM, etc.)

5. SNS Features

5.1 Message Filtering

FeatureDetails
Filter PolicyJSON policy applied to subscription to filter messages
AttributesFilter based on message attributes (not body)
Default BehaviorWithout filter, subscription receives all topic messages
OperatorsExact match, prefix, numeric ranges, exists check

5.2 Message Attributes

  • Name-value pairs sent with message
  • Types: String, String.Array, Number, Binary
  • Used for message filtering at subscription level
  • Maximum 10 attributes per message

5.3 Delivery Retry Policy

PhaseDetails
Immediate RetryNo delay between retries, 3 attempts
Pre-Backoff1 second delay, 10 attempts
BackoffExponential backoff from 1 sec to 20 sec
Post-Backoff20 second delay, 100,000+ attempts
Total DurationHTTP/S endpoints: retries over several hours

5.4 Dead Letter Queue for SNS

  • Configure DLQ at subscription level (not topic level)
  • SQS queue captures messages that fail delivery after retries
  • Client-side errors (4xx) sent directly to DLQ without retries
  • Server-side errors (5xx) trigger retry policy before DLQ

6. Decoupling Patterns

6.1 SNS + SQS Fan-Out

AspectDetails
PatternSNS topic delivers message to multiple SQS queues
BenefitFully decoupled, no data loss, parallel async processing
Use CaseMultiple downstream systems need same data
PermissionsSQS queue policy must allow SNS SendMessage
Cross-RegionSNS can deliver to SQS queues in different regions

6.2 SQS as Buffer

  • Queue absorbs traffic spikes between producers and consumers
  • Consumers process at their own pace
  • Prevents overloading downstream systems
  • Auto Scaling can scale consumers based on queue depth (ApproximateNumberOfMessages)

6.3 Message Processing Patterns

PatternImplementation
Load LevelingSQS queue smooths variable load to steady consumption rate
Priority QueueUse separate queues for different priority levels
Request-ResponseUse message attributes and correlation ID with two queues
Batch ProcessingAccumulate messages in queue then process in batches

6.4 Ordering Considerations

ScenarioSolution
No Order RequiredUse Standard SQS for maximum throughput
Strict Order RequiredUse FIFO SQS with Message Group ID
Partial OrderFIFO queue with multiple Message Group IDs for parallel processing
Order with SNSSNS FIFO to SQS FIFO preserves order

7. Security and Access Control

7.1 Encryption

TypeDetails
In-TransitHTTPS API endpoints, TLS encryption
At-Rest (SQS)SSE using KMS keys (AWS managed or customer managed)
At-Rest (SNS)SSE using KMS keys for messages stored temporarily
Key TypesAWS managed key (aws/sqs or aws/sns) or customer managed CMK

7.2 Access Policies

Policy TypeUse Case
IAM PolicyControl user/role access to SQS/SNS APIs
SQS Queue PolicyGrant cross-account access, allow SNS to send messages
SNS Topic PolicyControl who can publish or subscribe to topic
VPC EndpointPrivate connection from VPC without internet gateway

7.3 Cross-Account Access

  • Use resource-based policies (queue or topic policy)
  • Specify Principal as ARN of other account or IAM entity
  • For SQS: grant sqs:SendMessage, sqs:ReceiveMessage permissions
  • For SNS: grant sns:Publish or sns:Subscribe permissions

8. Monitoring and Troubleshooting

8.1 CloudWatch Metrics for SQS

MetricDescription
ApproximateNumberOfMessagesMessages available for retrieval
ApproximateNumberOfMessagesVisibleMessages in queue not in-flight
ApproximateNumberOfMessagesNotVisibleMessages in-flight (sent but not deleted)
NumberOfMessagesSentMessages added to queue
NumberOfMessagesReceivedReceiveMessage API calls returning messages
NumberOfMessagesDeletedMessages deleted from queue
ApproximateAgeOfOldestMessageAge of oldest non-deleted message (seconds)

8.2 CloudWatch Metrics for SNS

MetricDescription
NumberOfMessagesPublishedMessages published to topic
NumberOfNotificationsDeliveredMessages successfully delivered
NumberOfNotificationsFailedMessages failed to deliver
PublishSizeSize of published messages (bytes)

8.3 Common Issues

ProblemSolution
Duplicate MessagesUse FIFO queue or implement idempotent processing
Message LossCheck DLQ, verify DeleteMessage only after successful processing
Slow ProcessingIncrease visibility timeout, scale consumers horizontally
SNS Delivery FailureCheck endpoint availability, subscription filter policy, IAM permissions
High LatencyEnable long polling, use batching APIs, check queue depth

9. Cost Optimization

9.1 SQS Cost Factors

  • Charged per request (64 KB chunk)
  • SendMessage, ReceiveMessage, DeleteMessage, ChangeMessageVisibility count as requests
  • Long polling reduces costs by decreasing empty ReceiveMessage calls
  • Batch operations (up to 10 messages) count as single request
  • First 1 million requests per month free tier

9.2 SNS Cost Factors

  • Charged per publish request and delivery
  • 64 KB per message chunk
  • SMS and mobile push have additional per-message fees
  • First 1 million publishes per month free tier
  • Data transfer charges for cross-region delivery

9.3 Cost Optimization Strategies

StrategyImplementation
Message BatchingSendMessageBatch and DeleteMessageBatch APIs
Long PollingReduce empty receives, set ReceiveMessageWaitTimeSeconds to 20
Message SizeUse S3 for large payloads, reference in message
Filter SubscriptionsSNS message filtering reduces unnecessary deliveries

10. Design Best Practices

10.1 SQS Best Practices

  • Set visibility timeout to 6x average processing time
  • Use DLQ with appropriate MaximumReceives threshold (5-10 recommended)
  • Implement idempotent message processing for Standard queues
  • Delete messages only after successful processing
  • Use long polling to reduce costs and latency
  • Monitor ApproximateAgeOfOldestMessage for processing bottlenecks
  • Scale consumers based on ApproximateNumberOfMessages metric
  • Use FIFO only when strict ordering or deduplication required

10.2 SNS Best Practices

  • Use message filtering to reduce unnecessary processing
  • Configure DLQ at subscription level for failed deliveries
  • Set appropriate retry policies for HTTP/S endpoints
  • Use SNS + SQS fan-out for reliable multi-subscriber pattern
  • Enable encryption for sensitive data
  • Use resource-based policies for cross-account access
  • Monitor NumberOfNotificationsFailed for delivery issues

10.3 Resilience Patterns

PatternImplementation
Decouple ComponentsSQS between microservices for loose coupling
Handle FailuresDLQ for poison messages, retry logic in consumers
Scale IndependentlyProducers and consumers scale based on different metrics
Multi-RegionSNS to SQS queues in multiple regions for DR
Event-DrivenSNS triggers Lambda for serverless event processing

10.4 Choosing Between Standard and FIFO

Use Standard WhenUse FIFO When
Throughput is priority (unlimited)Order must be preserved
Order is not criticalExactly-once processing required
Can handle duplicatesDuplicates are unacceptable
Best-effort ordering sufficientSequential operations needed
The document Cheat Sheet: SQS & SNS — Decoupling Patterns is a part of the AWS Solutions Architect Course AWS Solutions Architect: Associate Level.
All you need of AWS Solutions Architect at this link: AWS Solutions Architect
Explore Courses for AWS Solutions Architect exam
Get EduRev Notes directly in your Google search
Related Searches
study material, video lectures, Previous Year Questions with Solutions, Cheat Sheet: SQS & SNS — Decoupling Patterns, pdf , Free, Cheat Sheet: SQS & SNS — Decoupling Patterns, MCQs, Extra Questions, Important questions, Cheat Sheet: SQS & SNS — Decoupling Patterns, past year papers, shortcuts and tricks, Semester Notes, Summary, ppt, Objective type Questions, practice quizzes, Viva Questions, Exam, mock tests for examination, Sample Paper;