Stay organized with collections
Save and categorize content based on your preferences.
A Pub/Sub schema is an optional feature that you can use to enforce
the format of the data field in a Pub/Sub message.
A schema creates a contract between the publisher and subscriber about the
format of the messages. Pub/Sub enforces this format.
Schemas facilitate inter-team consumption of data streams in your
organization by creating a central authority for message types and
permissions. A Pub/Sub message schema defines the names and
data types for the fields in a message.
You can create a schema and associate it with a topic to
enforce the schema for published messages. If a specific message does
not conform to the schema, the message is not published. You can also create
additional revisions for a schema.
Types of schemas
You can create a schema in Pub/Sub by using one of the
following frameworks:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[],[],null,["# Schema overview\n\nA Pub/Sub schema is an optional feature that you can use to enforce\nthe format of the [data](/pubsub/docs/reference/rpc/google.pubsub.v1#google.pubsub.v1.PubsubMessage.FIELDS.bytes.google.pubsub.v1.PubsubMessage.data) field in a Pub/Sub message.\n\nA schema creates a contract between the publisher and subscriber about the\nformat of the messages. Pub/Sub enforces this format.\nSchemas facilitate inter-team consumption of data streams in your\norganization by creating a central authority for message types and\npermissions. A Pub/Sub message schema defines the names and\ndata types for the fields in a message.\n\nYou can create a schema and associate it with a topic to\nenforce the schema for published messages. If a specific message does\nnot conform to the schema, the message is not published. You can also create\nadditional revisions for a schema.\n\nTypes of schemas\n----------------\n\nYou can create a schema in Pub/Sub by using one of the\nfollowing frameworks:\n\n- [Apache Avro](https://avro.apache.org/docs/++version++/specification/#schema-declaration)\n- [Protocol Buffer](https://protobuf.dev/)\n\nFor example, the following schema defines the inventory of a warehouse,\nfirst in the Avro format and then in the Protocol Buffer format.\n| **Note:** Avro version 1.11 is supported. For Protocol Buffers, proto2 and proto3 are supported.\n\n### Apache Avro format\n\n {\n \"type\" : \"record\",\n \"name\" : \"Avro\",\n \"fields\" : [\n {\n \"name\" : \"ProductName\",\n \"type\" : \"string\",\n \"default\": \"\"\n },\n {\n \"name\" : \"SKU\",\n \"type\" : \"int\",\n \"default\": 0\n },\n {\n \"name\" : \"InStock\",\n \"type\" : \"boolean\",\n \"default\": false\n }\n ]\n }\n\n| **Note:** Pub/Sub does not validate the default value of each field, follow the [Apache Avro specification](https://avro.apache.org/docs/1.11.1/specification/) for default value rules.\n\n### Protocol Buffer format\n\n syntax = \"proto3\";\n message ProtocolBuffer {\n string product_name = 1;\n int32 SKU = 2;\n bool in_stock = 3;\n }\n\nImportant information about schemas\n-----------------------------------\n\nThe following is some important information regarding creating and\nmanaging Pub/Sub schemas.\n\n- For a schema to work with Pub/Sub, you must define only\n one top-level [type](/pubsub/docs/schemas#types-schema). Import statements that reference other types\n are not supported.\n\n- You can associate the same schema to multiple topics.\n\n- You can manually test whether a message validates against a schema.\n\n- Don't include sensitive information such as personally identifiable\n information (PII) or security data in your schema field names.\n\nQuotas and limits for schemas\n-----------------------------\n\nSchemas have the following limits:\n\n- The schema definition field cannot exceed 300 KB in size.\n\n- A project can have a maximum of 10,000 schemas.\n\n- A single schema cannot have more than 20 revisions.\n\n For information about schemas and limits related to Pub/Sub,\n see [Pub/Sub quotas and limits](/pubsub/quotas).\n\nWhat's next\n-----------\n\n- [Create a schema](/pubsub/docs/create-schemas)\n\n- [Associate a schema with a topic](/pubsub/docs/associate-schema-topic)\n\n- [Commit a schema revision](/pubsub/docs/commit-schema-revision)\n\n- [Publish messages to a topic with a schema](/pubsub/docs/publish-topics-schema)"]]