Choosing Pub/Sub or Pub/Sub Lite

This page provides details to help you choose between Pub/Sub and Pub/Sub Lite. Pub/Sub and Pub/Sub Lite are asynchronous messaging services. For more information about publish-subscribe messaging, see the Pub/Sub overview.

Pub/Sub is a fully managed, high availability service that replicates messages across multiple zones. Pub/Sub is for most use cases.

To reduce costs, you can use Pub/Sub Lite. Pub/Sub Lite is a zonal service for messaging systems with predictable traffic patterns. If you publish 1 MiB-1 GiB of messages per second, Pub/Sub Lite might be an order of magnitude cheaper.

For more information about the cost difference between Pub/Sub and Pub/Sub Lite, see the Pub/Sub Lite pricing.

Comparison table

The following table compares the key differences between Pub/Sub and Pub/Sub Lite:

Feature Pub/Sub Pub/Sub Lite
Message replication Multi-zone in single region Single zone
Capacity Automatically provisioned Provision before you use
Pricing Pay for the capacity that you use Pay for the capacity that you provision
Storage Unlimited 30 GiB-10 TiB per Lite topic
Retention period Up to 7 days Unlimited
Service endpoints Global and regional Regional
Resource namespace Global Zonal
Message routing Global Zonal

Pub/Sub

In a Pub/Sub system, publisher applications send messages to topics, and subscriber applications receive messages from subscriptions. Topics and subscriptions are global resources, so they can be in different Cloud projects.

If a topic and subscription are in different projects, different quotas apply, and publishers and subscribers are billed independently. For details, see the Pub/Sub pricing.

Pub/Sub scales automatically. Any number of publishers and subscribers can send and receive any number of messages. The Pub/Sub service can store messages in any region.

Subscribers can request messages from Pub/Sub, or Pub/Sub can initiate requests. The following Google Cloud products can automatically authenticate requests from Pub/Sub:

  • App Engine
  • Cloud Functions
  • Cloud Run

Streaming pipelines

To read or write messages in Apache Beam pipelines, you can use Dataflow streaming templates or the Pub/Sub I/O for the Apache Beam SDK. The Pub/Sub I/O is available in the Apache Beam SDK for Java and the Apache Beam SDK for Python.

Pub/Sub Lite

In a Pub/Sub Lite system, publishers send messages to Lite topics and subscribers receive messages from Lite subscriptions. Lite topics and Lite subscriptions are zonal resources that must be in the same Cloud project and zone. For a list of zones that Pub/Sub Lite supports, see Pub/Sub Lite locations.

If you run a publisher or subscriber on Google Cloud, the application can run in a different Cloud project from the Cloud project that the Lite topic and Lite subscription are in.

Lite topics consist of partitions; a partition is a log of messages. Publishers assign each message to a partition, and the Pub/Sub Lite service appends each message to the log. The Pub/Sub Lite service delivers the messages from a partition in order.

Subscribers must request messages from Pub/Sub Lite. To request messages, subscribers establish bidirectional streaming connections with each of the partitions.

You manually provision the capacity to publish messages to Lite topics, receive messages from Lite topics, and store messages in Lite topics. When you create a Lite topic, you specify the number of partitions and the storage per partition. To increase the capacity of a Lite topic, you can scale the capacity of the partitions.

Streaming pipelines

To read or write messages in Apache Beam pipelines, you can use the custom Pub/Sub Lite I/O for the Apache Beam SDK. The Pub/Sub Lite I/O is in the Java client library. You can use the Pub/Sub Lite I/O with the Apache Beam SDK for Java.