Labels in Pub/Sub help you with cost management and resource
organization. For example, imagine you have multiple subscriptions for different
types of news updates. You can label each subscription with a relevant category,
such as news_category=sports or news_category=entertainment.
A label is a key-value pair that you can assign to Google Cloud resources. They help you organize these resources and manage your costs at scale, with the granularity you need. You can attach a label to each resource, then filter the resources based on their labels. Information about labels is forwarded to the billing system that lets you break down your billed charges by label. With built-in billing reports, you can filter and group costs by resource labels. You can also use labels to query billing data exports.
The labels applied to a resource must meet the following requirements:
These limits apply to the key and value for each label, and to the individual Google Cloud resources that have labels. There is no limit on how many labels you can apply across all resources within a project.
Here are some common use cases for labels:
Team or cost center labels: Add labels based on team or
cost center to distinguish resources owned by different
teams (for example, team:research and team:analytics). You can use this
type of label for cost accounting or budgeting.
Component labels: For example, component:redis,
component:frontend, component:ingest, and component:dashboard.
Environment or stage labels: For example,
environment:production and environment:test.
State labels: For example, state:active,
state:readytodelete, and state:archive.
Ownership labels: Used to identify the teams that are
responsible for operations, for example: team:shopping-cart.
We don't recommend creating large numbers of unique labels, such as for timestamps or individual values for every API call. The problem with this approach is that when the values change frequently or with keys that clutter the catalog, this makes it difficult to effectively filter and report on resources.
Labels can be used as queryable annotations for resources, but can't be used to set conditions on policies. Tags provide a way to conditionally allow or deny policies based on whether a resource has a specific tag, by providing fine-grained control over policies. For more information, see the Tags overview.
In Pub/Sub, labels are often used to organize fees for a given billing account. Fees are associated with the billing account of the project that contains the requested resource, but you might want to establish additional associations. For example, a subscription that belongs to one project might be created for a topic that belongs to a different project. You can use labels to associate that topic and subscription with a common cost center.
Pub/Sub resources don't inherit labels from each other. In the preceding example, you would set the same label on both the topic and the subscription in order to associate those charges.
You can use the following features to apply labels to Pub/Sub resources:
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-06-09 UTC.