Build a Fleet-Wide Log Search Platform at 100K Lines/Second
System DesignModel answerLast updated
Design a platform that collects logs from many microservices, keeps them for 30 days, and supports fast searches by service, time window, and text or regex pattern.
Design a Fleet-Wide Log Search Platform
Your company runs hundreds of microservices, and engineers currently SSH into hosts to read logs. Design a central platform that gathers logs from every service and lets engineers search them quickly.
Functional requirements
- Collection: services (directly or through a host agent) send log lines to the platform through a shared interface.
- Search: users can filter by service name and time range, and match on keywords or regular expressions.
- Retention: every log line stays searchable for 30 days, then is removed.
Non-functional requirements
- Throughput: sustain 100,000 log lines per second.
- Query speed: searches should return within a few seconds.
- No loss after acknowledgment: once the collection endpoint confirms a log line, it must never be lost.
What to cover
- Capacity estimates (volume per day, storage for the retention window).
- The write path from service to durable storage, including the API contract.
- Storage layout and schema.
- Indexing approach and why you chose it over alternatives.
- The read path for a search query.
- How the system behaves during traffic bursts and when downstream components fail.
- Trade-offs and what you would improve with more time.
Hints
Hint 1
Start with numbers: lines per second times average line size gives bytes per second, per day, and over 30 days. Notice that writes vastly outnumber reads, and ask how that should shape your indexing choice.
Hint 2
Compare indexing every word (inverted index) with indexing only a few low-cardinality labels such as service and level, then scanning matching data on demand. Think about index size, write cost, and how each handles regex.
Hint 3
For durability, decide exactly when the ingestion endpoint may say 'accepted', and make downstream consumers safe to retry. For bursts, think about a replicated log or queue that decouples producers from the storage writers.
Hint 4
Retention is easiest when stored data is immutable and organized by time. Consider how that makes deletion a simple lifecycle rule rather than a compaction job.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Clarify and size the problem
State assumptions first:
- Average line is about 500 bytes with metadata.
- Peak is roughly 3x average (~300K lines/s).
- Most searches target the last day and name a service.
| Metric | Estimate |
|---|---|
| Average ingest | 100K x 500 B = ~50 MB/s |
| Peak ingest | ~150 MB/s |
| Raw per day | ~4.3 TB |
| Raw over 30 days | ~130 TB |
| Compressed (zstd, ~8-10x) | ~13-16 TB |
This is a write-heavy, read-light workload: 100K writes/s, but only tens of queries/s, each potentially scanning gigabytes. That asymmetry drives the design toward cheap writes and a small index.
2. API
Ingest: POST /v1/logs with a batched, compressed payload (protobuf or gzip JSON) of records {ts, service, host, level, trace_id, message, attrs}. Authenticate with service tokens or mTLS.
202 Acceptedonly after the batch is durably written to the queue.429when a tenant exceeds quota; agents back off and retry from a local disk buffer.
Search: GET /v1/logs/search?service=&start=&end=&level=&q=®ex=&limit=&cursor=. Results stream newest first with a pagination cursor.
3. Architecture
Services -> Host agent (disk buffer)
-> Ingestion gateway (stateless: auth, validate, rate limit)
-> Kafka (partitioned by tenant/service, RF=3, acks=all, min ISR=2)
-> Writer fleet (consumer group): batch per stream, compress, write chunk to object storage, write index entry, commit offset
Query service -> index lookup -> parallel chunk scan -> merge -> stream
Durability chain
- The gateway replies 202 only after Kafka confirms with
acks=all. - Writers commit offsets only after both the chunk and its index entry are stored.
- Make writes idempotent: derive the chunk ID from partition plus offset range, so a retry overwrites the same object. At-least-once delivery becomes effectively-once storage.
- Agent disk buffers cover failures before acceptance.
Bursts and failures
- Kafka absorbs spikes; retain 24-72 hours so writer outages do not lose data.
- Gateways are stateless and scale horizontally; writers autoscale on consumer lag.
- If Kafka is saturated, shed load with 429. Agents still hold the data, so nothing already acknowledged is at risk.
- A single noisy service can create a hot partition. Apply per-tenant quotas, and split hot streams across sub-partitions by hashing a secondary key.
4. Storage layout
- Chunks: immutable, compressed blocks (1-4 MB) of lines from one stream (tenant + service + small label set) in one time window. Key:
/{tenant}/{service}/{date}/{hour}/{chunk_id}.zstin object storage. - Index: a small table in a KV or wide-column store. Partition key
(tenant, service, day), sort key(min_ts, chunk_id), valuesmax_ts, labels, line_count, level bitmap, bloom filter of tokens.
5. Indexing: the central trade-off
Option A, full inverted index (Elasticsearch/OpenSearch). Excellent keyword lookup, but index overhead is often 1-1.5x raw size, indexing 100K docs/s needs a big cluster, segment merging and shard management are operationally heavy, and regex still falls back to scanning.
Option B, label index plus scan. Index only low-cardinality fields (tenant, service, level, region). The index is under ~1% of data. Keyword and regex queries scan only the chunks that survive time and label pruning, in parallel on stateless workers.
Choice: Option B, given the write-heavy profile and the 30-day horizon, with two accelerators:
- Per-chunk bloom filters over tokens, so a search for "timeout" skips chunks that definitely lack it.
- Keep high-cardinality fields (
trace_id,user_id) out of the label index; they would explode the number of streams. Bloom filters still help find them.
Worked example: a service producing ~5% of traffic yields about 9 GB raw (~1 GB compressed) per hour. With bloom filters skipping ~80% of chunks and 50 workers scanning in parallel, a one-hour keyword search completes well under a second to a few seconds. Wide queries (all services, 7 days) are slow; mitigate by requiring a service filter, streaming partial results, and enforcing per-query scan budgets.
6. Tiering and retention
| Tier | Age | Where | Purpose |
|---|---|---|---|
| Hot | 0-48 h | NVMe cache on query workers + object store | Most queries |
| Warm | 2-30 d | Object store (standard/infrequent access) | Occasional investigations |
| Expired | >30 d | Lifecycle delete + index TTL | Retention rule |
Because chunks are immutable and date-keyed, retention is a lifecycle rule; no compaction needed. An optional compactor merges tiny chunks from low-volume services to cut request overhead.
7. Query path
- Authenticate and resolve which tenants and services the user may read.
- Query the index by
(tenant, service, day)across the range; prune with level bitmap and bloom filters. - Split surviving chunks across workers; read from SSD cache or object-store range reads.
- Decompress and match keywords or regex. Use a linear-time engine (RE2) to prevent pathological patterns.
- K-way merge by timestamp, scanning newest first, and stop once
limitis reached. - Cache repeated dashboard queries.
8. Trade-offs
- Scan vs index: cheaper writes and storage, slower needle-in-haystack searches. Acceptable given the read/write ratio.
- Chunk size: bigger chunks compress better and cut object-store calls but raise ingest-to-searchable latency. Let queries also read unflushed data from writers' in-memory buffers to close the gap.
- Partition key: partitioning by service gives locality but risks hot partitions.
9. Common mistakes
- Skipping capacity math or ignoring the read/write asymmetry.
- Acknowledging before data is replicated, which breaks the durability promise.
- Non-idempotent writers that create duplicates on retry.
- Indexing high-cardinality fields as labels.
- Using a backtracking regex engine on user-supplied patterns.
- Forgetting multi-tenant quotas, so one noisy service starves everyone.
10. Follow-ups worth preparing
- Handling a service that suddenly emits 100x its normal volume (quotas, sampling, dropping debug-level lines first).
- Live tailing (stream from Kafka or writer buffers rather than storage).
- Cost reduction (aggressive compression, shorter hot tier, sampling noisy levels).