What Is Cloud Pub/Sub? Design Message Delivery and Duplicate Handling
Cloud Pub/Sub is a Google Cloud messaging service that lets systems communicate asynchronously without directly connecting the message sender to the processor. Publishers send messages to a topic, and subscribers receive them through subscriptions, so producers and consumers can be deployed and scaled independently. However, the default delivery is at least once, and ordering is not guaranteed by default. Treat redelivery and duplicates as normal possibilities, and design acknowledgment timing and idempotent processing together.
What Is Cloud Pub/Sub? Design Message Delivery and Duplicate Handling
Cloud Pub/Sub is a Google Cloud messaging service that lets systems communicate asynchronously without directly connecting the message sender to the processor. Publishers send messages to a topic, and subscribers receive them through subscriptions, so producers and consumers can be deployed and scaled independently. However, the default delivery is at least once, and ordering is not guaranteed by default. Treat redelivery and duplicates as normal possibilities, and design acknowledgment timing and idempotent processing together.
Publisher
│
▼
Topic
├────────> Subscription A ─────> Subscriber instances (share work)
└────────> Subscription B ─────> Subscriber instances (share work)How are topics, subscriptions, and messages related?
A publisher creates an event or task as a message and publishes it to a topic. A subscription is an independent delivery path that expresses interest in messages from a particular topic. A subscriber receives and processes messages through that path. The message body carries application data; attributes can accompany it to convey metadata such as event type or origin.
When a topic has multiple subscriptions, each subscription receives its own copy of a message. This supports fan-out: for example, sending one order event to an analytics pipeline, an inventory processor, and a notification service. By contrast, multiple subscriber instances attached to one subscription divide the messages among themselves, which is useful for distributing work and scaling horizontally. Publishing to a topic does not identify a receiving application or prove that processing finished; delivery and acknowledgment state are tracked per subscription.
When should you choose pull, push, or export subscriptions?
With a pull subscription, the consumer program requests messages from Pub/Sub. This is flexible when the consumer needs to control throughput, concurrency, flow control, and acknowledgment timing. With a push subscription, Pub/Sub sends requests to the consumer endpoint. This can suit a simple service that receives messages through a public HTTPS endpoint. The endpoint response is tied to acknowledgment, so account for request timeouts, response codes, and retry behavior.
An export subscription sends messages directly to a Google Cloud destination such as BigQuery or Cloud Storage without an intermediate consumer program. This avoids writing code to receive each message, but supported destinations and transformation or error handling differ from a conventional pull consumer. Choose based on whether you need custom processing and acknowledgment control, can receive messages through an HTTP endpoint, or want to write them directly to a storage destination.
How do acknowledgments and redelivery work?
After receiving a message, a subscriber sends an acknowledgment (ack) when processing is complete. Pub/Sub keeps the message outstanding until it receives the acknowledgment. If the subscription’s acknowledgment deadline passes first, the message can be delivered again. Redelivery can also follow a negative acknowledgment (nack) or a temporary failure to respond. Consumer logic should therefore assume a message might be processed more than once.
A practical order is to process the message first and acknowledge it after the result is safely recorded. If you acknowledge before processing and the work then fails, the default behavior might not redeliver the message. Conversely, if processing finishes but the acknowledgment is lost to a network problem, the message might be redelivered. Use a stable business identifier, such as an order ID, to detect work already applied and reduce duplicate effects. This is idempotency: processing the same message again produces the same final result as processing it once.
Exactly-once delivery can suppress duplicate deliveries more strictly, but it is not a universal default for every delivery type. According to the official documentation, it is supported only for pull subscriptions and its guarantee applies when the subscriber connects in the same region. Enabling it does not combine an application database update and a message acknowledgment into one atomic transaction, so business-level duplicate protection still matters. Check the added latency and quota requirements as well.
What should you configure when message order matters?
Pub/Sub does not guarantee publish order by default. For a unit where order matters, such as a particular order or account, the publisher can set an ordering key and the subscription can enable ordering. Messages with the same key can then be delivered in the order Pub/Sub receives them in the same region. There is no global ordering guarantee across different keys, so this is not a mechanism that puts every message into one sequence.
Ordering can affect throughput and available parallelism. If an earlier message for a key is not acknowledged, acknowledgments for later messages can be blocked or messages can be redelivered. Identify exactly which business operations require ordering, avoid sharing one key too broadly, and verify that the subscriber processes and acknowledges messages sequentially within each key. For messages that do not need ordering, omit the key to avoid unnecessary serialization.
Example: route order events to inventory and notifications
Hypothetical example: Suppose an online store publishes order-confirmed events to an orders topic. Create one subscription for the inventory service and another for customer notifications; both services then receive the same event independently. The inventory service records the order ID in its processing record and acknowledges the message after the inventory change is committed. The notification service checks the order number and contact details, sends the notification, and records whether it has already sent one so it can handle redelivery.
If the inventory service is temporarily unavailable, the message might be redelivered after its acknowledgment deadline expires. For recoverable transient errors, consider increasing retry delays with exponential backoff. For messages that cannot be processed, such as malformed input, configure a dead-letter topic on the subscription to provide a separate investigation path. The maximum dead-letter delivery count is approximate, and IAM permissions also need to be configured, so do not treat it as an exact-count guarantee. This scenario is an illustrative assumption, not a result from testing a real system.
How can you protect consumers from failures and traffic spikes?
If a consumer receives more messages than it can process, it can miss acknowledgment deadlines; redelivery then adds even more load. A pull consumer can control flow by limiting outstanding message count and bytes, and can extend acknowledgment deadlines to match processing time. A push consumer needs to manage endpoint throughput and response latency. Recording message IDs and business identifiers helps investigate redeliveries and duplicates.
Monitor the dead-letter subscription so failures can be diagnosed, and use message schemas or input validation to manage the data format between producers and consumers. If you need replay, check that topic retention and the subscription’s seek or replay features meet your requirements. Do not assume every message is retained indefinitely or can be replayed to any point; define retention and reprocessing procedures in advance.
When is Pub/Sub a good fit, and what should you compare?
Pub/Sub is a candidate for asynchronous event delivery when producers and consumers should be deployed and scaled independently, for fan-out to multiple systems, and for distributing consumer work. If scheduling a task for a specific time or controlling the rate of individual tasks is central, compare a messaging broker with a task scheduler’s role. For a synchronous request and response within one service, HTTP or RPC might be simpler.
Before choosing, define message throughput and size, acceptable latency, ordering needs, the business impact of duplicates, replay and retention requirements, consumer deployment model, data location, and access permissions. In particular, “deliver a message once” and “apply its business effect once” are not the same guarantee. Evaluate Pub/Sub delivery semantics together with transaction and deduplication design in the consumer’s data store.
References
[Google Cloud documentation: Pub/Sub service overview](https://docs.cloud.google.com/pubsub/docs/pubsub-basics)
[Google Cloud documentation: Subscription overview and default delivery](https://docs.cloud.google.com/pubsub/docs/subscription-overview)
[Google Cloud documentation: Best practices for choosing a subscription type](https://docs.cloud.google.com/pubsub/docs/subscribe-best-practices?hl=en)
[Google Cloud documentation: Subscription retry policy](https://docs.cloud.google.com/pubsub/docs/subscription-retry-policy)
[Google Cloud documentation: Subscription properties, retry, and dead-letter settings](https://docs.cloud.google.com/pubsub/docs/subscription-properties)
[Google Cloud documentation: Dead-letter topics](https://docs.cloud.google.com/pubsub/docs/dead-letter-topics)
[Google Cloud documentation: Ordering messages](https://docs.cloud.google.com/pubsub/docs/ordering)
[Google Cloud documentation: Scope and limits of exactly-once delivery](https://docs.cloud.google.com/pubsub/docs/exactly-once-delivery)
Google Cloud’s official documentation was checked on November 21, 2026. Supported delivery modes and their limits can change; check the current documentation for each subscription type before adoption.