Skip to main content

Cloud

Google Cloud – PUB/SUB: Part 1 – Basic Concepts

Shot Of Corridor In Working Data Center Full Of Rack Servers And Supercomputers With Cloud Storage Advantages Icon Visualization.

Google Cloud

Google Cloud Platform (GCP), offered by Google, provides a broad spectrum of cloud computing solutions. It includes modular services across computing, data storage, analytics, and machine learning, supported by a suite of management tools. GCP stands out as a leading public cloud provider, providing a flexible array of computing services ranging from data management to web and video delivery, enhanced with advanced AI and machine learning functionalities. Its offerings encompass computing, storage, networking, big data handling, machine learning, and IoT, complemented by strong cloud management, security capabilities, and developer support.

 

Gcp Platforms

Let’s Understand Google Pub/Sub

Google Cloud Pub/Sub is a reliable messaging platform that enables secure and scalable communication between applications by separating senders and receivers. It’s essential for streaming analytics, data pipelines, and service integration, as well as supporting asynchronous event streaming for efficient data distribution and task parallelization.

Google Cloud Pub/Sub is a fully managed real-time messaging service that allows users to send and receive messages between independent applications.

The Basics of Google Cloud Pub/Sub

1. Key Concepts

  • Topic: A named resource to which messages are sent by publishers.
  • Subscription: Represents the stream of messages from a topic to a subscriber application.
  • Message: A publisher first sends data to a topic and subsequently delivers it to subscribers.
  • Publisher: An application that creates messages for topics.
  • Subscriber: An application that receives messages from topics through subscriptions.

2. Features and Capabilities

  • Scalability: Pub/Sub can handle real-time, high-volume data ingestion and delivery.
  • Durability: Messages persist and are retained until they are acknowledged by subscribers.
  • Reliability: Provides at least one message delivery guarantee.
  • Global: Pub/Sub topics and subscriptions can be international, enabling distributed systems.

3. Use Cases

  • Real-time Analytics: Streaming data for analysis, monitoring, and alerting.
  • Event-driven Architectures: Building event-driven systems for decoupled services.
  • Data Ingestion: Collecting and processing data from IoT devices, logs, etc.
  • Integration: Integrating systems and services in a loosely coupled manner.

4. Workflow

  • Publishers send messages to topics.
  • Subscribers create subscriptions to topics to receive messages.
  • Messages are delivered asynchronously and can be acknowledged by subscribers.
  • Supports push and pull delivery modes for subscriptions.

5. Integration and APIs

  • Provides client libraries and REST APIs to integrate various programming languages and platforms.
  • Integration with other Google Cloud services like Cloud Functions, Dataflow, BigQuery, etc.

6. Pricing

  • Charges are based on the volume of data exchanged and operations performed.
  • Offers a free tier with a certain amount of data and operations included.

7. Security

  • Supports IAM roles and permissions for access control.
  • It also supports encryption of data both in transit and at rest.

8. Monitoring and Logging

  • Provides monitoring and alerting capabilities via Stackdriver Monitoring.
  • Logs are available through Stackdriver Logging for debugging and audit purposes.

Google Cloud Pub/Sub is designed to be highly available, scalable, and reliable, making it suitable for building modern, cloud-native applications that require real-time messaging capabilities.

Request-Response vs. Pub-Sub Architecture

Request-Response Architecture

The typical model for computers communicating on a network is request-response. In the request-response model, a client computer or software requests data or services, and a server computer or software responds by providing the data or service.

Req Res Architecture

  • In this model, a client initiates communication by requesting data or services from a server.
  • The client sends a request, and the server responds with the requested data or service.
  • This model is akin to a client sending an empty truck to be filled with data by the server, which then sends the truck back and loaded.
  • Examples include printing a document, where the client (e.g., spreadsheet program) requests printer services from the server (print server), which then processes and completes the print job.

Publish-Subscribe Architecture

  • In pub-sub architecture, a central entity called a broker (or server) manages data distribution.
  • Clients can either publish data to the broker, subscribe to receive data from it, or perform both actions.
  • Publishers send data to the broker only when it changes (report by exception), while subscribers automatically receive data from the broker, but only when it changes.
  • The broker is a facilitator, routing data from publishers to subscribers without storing it.
  • In analogy, publishers send full data trucks to the broker, which then routes them intact to subscribing clients, cloning if necessary.
  • For instance, in the diagram, clients on the left publish data consumed by clients on the right, and vice versa.

Pub Sub Architecture

Lifecycle of a Message in Pub/Sub

In Google Cloud Pub/Sub, the lifecycle of a message typically involves several stages, from publication to consumption and acknowledgment.

Assume that a single publisher client is connected to a topic, and the topic has a single subscription attached to it. So, a single subscriber is connected to the subscription as well.

Pub Sub Lifecycle

Here’s the process detailing how a message traverses through Google Cloud Pub/Sub:

  • A publisher application sends a message to a specified Pub/Sub topic.
  • The message is stored persistently for reliability and fault tolerance.
  • At the same time, Pub/Sub delivers the message to all subscribed subscriptions associated with the topic. In this instance, there is only a single subscription.
  • The subscription forwards the message to the connected subscriber application(s).
  • Upon processing the message, the subscriber sends an acknowledgment to Pub/Sub, confirming successful handling.
  • After successfully receiving acknowledgments from at least one subscriber for each subscription, Pub/Sub automatically deletes the message from storage, thereby ensuring efficient message management and cleanup.

Google Cloud Pub/Sub is a wholly managed messaging service on Google Cloud Platform, enabling asynchronous communication between applications in real-time. It uses topics to categorize messages and subscriptions to deliver them reliably at scale. Pub/Sub supports push and pull delivery methods, integrates seamlessly with other Google Cloud services, and ensures data security through encryption. It’s ideal for applications needing scalable, reliable messaging for use cases like real-time analytics, IoT data processing, and event-driven architectures, offering robust monitoring and logging capabilities for operational visibility.

If you want to learn more, Google Cloud provides comprehensive documentation and tutorials on Google Cloud Pub/Sub.

Thoughts on “Google Cloud – PUB/SUB: Part 1 – Basic Concepts”

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Hemlata Sahu

Hemlata Sahu is a Technical Consultant at Perficient Nagpur. She is passionate about exploring new technologies and tools in testing. A creative problem solver, she has extensive experience in API automation using the Rest Assured BDD framework, Karate, API testing with POSTMAN, manual testing, and GCloud Pub/Sub testing. Hemlata is dedicated to staying at the forefront of the testing field and sharing her insights with others.

More from this Author

Follow Us