Skip to main content

librdkafka settings

On the bus transport Vector owns the Kafka clients, and the supervisor writes their librdkafka settings into the generated source and sink as librdkafka_options. This page covers where those settings come from and how to change them.

Layers​

Three layers merge into librdkafka_options, highest last:

LayerSourceWho manages it
1. Baseline profileconsumer.production or producer.production in the central file when it defines that profile, else scalo's CONSUMER_PRODUCTION or PRODUCER_PRODUCTIONPlatform operator, or scalo
2. Service overridesHardcoded in src/config/generate.rsThis repo
3. Per-instance optionssource.librdkafka_options, sink.librdkafka_optionsWhoever writes the config

Layer 1 is one layer, not two. A profile in the central file REPLACES the matching scalo constant set outright, so a central producer.production that names only linger.ms ships only linger.ms, and every other baseline setting reverts to what Vector writes itself, below, or else librdkafka's default. Layer 2 sits on whichever source won, so a central setting cannot undo a service override: queue.buffering.max.kbytes set centrally takes no effect here.

Vector applies librdkafka_options over the settings it writes itself from the source and sink fields, so every layer above outranks those:

librdkafka keyWritten by Vector from
session.timeout.ms, auto.commit.interval.ms, auto.offset.resetsource.session_timeout_ms (30000), source.commit_interval_ms (5000), source.auto_offset_reset (largest)
enable.auto.commit, enable.auto.offset.store, statistics.interval.msVector's kafka source code, as true, false and 1000
message.timeout.ms, socket.timeout.mssink.message_timeout_ms (0, no limit), sink.socket_timeout_ms (60000)
queue.buffering.max.ms, batch.num.messages, batch.sizesink.batch.timeout_secs, .max_events and, where set, .max_bytes

linger.ms is librdkafka's other name for queue.buffering.max.ms, and a client built from both takes whichever its hash map applied last. Vector always writes sink.batch.timeout_secs as queue.buffering.max.ms, so the supervisor moves a batching delay that a layer names into batch.timeout_secs and leaves both spellings out of librdkafka_options. A layer that names either spelling replaces the other spelling from every layer below it, and within one layer the spelling that sorts last wins. A layer therefore outranks sink.batch.timeout_secs. The production profile names linger.ms, so on the bus transport timeout_secs has no effect until a central profile drops that key, and the supervisor logs a warning when timeout_secs is not 1 and a layer overrides it.

A few keys are derived from the big dials and written after the merge, so librdkafka_options cannot reach them:

KeyOwned byWritten when
compression.type, compression.codecsink.compressionalways, on the sink, as Vector's compression field
security.protocol{source,sink}.sasl.enabled + .tls.enabledeither is on
sasl.mechanism{source,sink}.sasl.mechanismSASL is on
enable.ssl.certificate.verification{source,sink}.tls.skip_verifyTLS is on and verification is skipped

config-check rejects a config that sets one of these in librdkafka_options, and names the big dial that owns the key. With SASL off nothing derives sasl.mechanism, so setting it by hand there is allowed. Any other key can be set per instance, bar two checks. config-check rejects enable.auto.offset.store: true in any layer of the source consumer's options, the central profile included, because librdkafka would then store offsets at fetch, before the sink acknowledges. The client config built from each endpoint's brokers, SASL, TLS and librdkafka_options must pass scalo's Kafka security floor.

source:
librdkafka_options:
fetch.min.bytes: "2097152" # 2 MiB instead of 1 MiB

sink:
librdkafka_options:
queue.buffering.max.kbytes: "524288" # 512 MiB

For example, for a producer with no central file, sink.compression: lz4 and sink.librdkafka_options: {linger.ms: "20"}, the supervisor writes batch.timeout_secs: 0.02 and compression: lz4 on the sink and, in librdkafka_options, queue.buffering.max.kbytes=262144, enable.idempotence=true, socket.nagle.disable=true, statistics.interval.ms=1000 and message.max.bytes=16777216, the last because no layer set it.

Add a central producer.production naming only linger.ms: "50" and socket.nagle.disable and statistics.interval.ms drop out of librdkafka_options, because the central profile replaced the constants rather than merging over them. Vector still writes statistics.interval.ms=1000 itself. The delay stays 20 ms: the per-instance option outranks the central file. Drop that option and it becomes 50 ms.

dfe-transform-vector --config <file> assemble <dir> writes 90_sink.yaml and 00_source.yaml, so you can read the result for any config.

