Compression reduces the size of messages sent over the network and stored on disk, improving throughput and saving storage space.
Click to reveal answer
beginner
Name three compression codecs supported by Kafka.
Kafka supports gzip, snappy, and lz4 compression codecs.
Click to reveal answer
intermediate
How does gzip compression compare to snappy in Kafka?
Gzip offers higher compression ratio but is slower, while snappy is faster but compresses less effectively.
Click to reveal answer
intermediate
What is a key advantage of lz4 compression in Kafka?
Lz4 provides a good balance of fast compression and decompression speed with reasonable compression ratio, making it suitable for real-time data streams.
Click to reveal answer
beginner
How do you enable compression for Kafka producers?
Set the producer configuration property 'compression.type' to 'gzip', 'snappy', or 'lz4' to enable compression.
Click to reveal answer
Which Kafka compression codec typically offers the fastest compression speed?
Asnappy
Bgzip
Cnone
Dlz4
✗ Incorrect
lz4 is designed for fast compression and decompression, faster than snappy and gzip.
What is the default compression type in Kafka if none is specified?
Agzip
Bnone
Clz4
Dsnappy
✗ Incorrect
By default, Kafka producers do not compress messages unless 'compression.type' is set.
Which compression codec is best when you want the smallest message size regardless of speed?
Agzip
Bsnappy
Clz4
Dnone
✗ Incorrect
Gzip compresses data more tightly than snappy or lz4 but is slower.
How does compression affect Kafka network usage?
ADecreases network usage
BIncreases network usage
CNo effect on network usage
DDepends on message size only
✗ Incorrect
Compression reduces the size of messages, lowering network bandwidth usage.
Which Kafka compression codec is recommended for real-time streaming with low latency?
Agzip
Bsnappy
Clz4
Dnone
✗ Incorrect
Lz4 offers fast compression and decompression suitable for low latency streaming.
Explain the differences between gzip, snappy, and lz4 compression codecs in Kafka.
Think about speed versus compression size trade-offs.
You got /3 concepts.
Describe how to enable compression on a Kafka producer and why you might want to do it.
Consider configuration and benefits.
You got /4 concepts.
Practice
(1/5)
1. Which of the following compression types is NOT supported by Kafka by default?
easy
A. gzip
B. snappy
C. lz4
D. bzip2
Solution
Step 1: Recall Kafka's default compression types
Kafka supports gzip, snappy, and lz4 compression types by default.
Step 2: Identify unsupported compression
bzip2 is not included in Kafka's default compression options.
Final Answer:
bzip2 -> Option D
Quick Check:
Kafka default compression excludes bzip2 [OK]
Hint: Remember Kafka supports gzip, snappy, and lz4 only [OK]
Common Mistakes:
Confusing bzip2 as supported compression
Thinking all common compressions are supported
Mixing compression codecs with serialization formats
2. Which is the correct way to set gzip compression in Kafka producer configuration?
easy
A. compression.type = 'gzip'
B. compressionType = 'gzip'
C. compression.type = gzip
D. compression = 'gzip'
Solution
Step 1: Identify the correct property name
The Kafka producer config uses 'compression.type' to set compression.
Step 2: Check the correct value format
The value should be a string, so 'gzip' must be in quotes.
Final Answer:
compression.type = 'gzip' -> Option A
Quick Check:
Use compression.type with string value [OK]
Hint: Use compression.type with quotes around value [OK]
What is the effect of setting compression.type to snappy?
medium
A. Messages will be sent without compression.
B. Messages will be compressed using Snappy before sending.
C. Messages will be compressed using gzip.
D. Producer will throw an error due to invalid compression.
Solution
Step 1: Understand the compression.type setting
Setting compression.type to 'snappy' means messages are compressed with Snappy codec.
Step 2: Confirm no errors expected
Snappy is a valid compression type, so no errors occur and compression is applied.
Final Answer:
Messages will be compressed using Snappy before sending. -> Option B
Quick Check:
compression.type = snappy means Snappy compression [OK]
Hint: compression.type sets the codec used for message compression [OK]
Common Mistakes:
Assuming no compression happens
Confusing snappy with gzip
Expecting an error for valid compression type
4. You wrote this Kafka producer config:
props.put("compression.type", "lz5");
What is the problem with this configuration?
medium
A. lz5 is not a supported compression type in Kafka.
B. The property name should be compressionType, not compression.type.
C. The value should be uppercase: LZ5.
D. There is no problem; this is valid.
Solution
Step 1: Check the compression type value
Kafka supports gzip, snappy, and lz4 only; lz5 is invalid.
Step 2: Confirm property name correctness
The property name compression.type is correct, so no issue there.
Final Answer:
lz5 is not a supported compression type in Kafka. -> Option A
Quick Check:
Only gzip, snappy, lz4 are valid compression types [OK]
Hint: Use only gzip, snappy, or lz4 for compression.type [OK]
Common Mistakes:
Using unsupported compression types like lz5
Changing property name incorrectly
Assuming case sensitivity matters for compression type
5. You want to optimize Kafka message throughput by choosing a compression type that balances speed and compression ratio. Which compression type should you choose?
hard
A. gzip, because it has the best compression ratio but slower speed.
B. No compression, to avoid any overhead.
C. snappy, because it offers fast compression with reasonable compression ratio.
D. lz4, because it is the slowest but compresses best.
Solution
Step 1: Understand compression trade-offs
gzip compresses well but is slower; snappy is faster with decent compression; lz4 is fast and efficient.
Step 2: Identify best balance for throughput
snappy is known for fast compression speed and reasonable compression ratio, ideal for throughput.
Final Answer:
snappy, because it offers fast compression with reasonable compression ratio. -> Option C
Quick Check:
snappy balances speed and compression well [OK]
Hint: Pick snappy for speed and decent compression [OK]
Common Mistakes:
Choosing gzip for speed instead of compression ratio
Thinking lz4 is slowest
Assuming no compression is fastest overall
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.