AWS - Certified Solutions Architect Decoupling with SQS and SNS Questions and Answers 1 — Questions and Answers
Question 1: A company is designing an order processing system. When a new order is created, the event needs to be sent to multiple downstream services: an inventory service, a shipping service, and a data analytics service. Each service processes the event independently and at its own pace. The architecture must ensure that if the shipping service is temporarily unavailable, it does not impact the inventory and analytics services. Which architecture provides the best decoupling and reliability for this scenario?
- An SQS queue that all three services poll for new order messages.
- An SNS topic that publishes order events, with each of the three services subscribed directly via HTTPS endpoints.
- An SNS topic for new orders, with three separate SQS queues subscribed to the topic. Each service polls its respective queue. (Correct answer)
- A Kinesis Data Stream that captures order events, with each service running a Kinesis Client Library (KCL) application.
Correct answer: An SNS topic for new orders, with three separate SQS queues subscribed to the topic. Each service polls its respective queue.
This is a classic fan-out pattern. Publishing a single message to an SNS topic, which then distributes it to multiple subscribed SQS queues, is the ideal solution. This decouples the publisher from the consumers and also decouples the consumers from each other. Each SQS queue acts as a durable buffer, ensuring that if one consuming service is down, its messages are safely stored until it becomes available, without affecting the other services.
Question 2: What is a fundamental difference between the message consumption models of Amazon SQS and Amazon SNS?
- SQS uses a push model where messages are sent directly to consumers, while SNS uses a pull model where subscribers must poll a topic.
- SQS uses a pull (polling) model where consumers request messages from a queue, while SNS uses a push model to send messages to subscribers. (Correct answer)
- Both SQS and SNS use a push model, but SNS supports more subscriber types.
- Both SQS and SNS use a pull model, but SQS guarantees message ordering.
Correct answer: SQS uses a pull (polling) model where consumers request messages from a queue, while SNS uses a push model to send messages to subscribers.
The core difference in consumption is the mechanism. With SQS, consumers must actively poll the queue to retrieve messages. With SNS, the service pushes the message out to all of its subscribers (like Lambda, SQS, email, etc.) as soon as the message is published to the topic.
Question 3: An application processes large video files uploaded by users. The front-end service uploads the video to S3 and then sends a message with the S3 object key to a backend processing service. The processing can take several minutes and is resource-intensive. The company wants to ensure that messages are not lost if a processing instance fails, and that processing can scale by adding more instances. Which service is most appropriate for managing the messages between the front-end and the backend processing service?
- Amazon SNS, to notify the backend service.
- Amazon SQS, to queue the processing jobs. (Correct answer)
- AWS Step Functions, to orchestrate the entire workflow.
- Amazon Kinesis Data Streams, to stream the job data.
Correct answer: Amazon SQS, to queue the processing jobs.
Amazon SQS is a fully managed message queuing service designed for decoupling and scaling distributed systems. It provides a durable and reliable queue to store the processing jobs. If a processing instance fails, the message remains in the queue (after the visibility timeout expires) and can be picked up by another instance, ensuring no jobs are lost. This model also allows for horizontal scaling by simply adding more consumers (processing instances) to pull from the queue.
Question 4: A developer is using an SQS queue to process financial transactions. They observe that some malformed messages cause the consumer application to crash. When the application restarts, it retrieves the same malformed message and crashes again, preventing other valid messages from being processed. Which SQS feature should be configured to isolate these problematic messages after a certain number of failed processing attempts?
- Visibility Timeout
- Long Polling
- Message Retention Period
- Dead-Letter Queue (DLQ) (Correct answer)
Correct answer: Dead-Letter Queue (DLQ)
A Dead-Letter Queue (DLQ) is the designated feature for this exact use case. You can configure a source queue with a redrive policy that specifies a `maxReceiveCount`. If a message is received from the queue more than that number of times without being successfully deleted, SQS automatically moves it to the specified DLQ. This isolates the problematic message, allowing other messages to be processed, and lets developers inspect the failed messages in the DLQ to debug the issue.
Question 5: A consumer application retrieves a message from a standard SQS queue. The processing of the message is expected to take 5 minutes. During processing, another identical consumer instance starts up, retrieves the exact same message, and begins processing it, leading to data duplication. Which SQS parameter was misconfigured and needs to be adjusted to prevent this issue?
- DelaySeconds
- MessageRetentionPeriod
- VisibilityTimeout (Correct answer)
- ReceiveMessageWaitTimeSeconds
Correct answer: VisibilityTimeout
The Visibility Timeout is a period during which SQS prevents other consumers from receiving and processing a specific message after it has been retrieved by one consumer. If the processing time is longer than the visibility timeout, the message will become visible in the queue again and can be picked up by another consumer. To fix this, the Visibility Timeout should be set to a value greater than the 5-minute processing time.
Question 6: Which of the following is a primary use case for Amazon SNS, as opposed to Amazon SQS?
- Distributing tasks to a pool of worker nodes where each task should be processed only once.
- Buffering requests to a backend database to smooth out traffic spikes.
- Broadcasting a single event notification to multiple, diverse subscribers simultaneously, such as Lambda functions, SQS queues, and email addresses. (Correct answer)
- Storing messages durably for up to 14 days to ensure they are processed even if all consumers are offline.
Correct answer: Broadcasting a single event notification to multiple, diverse subscribers simultaneously, such as Lambda functions, SQS queues, and email addresses.
Amazon SNS is a publish/subscribe service designed to send notifications to a large number of subscribers. Its primary function is to fan out messages to multiple endpoints. The other options are characteristic of SQS: distributing tasks to competing consumers, buffering requests, and providing durable message storage.
A company is designing an order processing system.
When a new order is created, the event needs to be sent to multiple downstream services: an inventory service, a shipping service, and a data analytics service.
Each service processes the event independently and at its own pace.
The architecture must ensure that if the shipping service is temporarily unavailable, it does not impact the inventory and analytics services.
Which architecture provides the best decoupling and reliability for this scenario?