The production profiles​

This app reads CONSUMER_PRODUCTION for the source and PRODUCER_PRODUCTION for the sink, and no other profile. The librdkafka defaults below are those of the librdkafka release Vector bundles.

Consumer settingValuelibrdkafka defaultJustification
partition.assignment.strategycooperative-stickyrange,roundrobinKIP-429: incremental rebalances avoid stop-the-world pauses. Partitions stay assigned during rebalance -- only moving partitions are revoked.
fetch.min.bytes1048576 (1 MiB)1Batch fetches for throughput. Broker waits until 1 MiB of data is available before responding, reducing fetch round-trips.
fetch.wait.max.ms100500Upper bound on fetch latency when the fetch.min.bytes threshold isn't met. Prevents 500 ms stalls on low-volume topics.
queued.min.messages20000100000Pre-fetch queue depth, large enough for batching and small enough to bound memory and rebalance lag.
enable.auto.commitfalsetrueSuits a service that commits by hand after processing. This app overrides it back to true -- see Service overrides.
statistics.interval.ms10000 (disabled)librdkafka internal metrics at 1-second granularity.
Producer settingValuelibrdkafka defaultJustification
linger.ms205scalo's throughput sizing, as every scalo producer batches. This is the delay the sink uses, in place of sink.batch.timeout_secs. See Layers.
compression.typezstdnonescalo's codec on every sizing profile. sink.compression replaces it on every sink.
socket.nagle.disabletruetruelibrdkafka's default as well. The profile states it.
statistics.interval.ms10000librdkafka metrics.

Left at librdkafka's default, unless a layer or a Vector field above writes them:

SettingDefault
queued.max.messages.kbytes65536 (64 MiB)
socket.receive.buffer.bytes0 (OS default)
heartbeat.interval.ms3000
max.poll.interval.ms300000
fetch.max.bytes52428800 (50 MiB)
acksall (-1), which idempotence needs anyway
retries2147483647

Service overrides​

SettingSideValueReason
queue.buffering.max.kbytesproducer262144 (256 MiB)librdkafka's default 1 GiB producer queue is too large for a transform-vector pod.
enable.idempotenceproducertrueThe sink retries without limit, and a retry on a non-idempotent producer can reorder and duplicate records within a partition.
enable.auto.commitconsumertrueVector's kafka source stores offsets on delivery and leaves the periodic flush to librdkafka's commit timer, which the baseline's false never arms. Vector still commits on rebalance and clean shutdown, so the baseline left reported lag stuck between those points rather than losing offsets.
message.max.bytesproducer16777216 (16 MiB), scalo's MESSAGE_MAX_BYTESThe record ceiling every other stage's producer and every topic scalo creates accept, where librdkafka's default of 1000000 rejects a larger record. Written only where neither layer 1 nor sink.librdkafka_options sets the key. The size cap in front of the sink reads the same value.

Central config file​

The central file is $DFE_CONFIG_DIR/shared/librdkafka.yaml, read only when DFE_CONFIG_DIR is set. This app reads it if it is there and falls back to scalo's constants if it is not, and no other DFE app reads it. It is layer 1, so the service overrides still win over any key it sets.

The profiles load once, on first access, and are cached for the process lifetime, so a change to the file needs a restart: a hot reload keeps the cached profiles.

consumer:
production:
partition.assignment.strategy: cooperative-sticky
fetch.min.bytes: "1048576"
# ... add/remove/change any librdkafka setting

producer:
production:
linger.ms: "20"
compression.type: zstd
# ...

Only the production profile of each side is read. A profile in the file replaces the scalo constant set of that name, and a missing one leaves the constants in force. So does an empty one, or one holding no string, number or boolean value: it is skipped.

The code and the references behind this page:

  • Profile constants: scalo-rs src/kafka_config.rs
  • Central file loader: src/config/kafka_defaults.rs (consumer_profile(), producer_profile(), the OnceLock cache, merge_layers())
  • Layer merge and derived keys: src/config/generate.rs (build_source_librdkafka, build_sink_librdkafka, SERVICE_CONSUMER_OVERRIDES, SERVICE_PRODUCER_OVERRIDES)
  • Config fields: src/config/loader.rs (SourceConfig.librdkafka_options, SinkConfig.librdkafka_options)
  • librdkafka CONFIGURATION.md -- every property, with its default
  • KIP-429 -- the cooperative-sticky rebalance protocol