Why delivery guarantees affect correctness in Kafka - Performance Analysis
When using Kafka, delivery guarantees impact how many times messages are processed.
We want to understand how these guarantees affect the number of operations as message volume grows.
Analyze the time complexity of message processing with different delivery guarantees.
// Pseudocode for consuming messages with delivery guarantees
consumer.subscribe(topic)
while (true) {
records = consumer.poll(timeout)
for (record in records) {
process(record)
consumer.commit()
}
}
This code consumes messages and commits offsets to track progress, ensuring messages are processed according to delivery guarantees.
Look at what repeats as messages come in.
- Primary operation: Processing each message inside the loop.
- How many times: Once per message received in the poll batch.
As the number of messages grows, the processing and commit operations grow too.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 10 process and commit calls |
| 100 | About 100 process and commit calls |
| 1000 | About 1000 process and commit calls |
Pattern observation: Operations increase directly with the number of messages.
Time Complexity: O(n)
This means the work grows in a straight line with the number of messages processed.
[X] Wrong: "Delivery guarantees don't affect how many times messages are processed."
[OK] Correct: Different guarantees like "at-least-once" can cause retries, increasing processing operations beyond the message count.
Understanding how delivery guarantees affect processing helps you explain real-world system behavior clearly and confidently.
What if we batch commit offsets less frequently? How would that change the time complexity?