TECHNOLOGIESTieInn Technologies

Pub/Sub

GCP · 13 questions

Short notes

Key idea

Pub/Sub is a messaging service. Publishers send messages to a topic; each subscription on the topic gets its own copy. It decouples systems: the sender doesn't need to know who reads, or wait for them.

Syntax

gcloud pubsub topics create orders
gcloud pubsub subscriptions create orders-to-bq --topic=orders
gcloud pubsub topics publish orders --message='{"id": 1, "amount": 500}'
  • Pull (the reader asks) or push (Pub/Sub calls an HTTPS endpoint).
  • Ack a message when processed; unacked ones are redelivered after the ack deadline.
  • Dead-letter topics catch messages that keep failing.
  • BigQuery subscriptions write messages straight into a table.

Example

The app publishes each order to orders. One subscription feeds Dataflow for real-time revenue, another sends emails, a third writes to BigQuery. Adding a fourth reader needs no change to the app.

Traps

  • Delivery is at least once: the same message can arrive twice. Make processing idempotent.
  • Order isn't guaranteed unless you use ordering keys.
  • Forgetting to ack causes endless redelivery.
  • Messages are kept 7 days by default; a reader offline longer loses data.

Want the full lesson with step-by-step examples, a project and a certificate? GCP course, ₹120 →

Questions

5 free questions
5 questions

    Pub/Sub

  1. Question 1easy

    Three different services each need every "order placed" message. How many subscriptions?

  2. Pub/Sub

  3. Question 2medium

    Pub/Sub's default delivery is at-least-once. What must a consumer handle?

  4. Pub/Sub

  5. Question 3medium

    When should a subscriber acknowledge a message?

  6. Pub/Sub

  7. Question 4medium

    One malformed message keeps failing and being redelivered. What prevents this from blocking processing?

  8. Pub/Sub

  9. Question 5easy

    What's the simplest way to land Pub/Sub messages in a BigQuery table without writing a pipeline?

8 more questions on this topic, with hints, and tests

Sign up free for 21 days of every question and test.