Avro Schemas and Subjects

A subject is the name a schema's version history lives under. The default TopicNameStrategy names it after the topic and the record part, <topic>-key or <topic>-value, so one topic holds one type. RecordNameStrategy uses the record's full name (com.example.booknest.OrderEvent) and lets a topic mix types; TopicRecordNameStrategy combines both. The order event in Avro 129 , with JSON, Columnar and Binary Formats's conventions:

schemas/order_event.avsc: BookNest's order event, version 1JSON
{"type": "record", "name": "OrderEvent", "namespace": "com.example.booknest",
 "doc": "One BookNest order lifecycle event",
 "fields": [
   {"name": "event_id", "type": "long"},
   {"name": "ts", "type": {"type": "long", "logicalType": "timestamp-millis"}},
   {"name": "type", "type": {"type": "enum", "name": "EventType", "symbols": ["order_placed",
     "order_paid", "order_shipped", "order_delivered", "order_cancelled", "order_returned"]}},
   {"name": "order_id", "type": "long"},
   {"name": "customer_id", "type": ["null", "long"], "default": null},
   {"name": "total", "type": ["null", "double"], "default": null}]}
listings/l0694_subjects.sh: register version 1 and read it backShell
# Register the Avro order event under the topic's value subject, then look it up
R=localhost:33081; S=booknest.order-events-avro-value
jq -n --rawfile s schemas/order_event.avsc '{schema: $s}' |
  curl -s -X POST -H 'Content-Type: application/vnd.schemaregistry.v1+json' -d @- \
    $R/subjects/$S/versions | jq -c '{id, version}'
curl -s $R/subjects/$S/versions/latest | jq -c '{version, id, fields:
  (.schema | fromjson | .fields | map(.name))}'
Output
{"id":1,"version":1}
{"version":1,"id":1,"fields":["event_id","ts","type","order_id","customer_id","total"]}

Registering an identical schema again returns the same ID, not a new version. The enum restricts type to six values; the unions with null defaults make customer_id and total optional.