Google Cloud

Messaging & Events — Pub/Sub & Eventarc

Decouple services with one global messaging service, and know how its delivery guarantees actually behave.

Pub/Sub is GCP's single messaging service, and it is global by default — no regional endpoint to choose.

A newsroom wire. Every subscribing desk gets its own copy of each story, works through its own backlog at its own pace, and can go back through the last week if it missed something.

Key Concepts

1
    publisher -> [ topic ] -> subscription A -> service 1
                           -> subscription B -> service 2
2
A subscription is the unit of delivery. Each gets its own copy of every message and its own acknowledgement state, so adding a consumer never affects the others — the thing that normally needs a separate queue elsewhere.
3
Push or pull, and the choice matters.
    pull   your consumer asks for messages. Good for throughput and
           for controlling your own rate.
    push   Pub/Sub POSTs to your HTTPS endpoint. Good for Cloud Run
           and Functions. Delivery rate adapts to your responses.
4
Acknowledgement works like a lease.
    deliver -> ack deadline (default 10s, extendable to 600s)
            -> ack()   message removed for this subscription
            -> no ack  redelivered
5
Processing that outlives the deadline means the message is delivered again. The client libraries extend the deadline automatically while you work, which is why using them beats raw API calls.
6
At-least-once is the default, so consumers must be idempotent. Exactly-once delivery is available per subscription within a region, at a throughput cost.
7
Ordering is off unless you ask for it. Enable message ordering and supply an ordering key, and messages with the same key are delivered in order — at the cost of throughput for that key.
8
Dead-letter topics catch poison messages after a maximum delivery attempt count, instead of retrying forever.
9
Retention and replay are the underrated features: messages are kept for up to 7 days, and seek rewinds a subscription to a timestamp or a snapshot. So after fixing a consumer bug you can reprocess, which usually requires a streaming product elsewhere.
seek
10
Eventarc routes Google Cloud events — an object created, an audit log entry — to Cloud Run, Functions or Workflows, using Pub/Sub underneath with CloudEvents formatting.
11
What the interviewer is probing.1. "What is the unit of delivery in Pub/Sub?" Probing: the subscription model. Stalls: "The topic." Moves up: the subscription — each gets its own copy and its own acknowledgement state, so adding a consumer never affects the others.
12
2. "Push or pull?" Probing: the trade. Stalls: "Push is simpler." Moves up: pull for throughput and rate control; push for Cloud Run and Functions, where delivery rate adapts to your responses.
13
3. "What happens if processing outlives the ack deadline?" Probing: redelivery. Stalls: "It waits." Moves up: the message is redelivered and processed twice — which is why consumers must be idempotent and the client libraries extend the deadline automatically.
14
4. "How do you reprocess yesterday's events after fixing a bug?" Probing: seek, which many do not know exists. Stalls: "You cannot, they are consumed." Moves up: messages are retained up to 7 days and seek rewinds a subscription to a timestamp or snapshot.