Bird
Raised Fist0
Kafkadevops~20 mins

Schema Registry concept in Kafka - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Schema Registry Master
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 Schema Registry API call?
Given a Schema Registry REST API call to get the latest schema for a subject, what is the expected output?
Kafka
curl -X GET http://localhost:8081/subjects/user-value/versions/latest
A{"subjects":["user-key","user-value"]}
B{"error_code":404,"message":"Subject not found"}
C{"id":10,"schema":"{\"type\":\"string\"}"}
D{"subject":"user-value","version":3,"id":10,"schema":"{\"type\":\"record\",\"name\":\"User\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"}]}"}
Attempts:
2 left
💡 Hint
The latest schema for a subject returns detailed schema info including subject, version, id, and schema string.
🧠 Conceptual
intermediate
1:30remaining
What is the main purpose of a Schema Registry in Kafka?
Choose the best description of what a Schema Registry does in a Kafka ecosystem.
AIt stores and manages schemas for Kafka messages to ensure compatibility and validation.
BIt acts as a message broker to route Kafka messages between producers and consumers.
CIt provides a user interface to monitor Kafka cluster health and metrics.
DIt compresses Kafka messages to reduce network bandwidth usage.
Attempts:
2 left
💡 Hint
Think about how Kafka producers and consumers agree on message formats.
🔧 Debug
advanced
2:30remaining
Why does this Kafka producer fail when using Schema Registry?
A Kafka producer configured with Schema Registry throws an error when sending messages. What is the likely cause?
Kafka
Producer config:
{
  "bootstrap.servers": "localhost:9092",
  "key.serializer": "org.apache.kafka.common.serialization.StringSerializer",
  "value.serializer": "io.confluent.kafka.serializers.KafkaAvroSerializer",
  "schema.registry.url": "http://localhost:8081"
}

Error message: "org.apache.kafka.common.errors.SerializationException: Error serializing Avro message"
AThe key.serializer is incompatible with the value.serializer.
BThe Kafka broker is down and cannot accept messages.
CThe schema for the message value is not registered in the Schema Registry.
DThe producer is missing the bootstrap.servers configuration.
Attempts:
2 left
💡 Hint
SerializationException often means the schema is missing or incompatible.
📝 Syntax
advanced
2:00remaining
Which Avro schema is valid for registering in Schema Registry?
Select the valid Avro schema JSON string that can be registered in Schema Registry.
A{"type":"record","name":"User","fields":[{"name":"id","type":"int"},{"name":"name","type":"string"}]}
B{"type":"record","fields":[{"name":"id","type":"int"},{"name":"name","type":"string"}]}
C{"type":"record","name":"User","fields":{"id":"int","name":"string"}}
D{"type":"record","name":"User","fields":[{"id":"int"},{"name":"string"}]}
Attempts:
2 left
💡 Hint
Avro record fields must be an array of objects with 'name' and 'type' keys.
🚀 Application
expert
3:00remaining
How many schema versions exist after these operations?
You register a schema for subject 'order-value' three times with these schemas: 1) {"type":"record","name":"Order","fields":[{"name":"id","type":"int"}]} 2) {"type":"record","name":"Order","fields":[{"name":"id","type":"int"},{"name":"amount","type":"float"}]} 3) {"type":"record","name":"Order","fields":[{"name":"id","type":"int"},{"name":"amount","type":"float"}]} How many versions will the subject 'order-value' have in Schema Registry?
A0
B2
C1
D3
Attempts:
2 left
💡 Hint
Schema Registry does not create a new version if the schema is identical to the latest one.

Practice

(1/5)
1. What is the main purpose of a Schema Registry in Kafka?
easy
A. To encrypt Kafka messages during transmission
B. To monitor Kafka broker performance
C. To route messages between Kafka topics
D. To store and manage data schemas for Kafka messages

Solution

  1. Step 1: Understand the role of Schema Registry

    Schema Registry stores and manages the structure (schema) of data used in Kafka messages.
  2. Step 2: Compare with other Kafka components

    Monitoring, routing, and encryption are handled by other Kafka tools, not Schema Registry.
  3. Final Answer:

    To store and manage data schemas for Kafka messages -> Option D
  4. Quick Check:

    Schema Registry = data schema storage [OK]
