Publish-Subscribe
Definition
Messaging pattern where publishers broadcast to topics without knowing subscribers, decoupling producers from consumers for scalable architectures.
Use Cases
- Netflix: Event-driven microservices where one service emits events and multiple downstream services react (fan-out) without tight coupling. — Netflix has publicly described using an event-driven architecture on AWS, commonly leveraging managed messaging/notification patterns (including topic-based fan-out) to distribute events to multiple consumers and decouple services. (Improved service decoupling and scalability, enabling independent evolution of services and more resilient asynchronous processing.)
- The New York Times: Processing and distributing content-related events (e.g., media ingestion and processing steps) to multiple systems. — The New York Times has publicly shared its use of Google Cloud Pub/Sub as part of cloud-based data and content pipelines to distribute messages to multiple subscribers for downstream processing. (More reliable, scalable pipelines and easier integration between independently deployed components.)
- Spotify: Asynchronous event distribution between services for analytics and operational workflows. — Spotify has publicly discussed using Google Cloud Pub/Sub in parts of its Google Cloud data platform to move events/messages between producers and multiple consumers. (Reduced coupling between systems and improved throughput for event-driven processing at scale.)
Provider Equivalents
- AWS: Amazon Simple Notification Service (SNS)
- Azure: Azure Service Bus Topics
- GCP: Google Cloud Pub/Sub
- OCI: OCI Notifications
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