Google Cloud Pub/Sub: Asynchronous Messaging Service

Reading Time: 3 minutes

What Is Cloud Pub/Sub?

Google Cloud pub/sub icon

Cloud Pub-Sub is a real-time messaging service offered by Google for applications to publish and subscribe to events.

Google Cloud Pub/Sub provides messaging between applications and is designed to provide reliable, many-to-many, asynchronous messaging between applications. Publisher applications can send messages to a “topic” and other applications can subscribe to that topic to receive the messages.

Pub/Sub= Publisher-Subscriber

One can publish the message manually or watch the changes in Gmail using Gmail API and notify the user application on a real-time basis.

Core Components of Google Cloud Pub/Sub

Pub/Sub basics
  • Topic: A named resource (which acts as an alias) to which the publishers send messages.
  • Publisher: It is an application that creates and sends a message to a Pub/Sub topic.
  • Subscriber: It is an application that registers itself to a specified topic of interest in order to get appropriate messages.
  • Subscription: It represents a stream of messages from a single, specific topic, which is delivered to the subscribing application.
  • Message: It is a combination of data and other attributes and is delivered to the subscribers at the end, which is sent by a publisher to a topic.
  • Message attribute: A key-value pair used by a publisher to define a message.

How does Pub/Sub work?

The diagram below explains the key components in the Google Cloud Pub/Sub messaging system and the flow of messages between publishers and subscribers.

Pub/Sub message flow
  1. A publisher application creates a topic in the Publisher/Subscriber service and sends messages to the topic. So, the message comprises a payload and optional attributes describing the payload content.
  2. The service makes sure that published messages are retained on behalf of the subscriptions.
  3. The message published is retained for a subscription till it is acknowledged by a subscriber consuming messages from that particular subscription.
  4. Pub/Sub forwards messages individually from a topic to all of its subscriptions.
  5. Similarly, a subscriber receives messages either by Pub/Sub pushing them to the subscriber’s chosen endpoint.
  6. Hence, an acknowledgment is transmitted by the subscriber to the Pub/Sub service for each received message.
  7. The service then removes acknowledged messages from the subscription’s message queue.

Key Features

1.) In-order delivery at scale: Optional per-key ordering simplifies state full application logic without sacrificing horizontal scale (i.e., no partitions required).

2.) Stream analytics and connectors: The native Data flow integration allows reliable, expressive, processing and integration of event streams in languages such as Java, Python, and SQL.

3.) Cost-optimised ingestion with Pub/Sub Lite: Pub/Sub Lite aims to be the lowest cost option for high-volume event ingestion. Therefore, it offers zonal storage, and users have control of capacity management.

4.) Google Cloud–native integrations: Take advantage of integrations with multiple services, such as Cloud Storage and Gmail update events and Cloud Functions for server-less event-driven computing.

Google Cloud Pub/Sub integration

5.) Dead letter topics: It allows for messages unable to be processed by subscriber applications to be put aside for offline examination and debugging then so that other messages can be processed without any delay.

References: https://cloud.google.com/pubsub/docs/overview

Written by 

Deepak kumar is a Software Intern at Knoldus Inc. He has done Post Graduation from Ajay Kumar Garg Engineering College Ghaziabad. He has the knowledge of various programming languages. He is passionate about Java development and curious to learn Java Technologies. He is a quick learner, problem solver and always enjoy to help others. His hobbies playing Cricket and watching Hollywood movies.