Google Cloud / Editorial solution guide

Diagnose Pub/Sub Backlog and Duplicate Effects

Trace publish identity, subscription delivery, acknowledgment, and the application commit boundary before assuming lost or exactly-once work.

About 3 min readContent reviewed

Read-only knowledge base · No public comments

Recognize the symptoms

Oldest-unacknowledged age or backlog grows, messages appear repeatedly, or a database effect is duplicated. A repeated delivery is not automatically a Pub/Sub defect, and a successful publish is not proof of completed application work. Separate delivery attempts, unique publishes, application event identity, and durable effects before choosing a correction.

Understand the likely causes

  • Consumers can be slower than arrivals, lose acknowledgment deadlines, fail after committing, or retry malformed events indefinitely. Publishing retries can also produce duplicates. Exactly-once delivery has supported subscription/regional scope and does not make an arbitrary database transaction atomic with acknowledgment. Ordering, retention, dead-letter policy, permissions, and flow control each affect progress differently.

1. Identify the exact subscription and event identity

Record topic/subscription, delivery type, region/endpoint assumptions, consumer identity, message/application event identifiers, and timing from existing authorized evidence. Separate the same message redelivered from two unique publishes representing one business event. Do not publish test traffic or inspect a configured account from this guide. A synthetic record can establish the questions without creating a workload.

2. Compare arrival, processing, and retry rates

Inspect the defined time window and units for backlog, age, processing latency, errors, and downstream saturation. Retries consume work too, so unique-event rate alone can understate load. An acknowledgment deadline change may delay a symptom without improving capacity. Flow-control and concurrency settings should protect consumer memory and dependencies rather than create an unbounded hidden queue.

3. Check a synthetic effect ledger

The complete offline program parses three invented delivery records and compares delivery count with unique event count. It reports one duplicate opportunity and a unique-event total. The in-memory dictionary is deliberately not a distributed deduplication implementation; a real design must preserve state across restarts and coordinate the effect with its processed marker. Conflicting payloads require review rather than silent overwrite.

python Inspect an invented effect ledger
import json

records = json.loads('[{"event":"a","amount":10},{"event":"a","amount":10},{"event":"b","amount":20}]')
ledger = {}
for record in records:
    key = record["event"]
    if key in ledger and ledger[key] != record["amount"]: raise ValueError("conflicting synthetic event")
    ledger[key] = record["amount"]
print(f"deliveries={len(records)} unique={len(ledger)} duplicate_opportunities={len(records) - len(ledger)} total={sum(ledger.values())}")
Expected output
deliveries=3 unique=2 duplicate_opportunities=1 total=30

Three deliveries represent two consistent invented events totaling30; no subscription is opened.

4. Review the acknowledgment and commit boundary

Acknowledging before required work is durable can lose application work. Committing before an acknowledgment is known successful can lead to a repeated attempt. Define atomic/idempotent processing appropriate to the data store and business operation. A transport guarantee does not remove publishing duplicates or turn a separately committed effect into one transaction. Confirm the selected delivery feature’s current scope.

5. Define bounded retries, review, and replay

Handle invalid schemas and poison events through a documented retry/dead-letter review process with the required identities and permissions. Ordering keys can constrain progress; they are not validation. Replay and retention expiry need an idempotency horizon matching the business requirement. Do not purge, seek, acknowledge, change policies, or scale consumers against a real subscription as an unplanned diagnostic action.

Verify the fix

The local program must report deliveries=3 unique=2 duplicate_opportunities=1 total=30. A real correction needs approved evidence for consumer completion, acknowledgment behavior, downstream effect consistency, backlog trend, and relevant failure/replay cases. Distinguish application event duplicates from delivery duplicates. No cloud delivery, ordering, exactly-once, retention, or quota claim is validated by the local ledger.

Keep it from recurring

  • Preserve event identity, schema/version, bounded flow control, retry policy, and durable idempotency design. Document delivery mode and regional assumptions, acknowledgment boundary, dead-letter ownership, and replay behavior. Link operational alerts to an approved runbook and never treat a process-local set as a persistent exactly-once guarantee.

Official references