2

I am a consumer and want to use SpecificRecord in Avro for type safety to avoid manually mapping things from a GenericRecord. As I understand things it makes little sense for me to still integrate with the schema registry because I could not do anything about the new schema in my consumer code anyways. Note that the schema registry has the full transitive mode enabled for any schema changes (I know that default values can still be changed and might lead to breaking changes).

Why use schema registry together with SpecificRecord in consumer code?

Fleshgrinder
  • 15,703
  • 4
  • 47
  • 56
  • 1
    To read Avro data, a consumer needs the schema used to write the data and the schema the consumer expects to read. Avro can resolve differences between these schemas when deserializing Avro data into a SpecificRecord returned to the application code. Obviously, the reader schema is built into the consumer application. From where does the consumer application get the writer schema? The answer is the schema registry. – Chin Huang Oct 28 '20 at 17:09
  • 1
    Right, but at compile time. So the question stands, why would I integrate with the schema registry at runtime? – Fleshgrinder Oct 28 '20 at 17:35
  • 1
    Imagine the producer application changes the schema for writing messages. If you built the writer schema into the consumer application at compile time, then you must deploy a new consumer application version with the new writer schema. – Chin Huang Oct 28 '20 at 19:17
  • 1
    I know, but using `GenericRecord` means that I need to manually take care of synchronizing with the changes in the code, instead of simply regenerating and having the compiler tell me what's wrong where. Really, the question is why I would still want to integrate with the schema registry if I use `SpecificRecord`. Everything else is clear. – Fleshgrinder Oct 29 '20 at 08:43

1 Answers1

0

I can answer my own question, because we tried it, and it’s impossible to use the schema registry together with SpecificRecord if you want to have schema evolution. Your code simply breaks at runtime, because it cannot find the required version. Hence, the only way to work with Avro and schema evolution is via GenericRecord, and integrating with the schema registry in case of SpecificRecord provides no value.

Compare this with Protobuf, where you have both, generated code and schema evolution.

Fleshgrinder
  • 15,703
  • 4
  • 47
  • 56