0
0
Kafkadevops~20 mins

Avro schema definition in Kafka - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Avro Schema Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Avro schema validation?
Given this Avro schema and a JSON record, what will be the result of validating the record against the schema?
Kafka
{
  "type": "record",
  "name": "User",
  "fields": [
    {"name": "name", "type": "string"},
    {"name": "age", "type": "int"}
  ]
}

Record:
{"name": "Alice", "age": "25"}
AValidation fails due to age being a string instead of int
BValidation passes successfully
CValidation fails due to missing required field
DValidation passes but age is converted to int automatically
Attempts:
2 left
💡 Hint
Check the data types of each field in the record compared to the schema.
🧠 Conceptual
intermediate
1:30remaining
Which Avro schema type is best for optional fields?
You want to define a field in an Avro schema that may or may not be present in the data. Which schema type should you use?
A"null"
B["null", "type"] (a union with null first)
C"nullable"
D"optional"
Attempts:
2 left
💡 Hint
Avro uses unions to represent optional fields.
🔧 Debug
advanced
2:30remaining
Why does this Avro schema cause a parsing error?
Identify the error in this Avro schema snippet: { "type": "record", "name": "Product", "fields": [ {"name": "id", "type": "int"}, {"name": "price", "type": ["float", "null"]}, {"name": "tags", "type": "array", "items": "string"} ] }
AThe 'items' property should be inside the 'type' array for 'tags'
BThe 'type' for 'tags' should be "array" with 'items' as a sibling key, but here 'items' is misplaced
CThe 'type' for 'tags' should be an object with 'type' and 'items' keys, not a string
DThe 'items' key is correctly placed; the error is in the union type for 'price'
Attempts:
2 left
💡 Hint
Check the structure of the 'array' type in Avro schemas.
📝 Syntax
advanced
2:30remaining
Which Avro schema snippet is syntactically correct for a nested record?
Choose the correct Avro schema snippet defining a record with a nested record field.
A
{
  "type": "record",
  "name": "Employee",
  "fields": [
    {"name": "name", "type": "string"},
    {"name": "address", "type": "record",
      "name": "Address",
      "fields": [
        {"name": "street", "type": "string"},
        {"name": "city", "type": "string"}
      ]
    }
  ]
}
B
{
  "type": "record",
  "name": "Employee",
  "fields": [
    {"name": "name", "type": "string"},
    {"name": "address", "type": "record",
      "fields": [
        {"name": "street", "type": "string"},
        {"name": "city", "type": "string"}
      ]
    }
  ]
}
C
{
  "type": "record",
  "name": "Employee",
  "fields": [
    {"name": "name", "type": "string"},
    {"name": "address", "type": ["null", {
      "type": "record",
      "name": "Address",
      "fields": [
        {"name": "street", "type": "string"},
        {"name": "city", "type": "string"}
      ]
    }]}
  ]
}
D
{
  "type": "record",
  "name": "Employee",
  "fields": [
    {"name": "name", "type": "string"},
    {"name": "address", "type": {
      "type": "record",
      "name": "Address",
      "fields": [
        {"name": "street", "type": "string"},
        {"name": "city", "type": "string"}
      ]
    }}
  ]
}
Attempts:
2 left
💡 Hint
Nested records must be defined as an object with type 'record' and a name.
🚀 Application
expert
2:00remaining
How many fields will the following Avro schema record have after default values are applied?
Consider this Avro schema: { "type": "record", "name": "Event", "fields": [ {"name": "id", "type": "string"}, {"name": "timestamp", "type": "long"}, {"name": "metadata", "type": ["null", "string"], "default": null}, {"name": "priority", "type": "int", "default": 5} ] } If a record is created with only 'id' and 'timestamp' provided, how many fields will the record have after applying defaults?
A4 fields
B3 fields
C5 fields
D2 fields
Attempts:
2 left
💡 Hint
Fields with defaults are added automatically if missing.