Docs / One query across live and historical data

One query across live and historical data

A single OpenSearch-compatible search in KalDB covers logs indexed seconds ago and years of history. The query node skips chunks that can't match, searches the rest in parallel, and merges the results. Cold data restores on demand, with local-disk performance for the length of an investigation.

One KalDB search covers logs indexed a second ago and logs from years ago. Callers use one OpenSearch-compatible API. The query node works out which chunks can match, searches them in parallel wherever they live, and merges the results into one response. For cold data, KalDB restores just the range you need onto local disk for the length of an investigation, so a one-off analysis over the past five years runs at the same speed as a search over the last hour, without paying to keep five years in cache.

How one KalDB search covers live, historical, and cold dataAn AI agent sends a search for the payments dataset over the last six hours to the query node. The query node reads chunk metadata, keeps only the chunks in that time range on the payments partitions, and searches them in parallel: an indexer for the live chunk and two cache nodes for uploaded snapshots. It merges the hits and aggregations into one response. When the investigation goes back five years, the older chunks are only in S3, so the agent asks the cluster manager to restore them. A cache node loads them from S3 onto local disk, and the same search covers five years and today's logs at local-disk speed. The restored copies expire after an hour.Chunk metadata (ZooKeeper)last 6 hourspast 5 yearspaymentspartition 112345678webpartition 2older1–4: cold, only in S31–4: restored for 1 hournowClustermanagerrestoreAI agentsor peopleQueryrequest inplanscattermerge5 years + todayIndexer 18Cache 156Cache 27Cache 3 · loadingCache 3 · restored1234live datauploaded snapshotsS3every chunkGET payments/_search · @timestamp: last 6 hoursOnly chunks 5–8 match. Older chunks and web's partition are skipped before any node is asked.One request per node, all in parallel. The live chunk is on the indexer, older ones on cache nodes.Hits are merge-sorted and aggregations combined into one OpenSearch response.RestoreReplica · payments · past 5 years · expires in 60 minFive years and today's logs in one search, at local-disk speed. You pay for an hour of cache.
Search One search, one API, any time range. 4 of 16 chunks match. 12 are never touched. Only the 3 nodes that hold matching chunks are searched, in parallel. Live and historical results in one response. Going back 5 years: chunks 1–4 are restored from S3 for an hour. 5 years searched at local-disk speed, without keeping 5 years in cache.

The problem

Most log stacks split data by age. Recent logs sit in a hot cluster, and older logs move to a warm tier, an archive, or a different product altogether. Searching across the boundary means two queries, two APIs, and stitching the results together by hand, or restoring the archive first.

The split hurts AI agents most. An agent investigating an incident needs to compare what’s happening now with what happened last week, and it can’t do that well if each time range needs a different tool.

Even inside one cluster, a search usually fans out to every shard of every index in the range, including shards that can’t contain a match.

How it works

KalDB stores logs as chunks. Each chunk belongs to one Kafka partition and covers a known time range. While a chunk is being written it lives on an indexer. Once it’s full, it’s uploaded to S3 as a snapshot and served by cache nodes. Metadata for every chunk, and for every node that can search it, is kept in ZooKeeper.

  1. One search arrives. A client sends an OpenSearch _search request to the query node, naming the dataset (index) and a time range. It doesn’t need to know whether the data is live or historical.
  2. Skip what can’t match. The query node looks up which partitions the dataset used during that time range. It keeps only chunks that overlap the time range and belong to those partitions. Everything else is skipped before any node is contacted.
  3. Pick one copy of each chunk. A live chunk is searched on its indexer. An uploaded chunk is searched on a cache node, picked at random when there are several replicas. If a chunk was just uploaded and is on both an indexer and a cache node, the cache node copy is used, so the chunk is searched exactly once.
  4. Search in parallel. The query node groups the chunks by node and sends one request to each node, all at the same time. Each node searches its own chunks and returns its top hits and aggregations.
  5. Merge into one response. The query node merge-sorts the hits, keeps the requested number, and combines the aggregations into a single OpenSearch response.
  6. Answer on time. Each node gets a deadline. If a node misses it or fails, the query node returns what it has and reports how many nodes failed, instead of waiting or failing the whole search.

