Poppy
Poppy

Reputation: 3092

Avro schema : is adding an enum value to existing schema backward compatible?

I have an enum field for status in my Avro schema in which the possible statuses currently are

PENDING
APPROVED
REJECTED

I want to add one more value in this enum “RESUBMIT”. Is this change backward compatible ?

Upvotes: 7

Views: 9034

Answers (3)

Reynard
Reynard

Reputation: 1102

No, it is not. Here's why: If you are using this new schema to, let's say, emit events to Kafka, then all clients will try to deserialize the value. When event with new type will appear, there would be 2 cases:

  1. clients with new schema will deserialize successfully
  2. clients with the old schema will fail to deserialize, because they don't have such value in their enum

So, no, this is not backward compatible.

update: You can probably avoid deserialization failure by specifying the default value for enum (available in Avro version 1.10.2+)

Upvotes: 1

Avinash
Avinash

Reputation: 879

As per https://docs.confluent.io/platform/current/schema-registry/avro.html

  • BACKWARD compatibility means that consumers using the new schema can read data produced with the last schema
  • FORWARD compatibility means that data produced with a new schema can be read by consumers using the last schema

Going by that definition/terminology above, the change is BACKWARD compatible i.e. all your consumers need to be upgraded first. But not FORWARD compatible since the consumer with the old schema cant deserialize this.

Correcting my previous answer above.

https://avro.apache.org/docs/current/idl.html#:~:text=An%20Avro%20Enum%20supports%20optional,an%20incompatible%20symbol%20is%20read

There is a way to add a new enum value in a compatible way

Upvotes: 8

OneCricketeer
OneCricketeer

Reputation: 191743

I don't think it is, but you are welcome to use the Schema Registry API to verify compatbility

https://docs.confluent.io/current/schema-registry/develop/api.html#id1

Upvotes: 1

Related Questions