NashTech Insights

PUB/SUB in Google Cloud

Deepak Kumar
Deepak Kumar
Table of Contents
artificial intelligence, brain, think-3382507.jpg


PUB/SUB stands for “Publisher/Subscriber” and is a messaging system used to exchange messages between different services and applications in a distributed system.

Publishers send messages to a topic in PUB/SUB, while subscribers receive messages from a subscription. PUB/SUB manages message delivery, scales automatically, and supports multiple delivery methods, making it a powerful messaging system that simplifies communication between different components of an application.

Here are the core concepts

  • Topic: To which publisher sends the messages.
  • Publisher: The component or service that sends the message to the topic.
  • Subscription: In order to get the data published on the topic, we must subscribe to that topic. A request from a subscriber to receive messages published on a specific topic.
  • Message: A data that is going to be published and subscribed.
  • Message attribute: Depending on the receiver’s language, the publisher can define a key-value pair for the message.

Data flow in Pub/Sub

It is mainly dependent on the publisher application, topic, and subscribing application.

Publishers are the applications or services that generate data and want to share it with other services or applications. They send messages to a topic in Pub/Sub.

Subscribers are the applications or services that receive the messages sent to the topic. They subscribe to the topic by creating a subscription to receive messages from them.

Pull subscribers using the Pub/Sub API to request messages from a topic. When a pull subscriber requests messages, Pub/Sub returns a batch of messages.

Push subscribers: Applications that receive messages from Pub/Sub. Push subscribers are configured with a URL endpoint that receives messages from Pub/Sub. When a message is published to a topic, Pub/Sub sends the message to all push subscribers subscribed to that topic.

Overall, the data flow of Pub/Sub involves publishers sending messages to a topic, subscribers subscribing to the topic, Pub/Sub delivering messages to subscribers, and subscribers acknowledging and deleting messages once they have been processed.

How are data processes in Pub/Sub?

Create a topic:

  1.  In the google cloud console, navigate to the Pub/Sub topic page.
  2. Click Create a Topic and enter a unique name

Subscribe to the Topic:

  1. Add a subscriber after creating Pub/Sub Topic to this. Click: Create subscriptions.
  2. Name the subscription and select one option push or pull and then create.

Publish a message on the topic:

To publish a message on the created topic click on the message tab, select the subscription, and add a message in the body. Now click Publish.

Pull the data Published:

  1. Go to subscriptions, and click on subscription Id
  2. In the Messages tab, click Pull.


Overall, PUB/SUB is a valuable messaging system that facilitates efficient and reliable communication between services and applications in a distributed system, making it an essential tool for developers working with large-scale applications.


Deepak Kumar

Deepak Kumar

Leave a Comment

Your email address will not be published. Required fields are marked *

Suggested Article

%d bloggers like this: