Bird
Raised Fist0

Given this Kafka producer code snippet using Avro schema validation, what happens if the producer sends data that does not match the registered schema?

medium📝 Predict Output Q13 of Q15
Kafka - Schema Registry
Given this Kafka producer code snippet using Avro schema validation, what happens if the producer sends data that does not match the registered schema?
producer.send({ key: 'user1', value: { name: 'Alice', age: 'twenty' } });

Assuming the schema expects age as an integer.
AThe message is rejected and an error is thrown before sending.
BThe message is sent successfully with age as a string.
CThe message is sent but the consumer will fail to deserialize.
DThe message is silently corrected to convert age to integer.
Step-by-Step Solution
Solution:
  1. Step 1: Understand schema validation on producer side

    The producer validates data against the schema before sending; mismatched types cause errors.
  2. Step 2: Analyze the given data mismatch

    Age is given as a string 'twenty' but schema expects integer, so validation fails and sending is blocked.
  3. Final Answer:

    The message is rejected and an error is thrown before sending. -> Option A
  4. Quick Check:

    Schema validation blocks invalid data [OK]
Quick Trick: Producer blocks sending if data mismatches schema [OK]
Common Mistakes:
MISTAKES
  • Assuming message sends with wrong data type
  • Thinking consumer handles invalid data silently
  • Believing schema auto-corrects data types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes