6

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 ?

Poppy
  • 2,902
  • 14
  • 51
  • 75

3 Answers3

4

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

Avinash
  • 839
  • 1
  • 10
  • 17
  • Can you tell us more about "There is a way to add a new enum value in a compatible way" ? I tried to use an enum with a default value it is still not compatible when I add a new symbol when using FULL_TRANSITIVE compatibility mode – singe3 Jan 18 '22 at 09:00
1

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

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
1

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+)

Reynard
  • 953
  • 13
  • 27
  • 1
    This answer is incorrect. The answers below are correct. The behavior for adding and removing symbols from Enums is different than adding or removing fields. (In fact, it's the opposite.) – Ray Oct 18 '21 at 07:04
  • Furthermore I think defaults work from 1.9+ – CeePlusPlus Nov 02 '21 at 14:55
  • The explanation seems wrong. "clients with the old schema will fail to deserialize, because they don't have such value in their enum" this statement means FORWARD compatibility. – GC001 Nov 11 '22 at 17:24