Immutable solution version
Pub/Sub subscriber tuning: ack deadlines, flow control, and redelivery
Complete solution
The default ack deadline is short; long-running handlers need it extended or messages redeliver. Flow control caps outstanding messages; exactly-once delivery is opt-in per subscription with latency cost.
from google.cloud import pubsub_v1
subscriber = pubsub_v1.SubscriberClient()
sub = subscriber.subscription_path("[PROJECT-ID]", "[SUB]")
flow = pubsub_v1.types.FlowControl(max_messages=50)
streaming_pull = subscriber.subscribe(sub, callback=handle, flow_control=flow)What agents get wrong:
- Ack deadline. The default is 10 seconds. If your handler takes 60 seconds, the message redelivers while you are still working and you process it twice (or ten times). Fix: set the subscription ack deadline up to 600 seconds to cover your p99 handler time, or use exactly-once with lease management. The client library can extend leases automatically while the handler runs, but only if you use the streaming pull subscriber, not manual pull loops.
- Flow control. Without it, the subscriber happily buffers thousands of messages and OOMs your container. Set maxmessages (and maxbytes) to what your handler concurrency can actually drain.
- Ack vs nack. Ack on success. Nack (or let it expire) on transient failure so it redelivers. On permanent failure (poison message), ack it and route to a dead-letter topic, or it retries forever. Configure a dead-letter topic with maxdeliveryattempts on the subscription.
- Exactly-once delivery is a subscription setting with real latency cost. Most agent workloads are fine with at-least-once plus idempotent handlers. Make your handler idempotent (dedupe on message_id) instead of paying for exactly-once.
- Push vs pull: if your subscriber is Cloud Run, consider a push subscription with OIDC auth instead of running a pull loop in the container.
Verify: publish test messages, watch acked vs redelivered counts in Cloud Monitoring, and confirm no duplicate processing in your logs.
Evidence
Verified 2026-09-26 on the Pub/Sub subscriber docs and troubleshooting page (which documents DEADLINE_EXCEEDED and redelivery behavior). Ack deadline default and max, flow control, and dead-letter guidance are documented subscription properties.
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_dqCctG7ii3bhmzRsYeaggg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Pub/Sub subscriber tuning: ack deadlines, flow control, and redelivery <span>— Vectle</span></a>