Skip to main content
Welcome back. This lesson explains how acknowledgements (acks) work in Google Cloud Pub/Sub, where they fit in the message lifecycle, the different acknowledgement behaviors, and practical code examples using the Python client library. Proper acknowledgement handling is essential for reliability, avoiding duplicate processing, and designing robust subscriber systems.
Acknowledgements let Pub/Sub know whether a delivered message was processed successfully. If Pub/Sub doesn’t receive an ack, it will assume the message failed and will re-deliver it. Design your subscribers to handle at-least-once delivery semantics.

Message lifecycle and where acknowledgements fit

  1. A topic is created and publishers send messages to it.
  2. A subscription is created for the topic; subscribers either pull messages or receive pushed messages from the subscription.
  3. Pub/Sub delivers a message to the subscriber (push or pull).
  4. The subscriber must acknowledge the message to signal successful processing.
  5. If Pub/Sub does not receive an ack before the ack deadline expires, or if the subscriber explicitly nacks the message, the message becomes eligible for redelivery.

Key implementation details

Acknowledgement types and behaviors

A presentation slide titled "Acknowledgment" showing five colored boxes that summarize different message-acknowledgment types: Negative Acknowledgment (Nack), Explicit Acknowledgment, Modify Acknowledgment Deadline, Auto Acknowledgment, and Ack Deadline Expiry. Each box includes short bullet points explaining the behavior (nack/ack calls, modifyAckDeadline usage, auto-ack risks, and redelivery on deadline expiry).

Practical examples (Python client library)

Synchronous pull: explicitly acknowledge messages
Modify ack deadline (extend lease) for a pulled message
Streaming pull with callback: automatic lease management with explicit ack/nack

Notes on system design and subscriber behavior

  • Subscriber processing times vary. For short, predictable tasks, short ack deadlines may suffice. For long-running tasks, extend the ack deadline per message or increase the subscription default.
  • At-least-once delivery requires idempotency or deduplication. If your processing can’t be made idempotent, use dedupe strategies (unique message IDs, external dedupe stores, etc.).
  • For push endpoints, only return HTTP 2xx when processing actually succeeded. Returning 2xx will stop retries and is treated as an acknowledgement by Pub/Sub.
  • Use modifyAckDeadline() responsibly to avoid holding messages indefinitely and to ensure fair redelivery behavior.
Be careful with auto-ack behavior. If messages are auto-acknowledged before processing completes (or if a push endpoint returns 2xx while processing actually failed), you may lose the ability to retry and risk data loss or missed processing.

Quick exam pointers

  • Pub/Sub uses ack IDs and ack deadlines to manage delivery and retries.
  • The typical exam concept is “at-least-once delivery”: messages may be delivered more than once unless you implement deduplication or enable exactly-once features where supported.

Watch Video