Event Data Serialization with Apache Avro

Pub/Sub API publishes and delivers binary-encoded events with payloads encoded in the Apache Avro schema. Apache Avro is a data serialization system that provides a binary or JSON data encoding and a schema. The Avro binary encoding is more efficient than the Avro JSON encoding because it enables faster serialization and produces smaller sizes of serialized data. For more information, see Data Serialization and Deserialization in the Apache Avro specification.

When sending or receiving events from Pub/Sub API, your app must use Apache Avro to serialize and deserialize event payloads. Before you publish an event message, encode it to the Avro format. And when you receive an event message, decode it using the Avro format before you can retrieve the contents of the event payload. For more information, see Pub/Sub API as a gRPC API and the Apache Avro Documentation. The Python Quick Start for Pub/Sub API includes example functions for encoding and decoding the event messages using Avro.

Pub/Sub API doesn’t validate the Avro format of the event payload that’s passed in to the Publish or PublishStream calls. It’s up to the client to make sure that the event payload is in Avro format and that it’s valid. The Publish and PublishStream calls complete successfully even if an event payload isn’t in valid Avro format. Because an event with an invalid payload fails to deserialize, a subscriber must filter out the events with invalid payloads.

See Also