Overview
Schemas define the structure of messages in Pulsar topics. The Schemas API allows you to register, retrieve, update, and delete schemas, as well as test schema compatibility. Pulsar supports multiple schema types including Avro, JSON, Protobuf, and more. Base Path:/admin/v2/schemas
Get Schema
Retrieve the current schema for a topic.Path Parameters
The tenant name
The namespace name
The topic name
Query Parameters
Whether this broker is authoritative for the topic
Response
Schema version number
Schema type (AVRO, JSON, PROTOBUF, etc.)
Schema creation timestamp
Base64-encoded schema definition
Additional schema metadata
Example
Response Example
Get Schema by Version
Retrieve a specific version of a schema.Path Parameters
The tenant name
The namespace name
The topic name
Schema version number or “latest”
Example
Get All Schemas
Retrieve all schema versions for a topic.Example
Response Example
Upload Schema
Register or update a schema for a topic.Path Parameters
The tenant name
The namespace name
The topic name
Request Body
Schema type: AVRO, JSON, PROTOBUF, STRING, BYTES, etc.
Schema definition (format depends on type)
Additional metadata key-value pairs
Example - Avro Schema
Example - JSON Schema
Response Codes
| Code | Description |
|---|---|
| 200 | Schema created/updated successfully |
| 307 | Current broker doesn’t serve this topic |
| 401 | Don’t have permission |
| 403 | Don’t have admin permission |
| 404 | Tenant/namespace/topic doesn’t exist |
| 409 | Incompatible schema |
| 422 | Invalid schema data |
Response Example
Delete Schema
Delete all versions of a schema for a topic.Query Parameters
Force delete even if topic has active producers/consumers
Whether this broker is authoritative
Example
Response Example
Test Schema Compatibility
Test if a new schema is compatible with the existing schema.Request Body
Schema type
Schema definition to test
Schema properties
Example
Response Example
Get Schema Version
Get the version number for a specific schema definition.Request Body
Schema type
Schema definition
Example
Response Example
Schema Types
Pulsar supports various schema types:Primitive Types
- STRING: UTF-8 encoded strings
- BYTES: Raw byte arrays
- INT8/INT16/INT32/INT64: Integer types
- FLOAT/DOUBLE: Floating point numbers
- BOOLEAN: Boolean values
Complex Types
- AVRO: Apache Avro schemas with evolution support
- JSON: JSON Schema definitions
- PROTOBUF: Protocol Buffers schemas
- PROTOBUF_NATIVE: Native Protobuf with descriptor
Example - String Schema
Schema Compatibility
Pulsar supports different compatibility strategies:Compatibility Strategies
- ALWAYS_COMPATIBLE: Any schema change is allowed
- ALWAYS_INCOMPATIBLE: No schema changes allowed
- BACKWARD: New schema can read data written with old schema
- FORWARD: Old schema can read data written with new schema
- FULL: Both backward and forward compatible
- BACKWARD_TRANSITIVE: Backward compatible with all previous versions
- FORWARD_TRANSITIVE: Forward compatible with all previous versions
- FULL_TRANSITIVE: Full compatibility with all previous versions
Setting Compatibility Strategy
Compatibility is configured at the namespace level:Best Practices
Schema Design
- Use Avro or Protobuf for complex data structures
- Include default values for optional fields
- Document schema fields with descriptions
- Version schemas properly
Schema Evolution
- Test compatibility before deploying changes
- Add new fields as optional with defaults
- Never remove required fields
- Use appropriate compatibility strategy for your use case
Schema Management
- Store schema definitions in version control
- Use schema registry for centralized management
- Implement schema validation in CI/CD pipelines
- Monitor schema usage and versions
Performance
- Cache schema information on clients
- Use schema versioning to avoid repeated uploads
- Choose appropriate schema types for your data
- Consider schema size impact on serialization
Error Handling
409 - Incompatible Schema
409 - Incompatible Schema
The new schema is not compatible with existing versions.Solution: Modify schema to maintain compatibility or change the compatibility strategy.
422 - Invalid Schema Data
422 - Invalid Schema Data
The schema definition is malformed or invalid.Solution: Validate your schema definition against the type specification.
404 - Schema Not Found
404 - Schema Not Found
No schema exists for this topic.Solution: Upload a schema first before trying to retrieve it.
Related Resources
Topics API
Manage topics that use schemas
Namespaces API
Configure namespace-level schema policies