Kafka
C#
Confluent-Kafka-Dotnet
Message Timeout
Programming

confluent-kafka message timeout: delivery.timeout.ms vs message.timeout.ms

Codemia Knowledge Hub ·

In confluent-kafka-dotnet (and the other Confluent clients built on librdkafka), a produced message times out when it is not delivered within message.timeout.ms, which defaults to 300,000 ms (5 minutes) and includes retries. delivery.timeout.ms is an alias for the same setting, not a separate limit. request.timeout.ms and retry.backoff.ms shape what happens inside that window.

confluent-kafka-dotnet is the Kafka client for .NET designed and maintained by Confluent. Timeouts can affect consumers too, but they show up most often on the producer.

The producer timeout settings

  1. message.timeout.ms: how long the client waits for a message to be acknowledged by the broker, including retries, before it reports an error. Default 300,000 ms (5 minutes).
  2. delivery.timeout.ms: an alias for message.timeout.ms in librdkafka. It sets the upper bound on the time to report success or failure of a send.
  3. request.timeout.ms: the ack timeout of a single produce request. The broker enforces it, and it applies only when acks is not 0. A request that times out can be retried while message.timeout.ms has time left.
  4. retry.backoff.ms: how long the producer waits before retrying a failed send, which can help under load or partial outages.
ConfigurationDefault Value (ms)Description
message.timeout.ms300000Max time producer will wait for message acknowledgment
request.timeout.ms30000Max time for request response before timeout
delivery.timeout.ms300000Alias for message.timeout.ms
retry.backoff.ms100Wait time before retrying a failed send

Configuring the producer in C#

csharp
1using Confluent.Kafka;
2using System;
3using System.Threading.Tasks;
4
5public class KafkaProducer
6{
7    public static async Task Main(string[] args)
8    {
9        var config = new ProducerConfig
10        {
11            BootstrapServers = "localhost:9092",
12            MessageTimeoutMs = 5000, // 5 seconds
13            RequestTimeoutMs = 3000, // 3 seconds
14            RetryBackoffMs = 500 // 0.5 second
15        };
16
17        using (var producer = new ProducerBuilder<Null, string>(config).Build())
18        {
19            try
20            {
21                var result = await producer.ProduceAsync("test-topic", new Message<Null, string> { Value = "Hello Kafka" });
22                Console.WriteLine($"Message delivered ('{result.Value}' to {result.TopicPartitionOffset})");
23            }
24            catch (ProduceException<Null, string> e)
25            {
26                Console.WriteLine($"Delivery failed: {e.Error.Reason}");
27            }
28        }
29    }
30}

When delivery does not succeed in time, ProduceAsync throws a ProduceException, and e.Error.Reason says why. ProducerConfig exposes this limit as MessageTimeoutMs. delivery.timeout.ms is only an alias for it, so configure one name, not both.

Dealing with timeout errors

Timeout errors are usually transient. Adjusting these settings or adding resources (network bandwidth, broker capacity) often resolves them. Errors that persist usually point to an underlying problem such as a network partition or a failed broker.

Practices that reduce timeouts

  • Monitor Kafka, your applications and the network, which catches many issues early.
  • Use retries with idempotent producers so messages are not lost and failures do not flood the network.
  • Test failure scenarios to see how the system reacts and whether your timeout values hold up under different conditions.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design