Pub/Sub and Messaging
In one sentence
What it is
Pub/Sub is a messaging service. Publishers send messages to a topic. Subscribers create subscriptions to that topic and receive copies of the messages. The publisher does not know who the subscribers are, and adding a new subscriber requires no change to the publisher.
The service holds messages durably until they are acknowledged, so a subscriber can be slow, restart, or be offline briefly without messages being lost.
Why it matters
Direct synchronous calls between services couple them tightly. If the receiver is slow, the caller is slow. If the receiver is down, the caller fails. Adding a second consumer means changing the caller.
Messaging removes all three problems. The publisher's job ends when the message is accepted. Consumers process at their own pace, retry independently, and can be added or removed without touching the publisher. This is why event-driven architecture is built on it.
Key concepts
- Topic — the named channel messages are published to.
- Subscription — an independent stream of messages from a topic. Each subscription receives every message, so two subscriptions mean two copies.
- Push and pull — push delivers messages to an endpoint you provide; pull has your consumer request them. Push suits serverless handlers; pull gives you control over rate.
- Acknowledgement — the consumer confirms successful processing. Unacknowledged messages are redelivered after the acknowledgement deadline.
- At-least-once delivery — the default guarantee. A message may be delivered more than once, so consumers must be idempotent.
- Ordering key — guarantees ordered delivery for messages sharing a key. It reduces throughput, so enable it only where order genuinely matters.
- Dead-letter topic — after a configured number of failed attempts, the message is moved aside rather than retried forever.
- Message retention and replay — messages are retained for a configurable period and a subscription can be rewound to reprocess history.
How a message flows
- 1A publisher sends a message to a topic and receives confirmation
- 2The message is stored durably and copied to every subscription
- 3Subscription A delivers to an analytics consumer; subscription B delivers to a notification service
- 4Each consumer acknowledges independently once it has finished processing
- 5Unacknowledged messages are redelivered after the deadline expires
- 6Messages that fail repeatedly are routed to a dead-letter topic for inspection
Common use cases
- Decoupling microservices so a slow downstream service does not slow the caller.
- Ingesting event streams from applications, devices or clickstreams into analytics.
- Fanning one event out to several independent consumers — search indexing, notifications, auditing.
- Buffering traffic spikes so downstream systems process at a sustainable rate.
- Triggering serverless functions and Cloud Run services from events.
- Reliably delivering work to background processors with retry and dead-letter handling.
Certification relevance
Where this topic appears, and how deeply each exam goes into it. These are our own assessments based on published exam guides.
- Professional Data Engineer
Heavily tested. Delivery semantics, ordering, dead-letter handling and streaming ingestion patterns all appear.
- Professional Cloud Developer
Event-driven application design, idempotent consumers and integrating with managed runtimes.
- Professional Cloud Architect
Appears in decoupling, resilience and asynchronous integration design.
- Associate Cloud Engineer
Creating topics and subscriptions, and understanding push versus pull delivery.
Practice questions
Data & Analytics practice questions
8 original questions with full explanations.
Related Certifications
Related Cloud Topics
- Dataflow and Pipeline ProcessingBatch and stream processing in one model: windowing, watermarks, late data and the trade-offs that make streaming hard.
- BigQueryA serverless analytics warehouse: partitioning, clustering, the cost model, and how to make queries fast and cheap.
- Cloud RunRun a container without managing servers: request-driven scaling, scale to zero, and per-request billing.
- BigtableA wide-column NoSQL database built for very high throughput and low-latency lookups over enormous datasets.