Cold data: restore on demand

Keeping years of logs on fast local disk is what makes long retention expensive in most systems. KalDB keeps every snapshot in S3 and only caches recent data. When an investigation, an audit, or an ad hoc analysis needs older data, you restore just that range, as in steps 5 and 6 of the animation.

  1. Cold data stays in S3. Snapshots past the cache window stay in S3, at S3 prices. Nothing is archived to a different format or a different system.
  2. Restore a time range. Ask the cluster manager to restore a dataset’s snapshots for a time range, with the RestoreReplica Manager API or from the admin UI. You can also restore specific snapshots by ID with RestoreReplicaIds.
  3. Search at local-disk speed. The cluster manager creates temporary replicas of those snapshots, and cache nodes load them from S3 onto local disk. The cache tier scales up to hold them. Searches over the restored range run as fast as searches over recent data, through the same API, in the same query as live logs.
  4. Pay for the investigation, not the history. Restored replicas expire after an hour by default, and the cache tier scales back down. The data stays in S3, ready to restore again.
POST /slack.proto.astra.ManagerApiService/RestoreReplica
{
  "serviceName": "payments",
  "startTimeEpochMs": "1609459200000",
  "endTimeEpochMs": "1767225599000"
}

Why it matters

  • One API for every time range. Dashboards, scripts, and AI agents send the same request for the last minute or the last year.
  • Fresh and deep at once. Logs are searchable seconds after they arrive, and the same search reaches as far back as your retention goes.
  • Local performance for cold data, without the cost. Restore five years for an hour-long investigation and search it at local-disk speed, then let it expire. You pay for an hour of cache, not for five years of it.
  • Less work per search. Time range and partition pruning mean a search only touches chunks that can contain matches, not every shard in the cluster.
  • Predictable latency. One slow node can’t hold a search hostage. You get an on-time answer and a clear signal when it’s incomplete.

Trade-offs

  • Partial results are possible. When a node misses the deadline, the response leaves out its chunks. Check the failure count in the response before treating a result as complete.

  • Time range matters. Pruning is by time first. A search without a tight time range has to look at many more chunks.

  • Aggregations are merged in two stages. Each node aggregates its own chunks, and the query node combines the results, so very high-cardinality aggregations move more data back to the query node.

  • Restored data takes a few minutes to load. Cache nodes have to download the restored snapshots from S3, and new cache nodes have to start, before the range is searchable at full speed.

  • Restore is a request, not automatic. Someone, or an agent, asks for the range. Large ranges are split into several requests: each one can restore up to maxReplicasPerRequest snapshots (200 by default).

  • Retention is set on S3, not on cache. Snapshots are deleted from S3 after snapshotLifespanMins, which is 7 days by default. To restore years of history, raise it to cover your retention.

Configuration

The query node’s timeouts are set in queryConfig:

queryConfig:
  serverConfig:
    # Overall timeout for a request to the query node.
    requestTimeoutMs: 5000
  # Deadline for each node to return its results.
  defaultQueryTimeoutMs: 3000

requestTimeoutMs must be higher than defaultQueryTimeoutMs, so the query node has time to merge results and respond. KalDB rejects a config where it isn’t.

Restores and S3 retention are set in managerConfig:

managerConfig:
  replicaRestoreServiceConfig:
    # How long restored replicas stay in cache before they expire.
    replicaLifespanMins: 60
    # Most snapshots a single restore request can cover.
    maxReplicasPerRequest: 200
  snapshotDeletionServiceConfig:
    # How long snapshots are kept in S3. Raise this to keep years of history.
    snapshotLifespanMins: 10080

Related