Docs / Pull-based ingestion

Pull-based ingestion

KalDB indexers pull logs from Kafka at their own pace instead of having writes pushed at them, so slow or failed indexers never raise write latency or reject logs, and an indexer can crash without losing data.

In KalDB, clients never write to the nodes that index their logs. The preprocessor appends each batch to Kafka and acknowledges it, and indexers pull from Kafka at their own pace. Write latency stays flat when indexing slows down, writes keep succeeding when indexers are down, and Kafka doubles as the write-ahead log, so an indexer can crash without losing a single log.

How pull-based ingestion keeps writes fast and durableLogstash sends logs to the preprocessor, which appends them to a Kafka partition and acknowledges them, so they are durable before any indexing. The indexer pulls offsets 1 to 40 into a searchable chunk, uploads it to S3 as a snapshot, and records maxOffset 40 in the snapshot metadata. The indexer crashes while building the next chunk, but offsets 41 to 80 are still in Kafka and writes keep succeeding. A new indexer reads the durable offset, resumes at 41, and replays the rest from Kafka.Logstashor any clientPreprocessorvalidate · routeKafka partition 1 · the write-ahead logoffsets →102030405060708090100replay 41–80IndexerNew indexerreads partition 1active chunk 1–40 · searchablechunk full · uploadingcrashedresumes at offset 41upload snapshotS31–40Snapshot metadata (ZooKeeper)no snapshots yetpartition 1 · maxOffset 40Kafka acknowledges the write.The log is durable before it is indexed.The chunk it was building is gone.Its logs are still in Kafka. Writes continue.start = maxOffset + 1 = 41No other node is involved. No rebalance.
Ingest Writes are acknowledged once they are in Kafka. Indexing is not in the write path. Offsets 1–40 are searchable on the indexer and still safe in Kafka. Offsets 1–40 are in S3. Kafka holds everything after. Indexer down. Writes still succeed, and offsets 41–80 wait safely in Kafka. Caught up from offset 41. Nothing lost, nothing rebalanced.

The problem

Elasticsearch and OpenSearch use push-based ingestion. A _bulk request isn’t acknowledged until the data nodes have indexed it on the primary shard and copied it to the replicas. Anything that slows those nodes down shows up directly in write latency: segment merges, garbage collection, a heavy search, a shard relocation, or a node restart. P99 write latency climbs, bulk queues fill, and the cluster starts rejecting writes with 429 errors. Clients have to buffer, retry, or drop logs. If the cluster is unavailable, ingestion is unavailable too.

Push-based ingestion also makes every data node responsible for durability. Every write goes to a translog and is copied to replica shards on other nodes, usually in other availability zones. Every log is written several times inside the cluster, and when a node fails, the cluster copies shards around to restore the replica count, competing with ingest and searches at the worst possible time.

How it works

Writes and indexing are decoupled by Kafka. Each KalDB indexer pulls from exactly one Kafka partition, and two systems that are already built for durability, Kafka and S3, hold the data.

  1. Writes only touch Kafka. The preprocessor appends every batch to a Kafka partition and acknowledges the client once Kafka accepts it. The log is durable at that point, and no indexer has been involved, so write latency depends only on Kafka, not on how busy indexing is.
  2. Indexers pull at their own pace. Each indexer pulls its partition in offset order and adds each message to an active Lucene chunk on local disk. It tracks the highest offset in the chunk. The active chunk is searchable on the indexer while it is being built, so new logs show up in searches in near real time.
  3. Full chunks are uploaded to S3. A chunk rolls over when it reaches maxBytesPerChunk, maxMessagesPerChunk, or maxTimePerChunkSeconds. The indexer commits it and uploads it to S3 as an immutable snapshot.
  4. The offset is recorded with the snapshot. After the upload succeeds, the indexer publishes snapshot metadata to ZooKeeper: the partition, the time range, and the highest offset in the chunk (maxOffset). That offset marks how far the partition is durable in S3.
  5. A new indexer resumes from S3. When an indexer starts, it looks up the highest durable offset for its partition from the snapshot metadata. It also cleans up metadata for any chunk a crashed indexer was still building. If the gap to the head of the partition is within maxOffsetDelayMessages, it starts at the next offset and replays the rest from Kafka. If the gap is larger, it skips to the head and hands the gap to recovery nodes. See Fresh logs first.

Why it matters

  • Flat write latency. Merges, garbage collection, heavy searches, and indexer restarts never sit in the write path, so they don’t raise p99 write latency.
  • Writes keep succeeding when indexing doesn’t. If indexers are slow, down, or being redeployed, logs wait in Kafka and are indexed when the indexers catch up. Clients don’t see rejections and don’t need their own buffering.
  • Built-in backpressure. A spike lands in Kafka, not in an indexing queue that overflows. Indexers drain it at the rate they can sustain.
  • Each log is replicated once, by Kafka. There is no translog and no replica shards inside the cluster, so ingest doesn’t pay for extra copies or cross-AZ traffic between data nodes.
  • Indexers are disposable. An indexer can crash, be redeployed, or move to another machine at any time. Its replacement only needs the partition ID.
  • No rebalancing. Recovering from a failed indexer means replaying a few minutes of Kafka on one node, not copying shards across the cluster.
  • Simple to reason about. A log is in Kafka, in an indexer’s active chunk, or in S3. The snapshot metadata says exactly which offsets are where.

Trade-offs

  • Kafka retention has to cover the gap. Anything not yet uploaded to S3 is only in Kafka. Keep Kafka retention longer than the time it takes to fill and upload a chunk, plus the time to replace a failed indexer.
  • Replayed logs are searchable again only after replay. Until a new indexer catches up, logs from the lost chunk are in Kafka but not searchable.
  • Chunk size is a trade-off. Bigger chunks mean fewer, larger uploads and less metadata, but more to replay after a crash.

Configuration

indexerConfig:
  # A chunk rolls over and uploads to S3 when it hits any of these limits.
  maxMessagesPerChunk: 100000
  maxBytesPerChunk: 1000000
  maxTimePerChunkSeconds: 5400
  # Lag beyond which a starting indexer skips to the head instead of replaying.
  maxOffsetDelayMessages: 10000000
  kafkaConfig:
    kafkaTopic: test-topic
    kafkaTopicPartition: 0

To watch uploads, track these metrics from the metrics reference:

  • rollovers_completed_total: chunks uploaded to S3.
  • rollovers_failed_total: uploads that failed. Alert if this grows.
  • rollover_timer_seconds: how long each rollover and upload takes.

Related