Intro to Google Cloud Pub/Sub

Google Cloud Pub/Sub is a messaging service that uses a publish/subscribe-based mechanism for sending and receiving messages among applications and services. It’s designed to support both push- and pull-based models for message delivery, unlike SNS and SQS which use push-based and pull-based models respectively to deliver messages.

For the push-based delivery, Pub/Sub initiates requests to the subscriber application (chosen endpoint) to push messages. In pull-based delivery, it’s the subscriber application that initiates requests to the Pub/Sub server for retrieval of messages. Google Cloud Pub/Sub also supports many-to-one (fan-in), one-to-many (fan-out), and many-to-many asynchronous messaging between independent applications.

Note: Pub/Sub often gives preference to older messages first, but it does not guarantee first-in-first-out (FIFO) or in-order delivery. Check Message Ordering for detailed information on how you can receive messages in the order that the Pub/Sub service receives them.

Copy link to clipboardHow Did Google Cloud Pub/Sub come about?

Google Cloud Pub/Sub was released in August 2015, alongside another cloud service (Cloud Dataflow). However, it was first introduced (briefly) at the Google I/O developer conference in June 2014 before its actual release. Cloud Pub/Sub — a backend messaging service enabling developers to send and receive data in the form of ‘’messages’’ between applications — launched in public beta on March 4, 2015.  

Google Cloud Pub/Sub is, at its core, a scalable messaging middleware service designed to allow developers to handle big data. It also allows developers to exchange information between independently written applications hosted on the Google Cloud Platform or anywhere on the internet. Today, it’s used by Client Platform, 9GAG, Samba Tech, Groww, and Postclick, among others.

Copy link to clipboardHow does Google Cloud Pub/Sub work?

Google Cloud Pub/Sub basic concepts

Here are some core concepts of this scalable messaging middleware:

  • Pub/Sub topic: a named resource that represents a stream of messages that a publisher sends. It’s an intermediary communication channel that allows applications to connect with one another within the Pub/Sub messaging system.

  • Pub/Sub Publisher: an application that creates and sends a message to a Pub/Sub topic. It’s also called a ‘’producer’’.

  • Pub/Sub Subscriber: an application that subscribes (registers) itself to a specified topic of interest in order to receive appropriate messages.

  • Pub/Sub Subscription: a named entity connecting and delivering a specified topic to a subscriber endpoint. A subscription is created from a topic and delivered to the subscribing applications. See the Subscriber Guide to learn more about Pub/Sub subscription and message delivery semantics.

  • Pub/Sub Message: the combination of data that the publisher sent to a topic

  • Pub/Sub Message attribute:  an optional key-value pair that a publisher can embed in the message body. Attributes could be text, strings, or byte strings.

The diagram below represents an overview of the key components in the Pub/Sub messaging system and how messages flow between publishers and subscribers.

Google Cloud Pub/Sub key components and flow

1. A publisher application creates a topic in the Cloud Pub/Sub service and sends a request to the Pub/Sub Server to push the messages to the desired topic.

2. The Pub/Sub service stores the published messages for a subscription until acknowledged by a subscriber consuming messages from that subscription.

3. Pub/Sub pushes messages from a cloud Pub/Sub topic to all of its appropriate subscriptions independently.

4. A subscriber that makes a ‘’subscription’’ to the specified topic receives messages either by pulling them from the Pub/Sub server or by Pub/Sub pushing them to the subscriber application (chosen endpoint).

5. The subscriber acknowledges the received message by sending a success response to the Pub/Sub service for each received message. A non-success response means that the message should be marked for redelivery.

6 (3). The Pub/Sub service removes messages with a success acknowledgement response from the subscription’s message queue so that they cannot be pulled again. 

Technical Overview of Google Cloud Pub/Sub

From the developers’ standpoint, Google Cloud Pub/Sub features both traditional REST/HTTP and gRPC service APIs. With these two service APIs, advanced developers have the option to write and use their own client code to directly access Pub/Sub’s REST/HTTP and gRPC APIs. However, this approach is recommended only if the provided client libraries do not meet your programming language requirements or other specific needs.

Google Cloud Pub/Sub integrates with multiple tools such as Cloud Functions, Cloud Functions for Firebase, Google Cloud Source Repositories, Snowplow, App EngineCloud Run, Google Cloud IoT Core, among others (or custom environments on Google Kubernetes Engine or Computer Engine). Cloud Pub/Sub also supports third-party and OSS integrations.

Google Cloud Pub/Sub is subscribed to HIPAA-compliant service to allow developers to store and transmit protected health information (PHI) between healthcare systems.

Cloud Pub/Sub also provides access control using Identity and Access Management (IAM) to allow you to define permission for all Pub/Sub topics and subscription both at the project and individual resource levels. Pub/Sub offers several layers of end-to-end encryption to protect messages stored at rest (using AES256) and in transit (using CMEK) in Google Cloud Platform.

Copy link to clipboardGoogle Cloud Pub/Sub Pros:

✔ Fully-managed and highly scalable messaging middleware service

✔ Provides good support for asynchronous processes 

✔ A dedicated topic for unprocessed messages (dead-letter topic)

✔ Supports traditional, third-party, and OSS Integrations

✔ HIPAA compliant 

Copy link to clipboardGoogle Cloud Pub/Sub Cons:

×      Message ordering is not guaranteed

×      Multiple transfer services can be complicated

Copy link to clipboardRead more…

Why developers like Google Cloud Pub/Sub

What is Pub/Sub? | Cloud Pub/Sub Documentation | Google Cloud

Google Cloud for AWS Professionals: Application Services

Introduction to Google Cloud Pub/Sub

Subscriber Overview | Cloud Pub/Sub | Google Cloud

Pub/Sub: A Google-Scale Messaging Service | Google Cloud