Pub/Sub Study Notes
Pub/Sub is Google Cloud's fully managed, real-time messaging service for sending and receiving messages between independent applications. Publishers send messages to a topic, and subscribers receive them through subscriptions, which decouples producers from consumers completely. It scales automatically to handle very high message volumes and delivers messages at least once by default.
Key facts
- A topic is a named channel to which publishers send messages, and a subscription is a named configuration that delivers messages from one topic to a specific subscriber.
- Each subscription is attached to exactly one topic, but a single topic can have many subscriptions, letting multiple independent consumers each receive a copy of every message.
- Pub/Sub supports pull subscriptions, where the subscriber requests messages, and push subscriptions, where Pub/Sub sends messages to a configured HTTPS endpoint.
- Message ordering can be enabled with ordering keys, which deliver messages with the same key in publish order, although this can reduce throughput for that key.
- When a subscription enables exactly-once delivery, Pub/Sub works to ensure each message is processed only once, provided the subscriber acknowledges correctly within the subscription.
- Dead-letter topics capture messages that cannot be delivered after a configured number of delivery attempts, so poison messages do not block healthy processing indefinitely.
- Messages are retained for a limited period if undelivered, by default up to seven days at the time of writing, after which undelivered messages are discarded.
- Schemas can be attached to a topic to validate message structure in Avro or Protocol Buffers format before messages are accepted for publishing.
- Pub/Sub integrates natively with Dataflow, Cloud Run, Cloud Functions, and BigQuery subscriptions, which can write messages directly into a BigQuery table.
What the exam expects you to know
- The exam tests decoupling: when a scenario needs to buffer, fan out, or asynchronously connect services, Pub/Sub is usually the intended answer over direct API calls.
- Know the difference between push and pull delivery, including that push requires a publicly reachable HTTPS endpoint that can handle Pub/Sub authentication.
- Expect questions on acknowledgement deadlines, redelivery, and how unacknowledged messages are sent again until they expire or reach a dead-letter topic.
- Candidates should distinguish at-least-once default delivery from exactly-once delivery and understand that consumers should still be designed to handle duplicates safely.
- Ordering questions focus on ordering keys and the trade-off that ordering is per key, not a guarantee of global order across all messages.
- You may be asked which service handles event ingestion and streaming pipelines, where Pub/Sub feeds Dataflow or a BigQuery subscription for processing.
Pub/Sub vs Cloud Tasks: when to use which
Choose Pub/Sub when many consumers need to react to the same event, when order of consumers does not matter, or when you are building a streaming ingestion pipeline. Messages are published once and fanned out to every subscription. Choose Cloud Tasks when a single worker must execute a specific task, such as calling one HTTP endpoint, with control over rate, retries, and scheduled dispatch time. In short, Pub/Sub broadcasts events to whoever is listening, while Cloud Tasks dispatches individual units of work to a chosen target. Exam scenarios mentioning fan-out or streaming point to Pub/Sub. See also the Cloud Tasks notes.
Useful gcloud commands
gcloud pubsub topics create my-topic
gcloud pubsub subscriptions create my-sub --topic=my-topic
gcloud pubsub topics publish my-topic --message='hello'
gcloud pubsub subscriptions pull my-sub --limit=5Common exam traps
- Pub/Sub does not guarantee global ordering by default: without ordering keys and an ordering-enabled subscription, messages can arrive out of publish order.
- Acknowledging a message before processing finishes risks data loss in your application logic, because Pub/Sub will not redeliver an acknowledged message.
- A topic and a subscription are not interchangeable: publishers write to topics, subscribers read from subscriptions, and deleting a subscription loses its undelivered backlog view.
- Pub/Sub is not a task queue with per-task scheduling control: if a scenario needs a specific dispatch time or strict rate limiting, Cloud Tasks fits better.
Frequently asked questions
What happens if a subscriber does not acknowledge a message?
Pub/Sub waits until the acknowledgement deadline expires and then redelivers the message to an available subscriber for that subscription. This continues until the message is acknowledged, the message retention period expires, or a configured maximum delivery attempt count sends it to a dead-letter topic for separate handling and investigation.
Should I use push or pull subscriptions?
Use pull when the subscriber can control its own consumption rate and can run continuously, such as a service on Compute Engine or Google Kubernetes Engine. Use push when you want Pub/Sub to invoke a webhook or serverless endpoint automatically, and that endpoint can accept HTTPS requests, verify tokens, and return a success response quickly.
Does Pub/Sub deliver messages exactly once?
By default Pub/Sub provides at-least-once delivery, so duplicates are possible and subscribers should be idempotent. Exactly-once delivery can be enabled on pull subscriptions, which reduces duplicate processing when acknowledgements are handled correctly, but application design should still tolerate edge cases, retries, and failures outside Pub/Sub itself for full reliability.
Study aid disclaimer: Cloud Cert Notes is an independent educational study aid. It is not affiliated with, endorsed by, or sponsored by Google, Microsoft, Amazon, Oracle, or Alibaba. Google Cloud, Associate Cloud Engineer, and Cloud Digital Leader are trademarks of Google LLC; all other certification names and product names are trademarks of their respective owners. Always confirm service details against the official provider documentation before sitting an exam.