An Avro schema is a JSON-based format that defines the structure of data, including fields and their types, used to serialize and deserialize data in Kafka.
Click to reveal answer
beginner
What are the main components of an Avro schema?
The main components are: 1. type: The data type (e.g., record, string, int). 2. name: The name of the record. 3. fields: A list of fields with their names and types.
Click to reveal answer
beginner
How do you define a record type in Avro schema?
You define a record by specifying "type": "record", giving it a "name", and listing its "fields" with their names and types.
Click to reveal answer
intermediate
What is the purpose of the namespace in an Avro schema?
The namespace groups related schemas together, like a folder name, to avoid name conflicts between schemas with the same record name.
Click to reveal answer
intermediate
How do you specify optional fields in an Avro schema?
You use a union type with "null" and the actual type, for example: ["null", "string"]. This means the field can be a string or null (optional).
Click to reveal answer
Which data type is used to define a complex structure in Avro schema?
Aboolean
Brecord
Cint
Dstring
✗ Incorrect
The 'record' type defines a complex structure with multiple fields.
How do you make a field optional in Avro schema?
ALeave the field out
BSet 'optional': true
CUse 'nullable': true
DUse a union with 'null' and the field type
✗ Incorrect
Avro uses a union type with 'null' to indicate optional fields.
What is the purpose of the 'namespace' in an Avro schema?
ATo specify the data type
BTo list the fields
CTo group related schemas and avoid name conflicts
DTo define default values
✗ Incorrect
Namespace helps organize schemas and prevent name clashes.
Which format is used to write Avro schemas?
AJSON
BXML
CYAML
DCSV
✗ Incorrect
Avro schemas are written in JSON format.
What does the 'fields' array in an Avro schema contain?
AList of field names and their types
BList of namespaces
CList of default values
DList of schema versions
✗ Incorrect
The 'fields' array defines each field's name and type.
Explain how to define a simple Avro schema for a user record with name (string) and age (int).
Think about the 'type', 'name', and 'fields' keys.
You got /4 concepts.
Describe how to make a field optional in an Avro schema and why it is useful.
Consider how to allow a field to be missing or null.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of an Avro schema in Kafka?
easy
A. To route messages to different topics
B. To define the structure and data types of messages
C. To compress messages for faster transmission
D. To encrypt messages for security
Solution
Step 1: Understand Avro schema role
An Avro schema describes how data is organized and typed in messages.
Step 2: Compare options with schema purpose
Only defining structure and data types matches the schema's role.
Final Answer:
To define the structure and data types of messages -> Option B
Quick Check:
Avro schema = data structure definition [OK]
Hint: Avro schema describes message format, not security or routing [OK]
Common Mistakes:
Confusing schema with encryption or compression
Thinking schema controls message routing
Assuming schema is for message storage
2. Which of the following is the correct way to start an Avro record schema definition?
easy
A. {"type": "enum", "symbols": ["A", "B"]}
B. {"type": "array", "items": "string"}
C. {"type": "map", "values": "int"}
D. {"type": "record", "name": "User", "fields": []}
Solution
Step 1: Identify record schema syntax
An Avro record schema starts with type "record", a name, and a fields array.
Step 2: Match options to record schema
Only {"type": "record", "name": "User", "fields": []} matches the record schema format correctly.
Final Answer:
{"type": "record", "name": "User", "fields": []} -> Option D
Quick Check:
Record schema = type "record" with name and fields [OK]
Hint: Record schemas always start with type "record" and have fields [OK]