Publish-Subscribe

Definition

Messaging pattern where publishers broadcast to topics without knowing subscribers, decoupling producers from consumers for scalable architectures.

Use Cases

Provider Equivalents

Frequently Asked Questions

What's the difference between Publish-Subscribe and a message queue?
In publish-subscribe (pub/sub), a message is published to a topic and can be delivered to multiple subscribers (fan-out). In a queue, messages are typically consumed by one worker/consumer (competing consumers) so each message is processed once. Use pub/sub when multiple systems need the same event; use queues when you want to distribute work across workers.
When should I use Publish-Subscribe?
Use pub/sub when you need to broadcast events to multiple independent consumers, such as order events going to inventory, shipping, and email services. It’s a good fit for event-driven architectures, integrating microservices, and adding new consumers later without changing the publisher. Avoid pub/sub if you need strict request/response behavior or if exactly-one consumer must process each message (a queue is often better).
How much does Publish-Subscribe cost?
Costs usually depend on the number of messages published, delivered, and sometimes the payload size and delivery type. You may also pay for data transfer and for downstream services that process messages (functions, containers, or VMs). For example, AWS SNS pricing is based on publishes, deliveries (including HTTP/S, email, SMS, and other protocols), and data transfer; Azure Service Bus Topics and Google Cloud Pub/Sub generally charge by operations/messages and throughput-related factors. Always estimate using your expected message rate, average message size, number of subscriptions, and retry/redelivery behavior.

Category: integration

Difficulty: intermediate

Related Terms

See Also