Cloud concept · Updated

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.

In short

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.

Cloud Concepts Hub →

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.

01
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.

02
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.

03
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.

04
Asynchronous processing

Publishing and subscriber processing occur separately. Applications must distinguish acceptance by the messaging service from completion of downstream business operations.

05
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.

06
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 EventBridgeAmazon 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 CloudWatchAmazon 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. Answer them with every option in the exam simulator.

CLF-C02

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?

Show answerCORRECT ANSWER

Publish payment messages to one Amazon SNS topic and subscribe each processing function to that topic.

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.

SOA-C03

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?

Show answerCORRECT 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.

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.

SAP-C03

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?

Show answerCORRECT 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.

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.

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:

Start a free practice exam

What is Publish-Subscribe Messaging

2 min read

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.

and 7 more lessons

Open the lessons