0
0
Kafkadevops~5 mins

At-most-once delivery in Kafka - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: At-most-once delivery
O(n)
Understanding Time Complexity

When using Kafka's at-most-once delivery, we want to know how the time to send messages changes as we send more messages.

How does the system handle more messages without slowing down too much?

Scenario Under Consideration

Analyze the time complexity of the following Kafka producer code snippet.

producer.send(record);
producer.flush();

This code sends a message and immediately flushes it to ensure at-most-once delivery.

Identify Repeating Operations

Look at what repeats when sending many messages.

  • Primary operation: Sending and flushing each message one by one.
  • How many times: Once per message sent.
How Execution Grows With Input

As you send more messages, the time grows directly with the number of messages.

Input Size (n)Approx. Operations
1010 sends and flushes
100100 sends and flushes
10001000 sends and flushes

Pattern observation: Doubling messages doubles the work because each message is sent and flushed separately.

Final Time Complexity

Time Complexity: O(n)

This means the time to send messages grows in a straight line with the number of messages.

Common Mistake

[X] Wrong: "Flushing after every message is fast and does not affect performance."

[OK] Correct: Flushing each message forces waiting for confirmation every time, making the total time grow linearly and slowing down sending many messages.

Interview Connect

Understanding how sending messages one by one affects time helps you explain trade-offs in message delivery guarantees clearly and confidently.

Self-Check

What if we batch multiple messages before flushing? How would the time complexity change?