Question

Difficulty: MediumMessage-Based Integration using Amazon SQS and SNS

A developer is designing a serverless notification architecture for an e-commerce platform. When an order is placed, details must be sent to three downstream systems: fulfillment (which only processes 'Express' orders), marketing (which tracks all orders), and analytics (which only processes orders with a value of $100 or more). The developer wants to minimize costs and operational overhead, and avoid having downstream systems filter out irrelevant messages. Which architecture should the developer implement?

  1. Publish messages to a single Amazon SNS topic. Create three Amazon SQS queues, one for each downstream system, and subscribe them to the SNS topic. Apply SNS subscription filter policies on the fulfillment and analytics queue subscriptions to filter by message attributes, and leave the marketing subscription unfiltered.Answer
  2. B
    Publish all messages to a single Amazon SQS standard queue. Configure the fulfillment, marketing, and analytics systems to poll the queue. If a system receives a message it does not need, it leaves the message in the queue and relies on a low SQS visibility timeout to allow other systems to retrieve it.
  3. C
    Publish all messages to a single Amazon SNS topic. Subscribe three Amazon SQS queues to the topic. Have the consumer applications initialize their AWS SDK clients using hardcoded AWS access keys inside the code to retrieve and filter messages from their respective queues.
  4. D
    Publish all messages to an Amazon SNS topic. Subscribe three AWS Lambda functions directly to the topic. Configure the fulfillment and analytics Lambda functions with short timeouts to quickly discard unmatched messages, assuming that database connections and stateful variables inside the functions are automatically cleaned up between execution threads.

Answer

Publish messages to a single Amazon SNS topic, subscribe three Amazon SQS queues to it, and apply SNS subscription filter policies to route specific messages to the fulfillment and analytics queues while leaving the marketing queue unfiltered.
The correct architecture uses the Amazon SNS fanout pattern combined with subscription filter policies. By publishing all events to a single SNS topic and subscribing separate SQS queues for each downstream service, you achieve complete decoupling. Applying SNS subscription filter policies directly on the subscriptions ensures that only matching messages are sent to the fulfillment and analytics SQS queues, eliminating the need for consumer-side filtering. This minimizes SQS request costs and operational overhead.

Step-by-Step Solution

1
Identify the routing requirements for the messages (one consumer needs all messages, while the other two need specific subsets based on string and numeric attributes).
Determined that a fanout pattern is required to deliver messages to multiple independent destinations.
This establishes that a single queue cannot be shared directly, as consumers would compete for messages rather than receiving clones of the messages.
2
Analyze how to filter messages before they reach the consumer systems to meet the cost and overhead minimization requirements.
Selected SNS subscription filter policies, which natively support string matching (for Express shipping) and numeric range matching (for order value >= 100).
SNS subscription filter policies prevent unwanted messages from being delivered to SQS queues, reducing SQS request and storage costs.
3
Integrate SQS queues as the endpoints for the SNS subscriptions to ensure durability and decouple the consumer processing from the message publisher.
Created three SQS queues subscribed to the SNS topic, with filter policies applied directly at the subscription level.
This architecture ensures messages are safely buffered and only matching messages are processed by each consumer system.

Key Concept

Message routing and fanout using Amazon SNS subscription filter policies and Amazon SQS queues

Alternative Method

An alternative approach is to use Amazon EventBridge, which natively supports content-based filtering. However, for standard high-throughput messaging patterns involving simple SQS integration, the SNS-to-SQS fanout with subscription filter policies is the standard, cost-effective, and highly scalable pattern tested on the AWS Certified Developer exam.
Estimated Time:2m 0s
Rate this question