# Publish-Subscribe Messaging

Publish-subscribe messaging is an asynchronous communication pattern in which publishers send messages to a topic or broker that distributes them to interested subscribers.

Cloud concept. Updated 2026-10-29. Page: https://blowstack.com/tools/cloud-concepts-hub/publish-subscribe-messaging

> Publishers do not need to know which applications or people receive their messages, allowing producers and consumers to evolve independently. This pattern supports event distribution, application integration, and operational alerts, especially when one event must reach multiple independent recipients.

Practice exams covering Publish-Subscribe Messaging: [CLF-C02 AWS Certified Cloud Practitioner](https://blowstack.com/practice-exams/aws-certified-cloud-practitioner), [SOA-C03 AWS Certified CloudOps Engineer - Associate](https://blowstack.com/practice-exams/aws-certified-cloudops-engineer-associate), [DEA-C01 AWS Certified Data Engineer - Associate](https://blowstack.com/practice-exams/aws-certified-data-engineer-associate), [DVA-C02 AWS Certified Developer - Associate](https://blowstack.com/practice-exams/aws-certified-developer-associate), [DOP-C02 AWS Certified DevOps Engineer - Professional](https://blowstack.com/practice-exams/aws-certified-devops-engineer-professional), [SAA-C03 AWS Certified Solutions Architect - Associate](https://blowstack.com/practice-exams/aws-certified-solutions-architect-associate), [SAP-C03 AWS Certified Solutions Architect - Professional](https://blowstack.com/practice-exams/aws-certified-solutions-architect-professional).

## 6 key aspects of Publish-Subscribe Messaging

Publish-subscribe combines decoupled producers, subscription-based fan-out, and asynchronous consumption, while requiring explicit decisions about reliability and message contracts.

1. **Publisher-subscriber decoupling**: Publishers send messages without directly invoking each recipient. Subscribers can be added or changed independently, provided they remain compatible with the message contract.
2. **One-to-many fan-out**: A single publication can reach multiple independent subscriptions. Use this when several applications or notification channels must react to the same event.
3. **Subscription-based routing**: Topics and subscription filters determine which recipients receive a message. Filtering reduces unnecessary processing but requires consistent message attributes or payload structure.
4. **Asynchronous processing**: Publishing and subscriber processing occur separately. Applications must distinguish acceptance by the messaging service from completion of downstream business operations.
5. **Explicit reliability design**: Delivery guarantees, ordering, retention, and replay depend on the implementation. Use idempotent consumers, appropriate retries, and dead-letter handling rather than assuming every message is processed exactly once.
6. **Independent consumer buffering**: A separate queue for each consuming application lets subscribers process at different rates without competing for the same copy. This combines publish-subscribe distribution with durable work buffering.

## Cloud services for Publish-Subscribe Messaging

Use CloudWatch to detect an operational condition and SNS to distribute the resulting alarm notification to subscribed people or systems. For application events that several services must process independently, publish to SNS and subscribe a separate SQS queue for each consuming application. Those queues buffer work and isolate differences in processing speed. EventBridge provides another event-distribution option when routing by event content and integrating event sources with targets are the main requirements. Select services by their roles: detecting a condition, distributing an event, routing it, or retaining work until a consumer can process it.

- **[Amazon EventBridge](https://blowstack.com/tools/cloud-services-hub/amazon-eventbridge)**: EventBridge event buses route events from applications, AWS services, and supported external sources to targets using matching rules. It applies publisher-consumer decoupling and one-to-many routing when event patterns and service integrations are central requirements.
- **[Amazon CloudWatch](https://blowstack.com/tools/cloud-services-hub/amazon-cloudwatch)**: CloudWatch monitors resources and applications, and its alarms can publish notifications to SNS topics. It supplies the detection and alarm logic, while SNS handles distribution to subscribed recipients.

## Publish-Subscribe Messaging exam questions

Real practice exam questions on Publish-Subscribe Messaging, with the correct answer and its explanation.

### Question 1 (CLF-C02)

**Question:**

A bank's payment application directly calls separate AWS Lambda functions for fraud analysis and rewards processing after each payment. The bank plans to add more processing functions over time. Every function must receive each payment message, but adding a function must not require changing the payment application's code or its list of recipients. Which design meets these requirements?

**Correct answer:** Publish payment messages to one Amazon SNS topic and subscribe each processing function to that topic.

**Explanation:** Amazon SNS distributes each published message to the topic's subscriptions. New functions can be subscribed without changing the payment application's code or making it maintain a recipient list.

### Question 2 (SOA-C03)

**Question:**

A company configures its CloudWatch alarms to publish notifications to one SNS standard topic. The topic has confirmed email subscriptions and a subscription for an SQS standard queue. Two incident-processing applications poll this queue. During testing, each application receives only some of the alarm notifications, although together they process all notifications.

Both applications must independently process every alarm notification and retain their own backlog when temporarily unavailable. Existing alarm actions and email delivery must remain unchanged. Which change should a CloudOps engineer make?

**Correct answer:** Use a separate SQS queue for each application and subscribe both queues to the existing SNS topic. Configure each queue policy to allow messages from that topic.

**Explanation:** SNS distributes each notification to both queue subscriptions while continuing delivery to the email subscriptions. Each application consumes its own queue, giving it an independent copy and backlog without changing the CloudWatch alarm actions.

### Question 3 (SAP-C03)

**Question:**

A company is building a multi-tenant incident-response application. Browsers use a custom JSON protocol over persistent WebSocket connections to subscribe to individual incident rooms. An existing backend publishes room updates independently of browser requests. Every connected browser subscribed to a room must receive its updates, and updates must not reach browsers subscribed only to other rooms.

Users can gain or lose permission to join rooms while connected. Subsequent subscription requests must use the user's current permissions without requiring a reconnect. The company wants managed connection handling and no continuously running application servers.

Which architecture best meets these requirements?

**Correct answer:** Create an API Gateway WebSocket API with connection authentication and a Lambda integration for subscription messages. Validate current room permissions for each subscription and store room-to-connection mappings in DynamoDB. Have a publisher Lambda function query the room's mappings and use the API Gateway Management API PostToConnection operation for each connection, removing stale mappings when delivery returns GoneException.

**Explanation:** API Gateway manages persistent connections while short-lived Lambda functions handle application operations. Checking current permissions in the subscription handler enforces authorization independently of connection establishment. The registry implements room subscriptions, and PostToConnection enables backend-initiated delivery to every matching browser. Removing stale mappings after GoneException complements $disconnect cleanup, which is not guaranteed to occur.

### Question 4 (DEA-C01)

**Question:**

A manufacturer publishes a continuous stream of calibration changes from thousands of machines. A data lake ingestion application and a quality-control application must each receive every change and process changes for each machine in publication order. Different machines must be processable concurrently. Each application must have its own backlog so that pausing one application does not interrupt the other.

The producer publishes changes sequentially for each machine and must use one publish request per change, regardless of the number of downstream applications. The company wants managed message distribution without custom routing code. Historical replay before a new application subscribes is not required.

Which design meets these requirements?

**Correct answer:** Publish to an Amazon SNS FIFO topic with the machine ID as MessageGroupId. Subscribe a separate Amazon SQS FIFO queue for each application, and have each application process messages from its own queue while respecting message-group ordering.

**Explanation:** The topic fans out each published change to both subscribed queues. Separate queues provide independent backlogs. Using the machine ID as MessageGroupId preserves publication order for each machine while allowing different machines' message groups to be processed concurrently.

### Question 5 (DOP-C02)

**Question:**

A company's incident detector publishes small JSON messages to an Amazon SNS standard topic. Each message includes between 5 and 15 SNS message attributes that contain investigation context. An Amazon SQS standard queue subscribes to the topic with raw message delivery enabled. An incident-response application reads the message body and native SQS message attributes.

During testing, messages with up to 10 attributes reach the queue, but messages with more than 10 attributes do not. All publish requests succeed, and the topic and queue permissions are correct.

A DevOps engineer must deliver every incident message and preserve all its attributes. The publisher must remain unchanged, and the solution must not introduce another service or custom forwarding code. The incident-response application can be modified.

Which solution meets these requirements?

**Correct answer:** Disable raw message delivery on the subscription. Modify the application to extract the original message and its attributes from the SNS JSON envelope in the SQS message body.

**Explanation:** An SNS subscription to SQS with raw message delivery enabled supports a maximum of 10 message attributes. SNS discards messages with more than 10 attributes for these subscriptions. Disabling raw delivery places the original message and SNS attributes in a JSON envelope in the SQS message body, preserving the attributes without changing the publisher.

### Question 6 (DVA-C02)

**Question:**

An order application publishes events to an Amazon SNS standard topic. Each message body is a JSON object, such as {"eventType":"OrderPlaced","detail":{"region":"eu-west-1","orderId":"A123"}}. The publisher does not include SNS message attributes. A fulfillment application's existing subscription must receive only events whose eventType is OrderPlaced and whose detail.region is eu-west-1. Other subscriptions must remain unaffected, and neither publisher nor consumer code can be changed. Which subscription configuration meets these requirements?

**Correct answer:** Set FilterPolicyScope to MessageBody and set FilterPolicy to {"eventType":["OrderPlaced"],"detail":{"region":["eu-west-1"]}}.

**Explanation:** MessageBody filtering evaluates the JSON message payload and supports nested filter policies. This policy requires both the specified eventType and the nested detail.region value to match. Applying it to the fulfillment subscription leaves other subscriptions unchanged.

### Question 7 (SAA-C03)

**Question:**

A company publishes deployment events to an Amazon SNS standard topic. Three independent partner applications subscribe through HTTPS endpoints. Occasionally, one partner endpoint returns HTTP 503 responses until SNS exhausts its delivery retries. The other partners receive the events successfully. The company must retain events whose delivery retries are exhausted for at least 7 days so that operators can recover them later. Successfully delivered events must not enter this recovery backlog, and failures at one subscription must not cause events to be resent to healthy subscribers. Which solution meets these requirements with the LEAST operational overhead?

**Correct answer:** Create an SQS standard queue with a 14-day retention period for each HTTPS subscription. Configure each subscription's redrive policy to use its queue, and grant SNS permission to send messages to the queues.

**Explanation:** An SNS subscription dead-letter queue captures messages that SNS cannot deliver to that subscriber after delivery attempts are exhausted. Separate queues isolate each partner's delivery failures, retain the failed events for recovery, and do not affect successful delivery to other subscribers.

## Practice Publish-Subscribe Messaging in a full exam

Questions on Publish-Subscribe Messaging in each practice exam, with every answer option and an explanation for each:

- [DEA-C01](https://blowstack.com/practice-exams/aws-certified-data-engineer-associate): 11 questions
- [SAA-C03](https://blowstack.com/practice-exams/aws-certified-solutions-architect-associate): 8 questions
- [DOP-C02](https://blowstack.com/practice-exams/aws-certified-devops-engineer-professional): 7 questions
- [CLF-C02](https://blowstack.com/practice-exams/aws-certified-cloud-practitioner): 2 questions
- [SOA-C03](https://blowstack.com/practice-exams/aws-certified-cloudops-engineer-associate): 2 questions
- [SAP-C03](https://blowstack.com/practice-exams/aws-certified-solutions-architect-professional): 2 questions
- [DVA-C02](https://blowstack.com/practice-exams/aws-certified-developer-associate): 2 questions

## What is Publish-Subscribe Messaging

Publish-subscribe messaging separates the act of producing a message from the work performed by its recipients. A publisher sends a message to a logical destination, commonly called a topic. A messaging service or broker then distributes the message to matching subscriptions. Subscribers might be applications, queues, serverless functions, HTTP endpoints, or human notification channels. The publisher addresses the messaging system rather than maintaining a list of recipients and contacting each one directly.

The defining behavior is one-to-many distribution, often called fan-out. For example, an ordering application can publish an order-created event once. Inventory, shipping, and analytics applications can each receive their own copy and respond independently. Adding a new subscriber generally does not require changing the publisher, although the new consumer must understand the message format and have permission to receive it. Subscription filters can restrict delivery so that a shipping application receives only events relevant to its region or workflow.

In cloud environments, managed messaging services operate the distribution infrastructure and provide integrations with other services. For AWS service-selection questions, Amazon Simple Notification Service, or Amazon SNS, is the primary choice for topic-based fan-out and notifications to supported destinations such as email, SMS, queues, and application endpoints. A monitoring alarm can publish to an SNS topic so that operators receive a notification while an automated system receives the same alert. Amazon CloudWatch detects the alarm condition; SNS distributes the notification. Amazon Simple Email Service, by contrast, is designed for application-generated email rather than general-purpose publish-subscribe distribution.

Publish-subscribe and work queues solve different delivery problems. Multiple workers consuming from one queue normally compete for work; they do not each receive an independent copy of every message. When several applications must independently process the same event, a common design gives each application its own queue and subscribes those queues to a topic. This combines fan-out with buffering, allowing each application to process messages at its own pace and recover from temporary outages within configured retention limits.

Asynchronous delivery introduces trade-offs. A successful publish does not mean that every subscriber has finished processing the message. Duplicates, retries, delays, and ordering behavior depend on the service and configuration, so consumers should generally use idempotent processing and avoid assuming global ordering. Durability, replay, and offline delivery are not guaranteed merely because a system uses publish-subscribe. Configure retention, retry policies, dead-letter handling, and monitoring according to the requirements of each delivery path.

Loose coupling also does not remove the need for coordination. Publishers and subscribers still depend on compatible message schemas and clear event meanings. Engineers should version schemas carefully, restrict publishing and subscription permissions, protect sensitive payloads, and monitor delivery failures. Fan-out also multiplies downstream traffic and processing costs, making filtering and subscriber capacity important design considerations.

## Learn Publish-Subscribe Messaging in lessons

13 short lessons on Publish-Subscribe Messaging in 6 certification courses.

- CLF-C02: Message Queuing vs. Publish-Subscribe Messaging (Premium), https://app.blowstack.com/lessons/message-queuing-vs-publish-subscribe-messaging-clf-c02
- SOA-C03: Publish-Subscribe Messaging: alert distribution through SNS topics (Premium), https://app.blowstack.com/lessons/publish-subscribe-messaging-alert-distribution-through-sns-topics-soa-c03
- SAP-C03: Publish-Subscribe Messaging: real-time subscriber delivery (Premium), https://app.blowstack.com/lessons/publish-subscribe-messaging-real-time-subscriber-delivery-sap-c03
- DEA-C01: Message Queuing vs Publish-Subscribe Messaging: competing consumers and fan-out (Premium), https://app.blowstack.com/lessons/message-queuing-vs-publish-subscribe-messaging-competing-consumers-and-fan-out-dea-c01
- DOP-C02: Message Queuing vs Publish-Subscribe Messaging (Premium), https://app.blowstack.com/lessons/message-queuing-vs-publish-subscribe-messaging-dop-c02
- SAA-C03: Event-Driven Architecture vs Publish-Subscribe Messaging (Premium), https://app.blowstack.com/lessons/event-driven-architecture-vs-publish-subscribe-messaging-saa-c03
