Quick revision
The short answer
We stop indexing every field. Based on real query patterns, we index only what people filter on, such as service, environment, level and trace id, and keep message bodies in compressed chunks in object storage, which queries narrow by labels and time and then scan in parallel. Chunk-level Bloom filters let queries skip chunks that cannot contain a term, a short hot tier keeps full-text indexing only for services that need it, and logs are parsed into structured fields at ingestion with noisy debug logs dropped or sampled under per-service quotas.
What to remember
In this answer, we saw that full-text indexing of every field costs CPU and storage on every line and falls behind exactly during incidents. We started from real query patterns, which showed that most searches filter by service, time and trace id, and redesigned around a small label index with compressed chunks in object storage scanned in parallel, Bloom filters per chunk to skip non-matching data, a short full-text hot tier only for services that need it, and structured parsing, debug sampling and per-service quotas at ingestion.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
We stop indexing every field. Based on real query patterns, we index only what people filter on, such as service, environment, level and trace id, and keep message bodies in compressed chunks in object storage, which queries narrow by labels and time and then scan in parallel. Chunk-level Bloom filters let queries skip chunks that cannot contain a term, a short hot tier keeps full-text indexing only for services that need it, and logs are parsed into structured fields at ingestion with noisy debug logs dropped or sampled under per-service quotas.
Why this question is asked
A search cluster that indexes every field of every line works beautifully at a few hundred gigabytes a day and becomes the most expensive system in the company at ten terabytes. The warning signs here are clear: 300 nodes, indexing 20 minutes behind at peak, and most data never searched. Interviewers ask this to see whether we redesign from how logs are actually used, rather than buying more nodes. In this answer, we will see why full indexing stops scaling, start from real query patterns, move to label indexing with chunks in object storage, use Bloom filters to skip chunks, keep a hot full-text tier where it pays, and control volume at ingestion.
1Why Indexing Everything Stops Scaling
A full-text index, an inverted index like a book's index that maps every term to the documents containing it, makes any word searchable in milliseconds. The price is paid on every line, whether or not anyone ever searches it: CPU to tokenise and index, an index that is often as large as the raw data, and replicas of both on fast disks. At 10 TB a day with 30 days of retention and one replica, the cluster stores on the order of 600 TB including indexes, which is why it needs 300 nodes.
The indexing lag at peak is the other symptom. Indexing throughput is bounded by cluster CPU, so when an incident raises log volume, indexing falls behind exactly when engineers need fresh data. Cost grows linearly with volume, or worse, while the value of most of that data stays at zero.
2Start From Real Query Patterns
Before choosing a design, we look at the last few months of query logs. Which fields appear in filters? How far back do queries go? What fraction of data is ever returned? The pattern is usually very consistent.
| Query shape | Share of queries | Typical time range |
|---|---|---|
| service + time + level | 62% | last 1 to 6 hours |
| trace id | 21% | last 24 hours |
| service + free text | 12% | last 1 to 3 days |
| free text across all services | 4% | last 7 days |
| anything older than 7 days | under 1% | audits, investigations |
Notice what this tells us. More than 80 percent of queries could be answered by an index of a handful of labels plus the trace id, and almost nothing needs full-text search over old data. The design should be built for the common case and accept being slower for the rare one.
3Index Labels, Keep Bodies in Chunks
The new design indexes only the fields people filter on: service, environment, level, region, and the trace id. Message bodies are written into compressed chunks, for example a chunk per stream of labels per few minutes, and stored in object storage such as S3. The index maps label values and time ranges to chunk references, so it is tiny compared with a full-text index.
A query proceeds in two steps. It uses the label index and the time range to select candidate chunks, for example checkout, prod, ERROR, last hour gives 400 chunks out of millions. Then it fetches and scans those chunks in parallel across many query workers. Scanning 40 GB of compressed data with 200 workers takes a few seconds. Storage costs drop dramatically: 10 TB a day compressed tenfold is 1 TB a day, so 30 days is about 30 TB in object storage, a fraction of the cost of 600 TB on SSD nodes.
8 messages in order. Play them, or step through them one at a time.
4Bloom Filters to Skip Chunks
For free-text searches we add a small summary per chunk: a Bloom filter of the terms it contains. A Bloom filter is a compact bit array that answers 'might this term be in the chunk?' with either 'definitely not' or 'maybe'. It never misses a term that is present, and with a few bytes per distinct term it gives a low false-positive rate, such as 1 percent.
So when someone searches for a rare order id across a day of one service's logs, the workers check each chunk's Bloom filter first and skip every chunk where the answer is 'definitely not'. A needle search that would scan 2,000 chunks might read only 25. That is most of the benefit of an inverted index for needle searches, at a small fraction of its size.
5A Hot Tier Where Full Text Pays
Some services do need fast arbitrary search, such as security event logs or a payments service with strict investigation targets. For them we keep a short hot tier, for example 3 days, in a full-text search cluster, alongside the chunk store. After 3 days, their data is like everyone else's: label-indexed in object storage. Older data, beyond 30 days, is archived in a cheaper storage class and searched on demand, where a query that takes minutes is acceptable.
The search cluster now holds 3 days of a subset of services instead of 30 days of everything, so it shrinks from 300 nodes to perhaps a few dozen, and its indexing keeps up because it receives a fraction of the volume.
6Structure and Quotas at Ingestion
The cheapest log is the one we never store. Processors parse logs into structured fields at ingestion, so searches filter on fields such as status or order_id instead of scanning text, and repeated free-text messages compress better. Debug logs are dropped in production by default or sampled, for example keeping 1 in 100.
Each service gets a volume quota, such as its normal daily volume plus 50 percent. Above the quota, the lowest-priority levels are sampled first, and the owning team is alerted. Together with showback of cost per service, this keeps volume growth tied to value rather than to habit.
7Follow-up questions
Will engineers accept slower free-text search?
Most of their queries become as fast or faster, because label-filtered queries scan a small set of chunks in parallel and indexing no longer lags. For the rare global free-text search, a few seconds or tens of seconds is an acceptable trade for a cost that grows much more slowly than volume. The hot tier covers services with a real need.
How do we migrate without losing search during the move?
Dual-write for the retention period: send logs to both systems, point queries at the new one service by service, compare results for a sample of real queries, and switch fully once the old cluster's data has aged out. No backfill is needed if we can wait 30 days.
Why not just add more nodes to the search cluster?
Because cost would keep growing at least linearly with volume, and indexing lag during incidents would return at the next growth step. The design spends money on data nobody reads; more nodes only spend more of it.
8Conclusion
In this answer, we saw that full-text indexing of every field costs CPU and storage on every line and falls behind exactly during incidents. We started from real query patterns, which showed that most searches filter by service, time and trace id, and redesigned around a small label index with compressed chunks in object storage scanned in parallel, Bloom filters per chunk to skip non-matching data, a short full-text hot tier only for services that need it, and structured parsing, debug sampling and per-service quotas at ingestion.
Open with
The cluster indexes every field of every line, so we pay CPU and SSD for an index about as large as the data, for data most of which is never searched, and indexing falls behind exactly when incidents raise the volume.
Then, if they want more
I would start from real query patterns over the last few months, which usually show that most incident queries filter by service, time window, level and trace id. So I would index only those fields, and store message bodies in compressed chunks in object storage.
A query uses the label index and time range to pick candidate chunks and then scans them in parallel across many workers, which takes seconds. Storage drops from hundreds of terabytes on SSDs to around thirty terabytes compressed in S3 for a month.
For free-text needle searches, each chunk carries a Bloom filter of its terms, so queries skip chunks that cannot match without a full inverted index. Services that genuinely need fast arbitrary search get a short hot tier, say three days, with full-text indexing; after that everything is label-indexed or archived and searched on demand.
At ingestion, logs are parsed into structured fields, debug logs are dropped or sampled, and each service has a volume quota with cost shown to its team. The result is that cost grows much more slowly than volume, while the queries people actually run during incidents still return in seconds.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How would you redesign log storage and indexing so cost grows more slowly than volume...": https://scrivio-interview-library.netlify.app/architecture/system-design-problems/70a5f695ba/