Hint: Schema Registry manages data formats, not Kafka internals [OK]
Common Mistakes:
  • Confusing Schema Registry with Kafka brokers
  • Thinking it handles message routing
  • Assuming it encrypts messages
2. Which of the following is the correct way to register a schema using Kafka Schema Registry API?
easy
A. DELETE /topics/{topic}/schemas with schema in YAML
B. GET /schemas/{id} with schema in XML
C. POST /subjects/{subject}/versions with schema in JSON
D. PUT /brokers/{brokerId}/schemas with schema in CSV

Solution

  1. Step 1: Identify the correct HTTP method and endpoint

    Registering a schema uses POST on /subjects/{subject}/versions with JSON schema.
  2. Step 2: Check other options for correctness

    GET retrieves schemas, DELETE removes topics (not schemas), PUT on brokers is invalid for schema registration.
  3. Final Answer:

    POST /subjects/{subject}/versions with schema in JSON -> Option C
  4. Quick Check:

    Register schema = POST with JSON [OK]
Hint: Register schemas with POST and JSON format [OK]
Common Mistakes:
  • Using GET instead of POST to register
  • Confusing schema formats (JSON vs XML/YAML/CSV)
  • Using wrong API endpoints
3. Given this code snippet using Kafka Schema Registry client, what will be the output?
schema = '{"type":"record","name":"User","fields":[{"name":"name","type":"string"}]}'
subject = "User-value"
schema_id = client.register_schema(subject, schema)
print(schema_id)
medium
A. An integer ID representing the registered schema
B. The original schema string printed
C. A JSON object with schema details
D. A runtime error due to missing client method

Solution

  1. Step 1: Understand the register_schema method

    This method registers the schema and returns an integer ID assigned by Schema Registry.
  2. Step 2: Analyze the print statement

    Printing schema_id outputs the integer ID, not the schema string or JSON object.
  3. Final Answer:

    An integer ID representing the registered schema -> Option A
  4. Quick Check:

    Register returns schema ID integer [OK]
Hint: Register returns schema ID number, not schema text [OK]
Common Mistakes:
  • Expecting schema string instead of ID
  • Confusing output with JSON object
  • Assuming method does not exist
4. Identify the error in this Kafka Schema Registry usage snippet:
schema = '{"type":"record","name":"User","fields":[{"name":"age","type":"int"}]}'
subject = "User-value"
schema_id = client.register_schema(subject, schema)
client.register_schema(subject, schema)
medium
A. Registering the same schema twice causes an error
B. No error; registering same schema returns same ID
C. Schema string is not valid JSON
D. Missing schema version in registration call

Solution

  1. Step 1: Check schema validity

    The schema string is valid JSON describing a record with an int field.
  2. Step 2: Understand Schema Registry behavior on duplicate schemas

    Registering the same schema again returns the same schema ID without error.
  3. Final Answer:

    No error; registering same schema returns same ID -> Option B
  4. Quick Check:

    Duplicate schema registration returns same ID [OK]
Hint: Duplicate schema registration is safe and returns same ID [OK]
Common Mistakes:
  • Assuming duplicate registration causes error
  • Thinking schema string is invalid JSON
  • Expecting version parameter in register call
5. You want to evolve a Kafka message schema by adding a new optional field without breaking existing consumers. Which Schema Registry feature helps achieve this safely?
hard
A. Schema compatibility settings (e.g., BACKWARD compatibility)
B. Schema encryption for secure transmission
C. Schema version rollback to previous schema
D. Schema validation disabling for faster registration

Solution

  1. Step 1: Understand schema evolution needs

    Adding a new optional field requires compatibility so old consumers still work.
  2. Step 2: Identify Schema Registry feature for compatibility

    Schema compatibility settings like BACKWARD ensure new schemas don't break old consumers.
  3. Step 3: Eliminate other options

    Encryption, rollback, or disabling validation do not help safe schema evolution.
  4. Final Answer:

    Schema compatibility settings (e.g., BACKWARD compatibility) -> Option A
  5. Quick Check:

    Compatibility settings enable safe schema evolution [OK]
Hint: Use compatibility settings to evolve schemas safely [OK]
Common Mistakes:
  • Confusing encryption with compatibility
  • Thinking rollback helps forward compatibility
  • Disabling validation breaks schema safety
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard