Bird
Raised Fist0
Kafkadevops~10 mins

Retention policies (time-based, size-based) in Kafka - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set a time-based retention policy of 7 days for a Kafka topic.

Kafka
retention.ms=[1]  # Set retention to 7 days in milliseconds
Drag options to blanks, or click blank then click option'
A259200000
B604800000
C86400000
D3600000
Attempts:
3 left
💡 Hint
Common Mistakes
Using seconds or minutes instead of milliseconds.
Confusing retention.ms with retention.bytes.
2fill in blank
medium

Complete the code to set a size-based retention policy of 1 GB for a Kafka topic.

Kafka
retention.bytes=[1]  # Set retention size to 1 GB
Drag options to blanks, or click blank then click option'
A1024000000
B1048576
C1000000000
D1073741824
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1,000,000,000 bytes instead of 1,073,741,824 bytes.
Confusing retention.bytes with retention.ms.
3fill in blank
hard

Fix the error in the retention policy configuration to correctly set retention to 3 days.

Kafka
retention.ms = [1]  # Intended 3 days retention
Drag options to blanks, or click blank then click option'
A86400000
B300000
C259200000
D3600000
Attempts:
3 left
💡 Hint
Common Mistakes
Using 300000 which is 5 minutes.
Using 86400000 which is 1 day.
4fill in blank
hard

Fill both blanks to create a retention policy that deletes messages older than 2 days or when the log size exceeds 500 MB.

Kafka
retention.ms = [1]
retention.bytes = [2]
Drag options to blanks, or click blank then click option'
A172800000
B524288000
C1048576000
D86400000
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up retention.ms and retention.bytes values.
Using 1 GB instead of 500 MB for retention.bytes.
5fill in blank
hard

Fill all three blanks to configure a Kafka topic with a retention time of 12 hours, a retention size of 200 MB, and a cleanup policy of delete.

Kafka
retention.ms = [1]
retention.bytes = [2]
cleanup.policy = "[3]"
Drag options to blanks, or click blank then click option'
A43200000
B209715200
Cdelete
Dcompact
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'compact' instead of 'delete' for cleanup.policy.
Mixing up retention.ms and retention.bytes values.

Practice

(1/5)
1. What does the retention.ms setting control in Kafka?
easy
A. The maximum size of a Kafka topic
B. How long Kafka keeps data before deleting it
C. The number of partitions in a topic
D. The replication factor of a topic

Solution

  1. Step 1: Understand retention.ms meaning

    retention.ms sets the time duration Kafka retains data before deletion.
  2. Step 2: Compare with other options

    Other options relate to size, partitions, or replication, not time retention.
  3. Final Answer:

    How long Kafka keeps data before deleting it -> Option B
  4. Quick Check:

    retention.ms = time-based retention [OK]
Hint: Remember ms means milliseconds, so it's about time [OK]
Common Mistakes:
  • Confusing retention.ms with retention.bytes
  • Thinking it controls topic size
  • Mixing it with partition count
2. Which of the following is the correct way to set a size-based retention policy in Kafka's topic configuration?
easy
A. "retention.bytes" = 1073741824
B. "retention.time" = 604800000
C. "retention.size" = 1073741824
D. "retention.ms" = 1073741824

Solution

  1. Step 1: Identify correct property for size-based retention

    The correct property is retention.bytes for size limits.
  2. Step 2: Check option values and names

    "retention.bytes" = 1073741824 uses retention.bytes with a size value (1GB). Others use wrong keys or time-based keys.
  3. Final Answer:

    "retention.bytes" = 1073741824 -> Option A
  4. Quick Check:

    Size retention uses retention.bytes [OK]
Hint: Size retention uses bytes, so look for retention.bytes [OK]
Common Mistakes:
  • Using retention.time instead of retention.ms
  • Using retention.size which is invalid
  • Confusing retention.ms with size setting
3. Given a Kafka topic with retention.ms=60000 and retention.bytes=1048576, what happens when the topic data reaches 2MB before 60 seconds pass?
medium
A. Kafka waits until 60 seconds pass before deleting any data
B. Kafka deletes data only if both time and size limits are reached
C. Kafka deletes old data immediately because size limit is reached
D. Kafka ignores retention settings and keeps all data

Solution

  1. Step 1: Understand retention.ms and retention.bytes interaction

    Kafka deletes data when either time or size limit is reached, whichever comes first.
  2. Step 2: Analyze given values

    Size limit is 1MB, data reached 2MB before 60 seconds, so size limit triggers deletion immediately.
  3. Final Answer:

    Kafka deletes old data immediately because size limit is reached -> Option C
  4. Quick Check:

    Retention triggers on earliest limit reached [OK]
Hint: Retention deletes when time OR size limit is reached [OK]
Common Mistakes:
  • Thinking both limits must be reached to delete
  • Assuming time limit always overrides size
  • Ignoring size limit when time not reached
4. You set retention.ms to a negative value in Kafka topic config. What is the likely outcome?
medium
A. Kafka treats it as infinite retention (never deletes data)
B. Kafka throws a configuration error and refuses to start
C. Kafka deletes data immediately after creation
D. Kafka uses default retention time instead

Solution

  1. Step 1: Check Kafka behavior for negative retention.ms

    Kafka interprets negative retention.ms as infinite retention, meaning no data deletion.
  2. Step 2: Confirm other options

    Kafka does not throw error or delete immediately; it does not revert to default automatically.
  3. Final Answer:

    Kafka treats it as infinite retention (never deletes data) -> Option A
  4. Quick Check:

    Negative retention.ms means infinite retention [OK]
Hint: Negative retention.ms disables deletion, keeps data forever [OK]
Common Mistakes:
  • Expecting an error on negative value
  • Assuming immediate deletion
  • Thinking default value applies automatically
5. You want to configure a Kafka topic to keep data for 2 hours or up to 500MB, whichever limit is reached first. Which configuration is correct?
hard
A. "retention.ms"=7200000 only, size limit is not needed
B. "retention.ms"=7200000 and "retention.bytes"=5000000000
C. "retention.ms"=120 and "retention.bytes"=524288000
D. "retention.ms"=7200000 and "retention.bytes"=524288000

Solution

  1. Step 1: Convert 2 hours to milliseconds

    2 hours = 2 * 60 * 60 * 1000 = 7,200,000 ms.
  2. Step 2: Convert 500MB to bytes

    500MB = 500 * 1024 * 1024 = 524,288,000 bytes.
  3. Step 3: Match values to options

    "retention.ms"=7200000 and "retention.bytes"=524288000 matches both correct values; others have wrong size or time values.
  4. Final Answer:

    "retention.ms"=7200000 and "retention.bytes"=524288000 -> Option D
  5. Quick Check:

    2 hours = 7200000 ms, 500MB = 524288000 bytes [OK]
Hint: Convert hours to ms and MB to bytes carefully [OK]
Common Mistakes:
  • Using seconds instead of milliseconds for retention.ms
  • Confusing MB with bytes without conversion
  • Setting only one limit when both are needed
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