In this blog, we will discuss Pub/Sub Lite in detail. In GCP, Pub/Sub means Publish/Subscribe. There exist two Pub/Sub services in GCP; one is the general Pub/Sub service and another in Pub/Sub Lite. Let us see how is Pub/Sub Lite different from Pub/Sub.
This article will help you add a little extra to your knowledge of Google Cloud and its services, so without further ado, let’s get started!
Pub/Sub in Google Cloud Platform
Pub/Sub messaging or Public/Subscribe messaging is a service-to-service communication that is asynchronous in nature. It is used in serverless and microservices architectures.
Pub/Sub provides reliable, many-to-many, and asynchronous messaging between the applications. It boosts a system’s overall flexibility and robustness.
Need for Pub/Sub Lite
At times there is demand for the very low cost of operation, this is exactly where Pub/Sub Lite comes into the picture. Let us discuss the needs in more detail:
Pub/Sub Lite is a high-volume messaging service that has been built for low-cost operation.
It offers pre-provisioned capacity and zonal storage.
Though Pub/Sub offers a very broad range of features, global routing, and scaling resource capacity automatically, there are times when we need a similar service that would help us achieve the same in extremely low cost.
Lite Topics
A topic is required to which publishers can send messages so that subscribers can receive those messages for a Pub/Sub Lite service. You can create a zonal or regional Lite topic in Pub/Sub Lite.
The only difference between a zonal Lite topic and a regional Lite topic is how data is replicated. All other topic properties are the same. Data is replicated asynchronously in Pub/Sub Lite.
The points below describe the process for different types of Pub/Sub Lite topics:
Data for Pub/Sub Lite regional topics are stored in two zones. Asynchronous replication occurs between two zones. Pub/Sub Lite replication is limited to a single region.
Pub/Sub Lite zonal topics replicate data only within one zone.
The availability of underlying components affects the availability of Pub/Sub Lite, which is both the storage as well as the frontend. Following are the types of failure which are possible:
If the application frontend or storage fails in a zone, the regional Lite topic remains accessible.
If both the application frontend and the storage experience a zonal failure, the regional Lite topic remains available as long as neither component fails simultaneously.
If the application frontend and storage both fail at the same time, the regional Lite topic is unavailable for the duration of the outage. Clients may fail to publish or consume messages during this time, but messages are still delivered in the correct order.
A regional Lite topic protects against the majority of single-zone failures. However, in rare cases, the asynchronous nature of replication may result in the failure of multiple components in a single zone at the same time. As a result, a regional Lite topic is no longer available.
If you do not use Lite reservations, you can limit the throughput capacity of each partition:
Publish throughput ranging from 4 to 16 MiBps(Mebibytes Per Second).
Subscriber throughput ranging from 4 to 32 MiBps(Mebibytes Per Second).
A Lite topic's storage capacity can be increased or decreased. The Lite topic gives each partition the same amount of storage. When the storage is increased to 60 GiB, each partition receives 60 GiB of storage.
When the amount of storage in a Lite topic is reduced, the Pub/Sub Lite service removes the oldest messages first.
Pub/Sub Lite Subscription
A zonal Lite topic has similar or rather identical properties to a subscription for a regional Lite topic. A delivery requirement property is available for Lite subscriptions. Lite subscriptions can deliver messages to subscribers either immediately or after the Pub/Sub Lite service stores the message on disc.
If the delivery requirement is deliver-immediately and there is a failure by Pub/Sub Lite to write a message to storage, the service returns an error to the publisher however message is still received by the subscribers.
Publishing Messages
Here, in this section, we are going to discuss how to publish messages to Lite topics.
Pub/Sub client library in Java can be used to publish messages to Lite topics.
Request a streaming connection to the Lite topic and then send messages over the streaming connection to publish messages. Also, messages are published in batches by the client library. Larger batches consume fewer compute resources but have higher latency. Batching settings allow you to change the batch size.
Lite topics sort messages in each partition based on when they were published. Use an ordering key to assign messages to the same partition.
Pub/Sub Lite delivers messages from a partition sequentially, and subscribers can process the messages sequentially.
Receiving Messages
Again, Pub/Sub client library in Java can be used to receive messages to Lite topics.
Subscribers receive messages from Lite subscriptions, which connect Lite topics to subscriber applications. Subscribers receive every message sent to the Lite topic by publisher applications, including messages sent before you create the Lite subscription.
Before receiving messages from a Lite subscription, you have to create a Lite topic, create a Lite subscription to that Lite topic, and then publish the messages to the Lite topic.
To receive messages from a Lite subscription, send a message request to the Lite subscription. The client library automatically connects to the Lite topic partitions associated with the Lite subscription. Messages will be spread across all clients if more than one subscriber client is instantiated. The number of divisions in the topic defines the maximum number of subscriber clients that can connect to a subscription simultaneously.
It may take up to one minute for subscribers to initialize and receive messages. Messages are received with little latency after startup.
Seek Operation
You can initiate and track the seek operations for Pub/Sub Lite subscriptions.
You can replay and erase messages using the Pub/Sub Lite seek feature. It serves the same purpose as Pub/Sub seek. A long-running operation can be used to trace the propagation of the seek to subscribers. Google Cloud products use this API pattern to track the progress of long-running processes.
Tracking Seek Propagation
If a long-running operation ID is returned for the original seek request, it indicates that the seek was successfully registered in the Pub/Sub Lite service and will eventually be propagated among subscribers. The procedure monitors this propagation and completes once all partitions' subscribers have responded to the seek.
If subscribers are online, the seek notification may take up to 30 seconds to arrive. Since seek notifications are transmitted independently to each partition, partitions may not respond to the seek at the same time. If subscribers are not connected, the seek action will be completed when they reconnect.
If a prior seek invocation has not finished propagating to subscribers, it is aborted and the current seek operation takes its place. Seek operation metadata expires after 30 days, effectively canceling any unfinished seek activities.
Access Control in Pub/Sub Lite
IAM or Identity and Access Management is used for access control in Pub/Sub Lite.To grant a user or application access to Pub/Sub Lite resources, grant the user or the service account that the application uses at least one predefined or custom role. The roles grant access to particular activities on Pub/Sub Lite resources. There are ‘Predefined roles’, ‘Custom roles’ and ‘Granting roles’ for managing access control.
Pub/Sub Lite Authentication
Following are the authentication methods that Pub/Sub Lite supports.
Service Accounts
Whether developing locally or in a production application, service accounts are suggested for practically all use-case scenarios.
User Accounts
When your application wants to access resources on behalf of an end user, you can directly authenticate the user. When an application requests a Google Cloud API, IAM verifies that the caller has the necessary rights to utilize the resource.
User and service accounts, for example, are identities. Grant at least one IAM role to a user or service account to make permissions available. A role is a collection of permissions that grants you the ability to conduct particular activities on Google Cloud services.
Pub/Sub Lite Monitoring
Pub/Sub Lite provides monitoring by reporting the metrics to Cloud Monitoring. Alerting policies and charts of metrics can also be created using Cloud Monitoring. A metric is basically a set of measurements about the behavior of a product, service or application.
Pub/Sub Lite is a high-volume messaging service. Pub/Sub Lite is a low-cost system that sacrifices operational workload, availability, and features for cost savings.
What is the pricing for Pub/Sub Lite?
You pay for the capacity that you provision for Pub/Sub Lite.
What are the types of message delivery that are supported by Pub/Sub Lite?
Push and pull are the two types of message delivery that are supported by Pub/Sub Lite.
What is the distinction between a message queue and a pub/sub?
The publisher pushes messages to a queue, and each subscriber might listen to a different queue in a message-queue paradigm. The publisher pushes messages to a topic that numerous subscribers can listen to in the event-stream model using Pub/Sub.
How can I activate the Pub/Sub API?
In the Cloud Platform Console, create a new project. Select ‘Pub/Sub’ in the console's left pane, followed by ‘Enable API’.
Conclusion
In this blog, we discussed about Pub/Sub Lite and how it is different from Pub/Sub. We then had a look at Pub/Sub Lite topics, subscription, publishing and receiving of messages. We also got to know about the seek operations, its tracking, Pub/Sub Lite access control, authentication and monitoring. Pub/Sub Lite provides a lot of services that too with cost-effective. We hope you liked reading about it and added something to your knowledge about the services that GCP provides.
To read more about Google Cloud and its services, refer to the following articles: