0
0
Kafkadevops~20 mins

Custom SerDes in Kafka - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Kafka SerDes 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 custom SerDes serialization?

Given the following Kafka custom serializer code snippet, what will be the output byte array when serializing the string "abc"?

Kafka
public class CustomStringSerializer implements org.apache.kafka.common.serialization.Serializer<String> {
    @Override
    public byte[] serialize(String topic, String data) {
        if (data == null) return null;
        byte[] originalBytes = data.getBytes();
        byte[] result = new byte[originalBytes.length + 1];
        result[0] = (byte) originalBytes.length;
        System.arraycopy(originalBytes, 0, result, 1, originalBytes.length);
        return result;
    }
}
A[99, 98, 97]
B[0, 97, 98, 99]
C[3, 97, 98, 99]
D[97, 98, 99]
Attempts:
2 left
💡 Hint

Think about how the length of the string is stored in the first byte.

Predict Output
intermediate
2:00remaining
What error occurs when deserializing null data?

Consider this Kafka custom deserializer snippet. What error will occur if data is null?

Kafka
public class CustomStringDeserializer implements org.apache.kafka.common.serialization.Deserializer<String> {
    @Override
    public String deserialize(String topic, byte[] data) {
        int length = data[0];
        return new String(data, 1, length);
    }
}
AClassCastException
BArrayIndexOutOfBoundsException
CNo error, returns empty string
DNullPointerException
Attempts:
2 left
💡 Hint

What happens if you try to access an element of a null array?

🧠 Conceptual
advanced
2:00remaining
Which statement best describes the role of a custom SerDes in Kafka?

Choose the most accurate description of what a custom SerDes (Serializer/Deserializer) does in Kafka.

AIt manages Kafka topic partitions and offsets automatically.
BIt converts data between Kafka's internal byte format and application-specific objects.
CIt encrypts messages to secure Kafka communication.
DIt balances load between Kafka brokers.
Attempts:
2 left
💡 Hint

Think about how Kafka sends and receives data as bytes but applications use objects.

🔧 Debug
advanced
2:00remaining
Why does this custom deserializer produce incorrect strings?

Given this deserializer code, why might the output strings be incorrect or corrupted?

Kafka
public class FaultyDeserializer implements org.apache.kafka.common.serialization.Deserializer<String> {
    @Override
    public String deserialize(String topic, byte[] data) {
        if (data == null) return null;
        int length = data[0];
        return new String(data, 0, length);
    }
}
AIt includes the length byte in the string, causing corruption.
BIt throws NullPointerException when data is null.
CIt uses the wrong character encoding by default.
DIt reverses the byte order before decoding.
Attempts:
2 left
💡 Hint

Check the substring start index and length used in the String constructor.

🚀 Application
expert
3:00remaining
How many items are in the map after this custom SerDes deserialization?

Assume a custom deserializer converts a byte array representing multiple key-value pairs into a Map<String, Integer>. The byte array encodes 3 pairs: {"a":1, "b":2, "c":3}. After deserialization, how many entries does the map contain?

Kafka
byte[] data = new byte[]{3, 97, 1, 98, 2, 99, 3}; // Custom format: first byte count, then pairs of (keyByte, valueByte)
// Deserializer logic:
// int count = data[0];
// for i in 0..count-1:
//   key = String.valueOf((char) data[2*i+1]);
//   value = data[2*i+2];
//   map.put(key, value);
A3
B6
C1
D0
Attempts:
2 left
💡 Hint

Count how many key-value pairs the first byte indicates and how the loop processes them.