Schema evolution limits: rollback safety after a schema change in Pulsar
0 reputation · 04 Nov 2023, 04:49 UTC
0 reputation · 04 Nov 2023, 04:49 UTC
The goal is to revert a Pulsar topic to a prior schema version without corrupting or losing data that was produced under the newer schema. Pulsar’s schema evolution supports backward, forward, and full compatibility modes for Avro, JSON, and Protobuf, yet no native transactional rollback exists. Producers and consumers must be compatible with the current schema; a manual update to an older schema can render existing messages unreadable.
Key constraints include the broker’s lack of a built‑in rollback mechanism, the need for client‑side compatibility checks, and the risk that older consumers cannot interpret new fields. The uncertainty lies in whether Pulsar offers a documented, safe path to revert schemas while preserving all data.
Unresolved questions:
31775 reputation · 04 Nov 2023, 13:40 UTC
Pulsar does not provide a native, transactional way to "roll back" a topic’s schema to a previous version while guaranteeing that all existing data remains readable. The schema registry stores each version, but messages retain the schema version they were written with, so changing the registry version alone does not alter stored data. Whether a rollback is safe depends entirely on the compatibility mode in effect and on the nature of the schema change (additive vs. breaking).
To safely revert to an earlier schema without data loss, follow these steps:
pulsar-admin namespaces get-schema-compatibility-strategy). If it is not BACKWARD or FULL, a rollback may be unsafe.pulsar-admin schemas get --version N). Ensure the change is additive only (new optional fields with defaults).SchemaCompatibilityException or IncompatibleSchemaException around the rollback window to confirm no incompatible writes were accepted.If an incompatible change (e.g., removal of a required field) was already written to the topic, the only safe path is to create a new topic with the old schema and replay/migrate the data, or treat the version as a breaking change and keep both schema versions in use.
To confirm whether the recommended steps apply, we need to know the effective schema compatibility strategy for the affected namespace/topic. If you can provide that, we can verify whether a rollback is safe without additional data migration.
Use comments to ask for clarification. Post a solution as an answer.
31,775 reputation · 04 Nov 2023, 15:01 UTC
When a message is produced, Pulsar embeds a schema ID that points to the exact schema version stored in the broker’s schema registry. Changing the topic’s “current” schema version (e.g., rolling back to an older version) only affects compatibility checks for new producers; it does not alter the schema ID attached to already‑persisted messages. Consequently, consumers can still fetch the appropriate schema by ID and deserialize older data, even after a rollback. To prevent incompatible writes after the rollback, set the namespace’s schema compatibility strategy to BACKWARD or FULL so the broker rejects producers whose schema is not compatible with the newly‑active version.