"Design a log aggregation system" is the question behind the search box where engineers type a request id at 3 a.m. and expect every line from every service to appear. Collecting logs from thousands of machines is the easy part. Paying for them is the interview.
The observability lesson explains why log volume is a design decision, and why structured, bounded logs beat free text. This page is the pipeline that carries them: how lines get from a process to a searchable store, what you index and what you leave alone, and what happens when a bug turns one service into a log firehose. It is the sibling of the metrics monitoring system, and the contrast is instructive. Metrics aggregate at the source and stay small. Logs keep every event, so their size grows with traffic and you have to decide where to spend.
Interviewers listen for four things: a number for the daily volume, a reason you do not index everything forever, a rule for what is dropped under overload, and the point that logging must never take down the application it observes.
Clarify the requirements
Functional requirements:
- Collect logs from every service instance (files, stdout and containers).
- Search logs by time range plus filters (service, host, level, request id) and by text.
- Tail logs live during an incident.
- Retain logs for a configured period, with older logs cheaper and slower to query.
- Support access control per team and redaction of sensitive fields.
Out of scope, said aloud: metrics and traces, log-based alerting rules (mention that alerts can read the stream), analytics dashboards and machine-learning anomaly detection.
Non-functional requirements:
- Never block the application: a slow or dead log pipeline must not slow or crash a service.
- Near-real-time: a line is searchable within about 10 seconds.
- Durable enough: losing a few lines in a crash is acceptable, losing minutes of logs is not, and error logs are the last to be dropped.
- Cost-aware: volume is large, so cost per terabyte retained drives the design.
- Absorbs bursts: an incident multiplies the log rate exactly when the logs matter most.
Estimate the scale
Assume 10 TB of logs per day, an average line of 300 bytes, a 3× peak and the retention policy: 3 days fully searchable, 90 days total.
Lines per day: 10 × 10¹² B ÷ 300 B ≈ 33 billion lines.
Line rate: 33.3B ÷ 86,400 s ≈ 386,000 lines per second, about 1.2 million per second at peak.
Bandwidth: 10 TB ÷ 86,400 s ≈ 116 MB/s, about 350 MB/s at peak.
Hot tier (full-text index): 3 days × 10 TB = 30 TB. A full-text index plus stored source takes about the size of the raw data after compression, so 30 TB, and with one replica 60 TB of SSD. At 2 TB per node that is 30 data nodes, and each indexes about 386,000 ÷ 30 ≈ 13,000 lines per second, comfortably under an assumed 20,000 per node.
If we indexed everything for 90 days: 900 TB, doubled by a replica is 1.8 PB of SSD, thirty times the hot tier.
Cold tier: 90 days × 10 TB = 900 TB raw. Compressed 8:1 in object storage, that is about 112 TB, a fraction of the SSD bill.
Buffer: to ride out an indexing outage of a day, keep 24 hours in the stream: 10 TB × 3 replicas = 30 TB of disk.
"At 386,000 lines per second, indexing is a real expense, and keeping a full-text index for 90 days would need 1.8 PB of SSD. The numbers say the design is a tiering problem: index only the recent days, and keep the rest compressed and cheap. And a day-long buffer in front means the indexers are never the thing that makes a service lose logs."
The capacity estimator reproduces the 386,000 lines per second and about 30 TB for the 3 days of hot data.
API and data model
POST /v1/logs batch of { ts, service, host, level, message, fields{} } (from collectors)
GET /v1/search ?q=level:error AND request_id:abc&from=...&to=...&limit=100
GET /v1/tail ?service=checkout&level=warn (streaming)log event ts (event time), service, host, level, request_id, message, fields
hot index daily indices, e.g. logs-2026.12.02, shards ~30 GB each, 1 replica
cold chunk object in object storage: compressed lines + per-chunk index of
(service, level, time range) and a Bloom filter of request idsEvents are structured at the source: a line is JSON with a few known fields and the rest in fields. Free-text lines force the pipeline to parse at ingest, which is slow and brittle.
High-level design
The slice to simulate is the ingest pipeline: services ship lines to collectors, a stream buffers bursts, and indexers write searchable batches into Elasticsearch.
- Services write lines locally and an agent ships batches to a collector tier.
- Collectors append the batches to a partitioned stream, which buffers bursts.
- Indexers read the stream and write bulk batches to the search index.
Describe this diagram
Components
- services (Client)
- collectors (Service)
- log buffer (Kafka)
- indexers (Service)
- log index (Search cluster (Elasticsearch))
Connections
- services sends to collectors
- collectors sends to log buffer
- log buffer sends to indexers
- indexers sends to log index
Run it, then try raising the load or lengthening the index's refresh_interval_s, and watch how the indexing stage and the end-to-end path react. Refresh interval is a direct trade of freshness for indexing throughput.
The write path: an agent on each host tails log files, joins multi-line stack traces into one event, attaches host and service labels, redacts configured fields, batches for a second or two and ships to a collector. The collector authenticates, applies quotas and appends to the stream. Indexers read in bulk (thousands of lines per request) and write to the current day's index.
The read path: a query service accepts a time range and filters. It picks the daily indices in range, searches them in parallel across shards and merges the top results. A tail request subscribes to the stream directly for matching lines, rather than polling the index.
The interesting problem: what to index
Approach A: full-text index everything
Index every field of every line in Elasticsearch or a similar engine, for the whole retention period.
Good: any term, in any field, is found in milliseconds. Engineers can search for a half-remembered message with no preparation.
Bad: it is the 1.8 PB answer. Indexing costs CPU on every line (386,000 per second), and the index plus replicas is as large as the data or larger. Most of what you index is never searched.
Approach B: index only labels, scan the rest
Index a few labels (service, host, level, time) and store the log lines in compressed chunks in object storage. A query narrows by labels and time to a set of chunks and scans them for the text.
Good: ingest is cheap, because only labels are indexed, and storage is cheap object storage at about 8:1 compression. Cost per terabyte is a small fraction of approach A.
Bad: a needle-in-a-haystack search ("find this exact error text across all services in 30 days") scans a lot of data and is slow. It rewards good labels and short time ranges.
Approach C: tier by age
Keep the full-text index for the last 3 days, where almost all incident searches happen. After that, move data to compressed, label-indexed object storage for the remaining 87 days, and keep one extra index on the field engineers search most by id, such as request_id, as a Bloom filter per chunk, so a request id lookup reads only the few chunks that might contain it.
Good: fast search where it matters and cheap storage where it does not. The cold tier costs about 112 TB instead of 900 TB of SSD.
Bad: two query paths with different speeds, and a lifecycle job that moves data between them. Users must learn that old searches are slower.
Diagram, as text
- Log line leads to Hot tier: full-text index, 3 days
- Hot tier: full-text index, 3 days leads to Warm: compressed chunks, labels indexed
- Warm: compressed chunks, labels indexed leads to Cold: object storage, Bloom filter per chunk
- Cold: object storage, Bloom filter per chunk leads to Deleted after retention
The recommended answer is C. The sentence to say: "I put the index money where the questions are: nearly all searches are about the last few hours, so I pay for full-text there and let older data be cheaper and slower." If an interviewer pushes for a simpler system, approach B alone is a legitimate starting point.
The second decision: what happens under overload
Logging has an unusual rule: it must never hurt the application. That decides every overload behavior.
- Inside the application, the logger writes to a bounded in-memory queue, or to a local file, and a separate agent ships it. If the queue is full, the logger drops the line and increments a counter. It never blocks the request thread.
- At the agent, a buffer on local disk (say 1 GB, about 15 minutes of a busy host) holds lines while the collector is slow or unreachable. When it fills, drop in order of value: debug first, then info (sampled), and errors last.
- At the collector, per-service quotas stop one noisy service from using the whole pipeline. Over-quota lines are sampled, not rejected outright, and the agent is told to back off.
- At the stream, the 24-hour buffer absorbs an indexer outage. Consumers catch up when the index recovers.
Delivery is at-least-once: if an agent resends a batch after a timeout, a line may appear twice. Duplicates in logs are an annoyance, not a bug, and are cheaper than the coordination needed to prevent them, though a deterministic event id lets the indexer drop exact repeats. Say this on purpose, because candidates usually claim exactly-once and then cannot explain it.
Bottlenecks and failures
A log storm. A bug or a retry loop makes one service log 100 times its normal rate: 10 TB a day becomes 10 TB an hour from that service. Quotas at the collector, sampling of repeated identical lines ("this message occurred 48,000 times") and an alert on per-service rate protect the shared pipeline.
Indexing falls behind. If indexers cannot keep pace, stream lag grows and searches miss recent lines. Alert on lag in seconds, scale indexers up to the partition count and lengthen the index refresh interval from 1 s to 5 s to gain throughput.
Hot shards and bad sizing. Shards that are too small waste memory and too large recover slowly. Aim for tens of gigabytes per shard (the Elasticsearch guidance is roughly 10 to 50 GB), use daily indices with a fixed number of shards and let index lifecycle management roll them over, move them to warm nodes and delete them.
Expensive queries. A wildcard regex across 90 days can scan terabytes. Require a time range, cap the range and result size, apply timeouts and show the cost before running a heavy query.
Sensitive data. Logs collect passwords, tokens and personal data by accident. Redact known patterns at the agent, before the data leaves the host, and apply per-team access control and an audit log on searches. Deleting one person's data from a 90-day immutable store is hard, so keep sensitive fields out in the first place.
What if the whole pipeline is down? Applications keep running, because they never wait on it. Agents buffer for about fifteen minutes and then start dropping low-value lines. When the pipeline returns, buffered data flows in, and the dropped-lines counter records the gap, so no one mistakes silence for health.
Trade-offs to name aloud
- Tiered indexing: slower searches on old data, in exchange for roughly a thirtieth of the SSD cost.
- At-least-once delivery: occasional duplicate lines, in exchange for simple, fast shipping.
- A day-long stream buffer: 30 TB of disk, in exchange for surviving an indexing outage without data loss.
- Dropping low-severity lines under pressure: missing debug output in a storm, in exchange for keeping errors and protecting the application.
- Structured logs at the source: discipline for developers, in exchange for cheap, reliable parsing and search.
What interviewers listen for
- A working answer: agents, a collector tier, a queue, an index and a search UI.
- A strong answer: computes lines per second and terabytes per day, explains why a full index of everything is unaffordable and tiers by age, and buffers bursts in a stream.
- A standout answer: also states that logging must never block the application, defines a drop order under overload, handles log storms with quotas, avoids mapping explosions and redacts sensitive data at the agent.
Check your understanding
Common mistakes
Sending all logs straight to the index. There is no buffer, so an index slowdown drops logs or backs up into services. Put a durable stream between collectors and indexers.
No volume estimate. Without lines per second and terabytes per day, "use Elasticsearch" has no basis. The numbers decide the tiering.
Letting logging block the application. A synchronous call to a remote log service in the request path makes the log system an outage multiplier. Write locally, ship asynchronously.
Claiming exactly-once. It is not free. Say at-least-once, accept rare duplicates and use event ids if you need dedup.
Treating all lines equally under load. A debug flood must not displace error lines. Define priorities before the incident.
Ignoring sensitive data. Logs are where secrets leak. Redact at the source and control access.
Practice
A deploy bug makes one service log 100 times more than usual for 30 minutes. What protects the pipeline, and what do you do afterward?
Write your own answer first, on paper or in a note. Then compare.
Show a hint
Think at each stage: the application, the agent, the collector and the stream.
Show a strong answer
At the source: the service's logger has a bounded queue, so the flood cannot block requests, only lose lines.
At the collector: a per-service quota (for example, three times the service's normal rate) throttles it. Lines over quota are sampled, and identical repeated messages are collapsed into one line with a count, so the information survives at a fraction of the volume.
In the shared pipeline: other services keep their own quotas, so they are unaffected. The stream absorbs any remaining excess, and the lag alert tells you if indexing falls behind.
Afterward: alert the owning team automatically from the per-service rate metric (that is the real signal), keep the sampled lines for debugging, and review the quota. Add a deploy check that compares log volume before and after a release.
The pattern worth keeping: isolate tenants with quotas so one bug cannot spend the shared budget.
An engineer has a request id and a 30-day-old incident, and cold logs are only label-indexed. How do you make the search fast without indexing everything?
Write your own answer first, on paper or in a note. Then compare.
Show a hint
You do not need full-text search, only a way to skip chunks that cannot contain the id.
Show a strong answer
Chunk the cold data by time and service, for example 256 MB compressed objects, each with a small summary: its service, its time range and a Bloom filter of the request ids inside.
Search the summaries first. The query service reads only chunk summaries for the time range, and tests the request id against each filter. A Bloom filter has no false negatives, so any chunk that does contain the id passes.
Read only the matches. If the request touched 50 services, perhaps 50 chunks pass the filter, plus a few false positives. Reading 50 × 256 MB ≈ 12.8 GB is a few seconds in parallel, compared with scanning 30 days of data, about 37.5 TB compressed.
Make it a habit: require a request id and a time range on the cold path, and store the request id as a first-class field so it is filterable.
The pattern worth keeping: a cheap probabilistic summary per chunk can replace an expensive index when you only need to skip what cannot match.
Key takeaways
- Do the arithmetic: 10 TB a day is 386,000 lines per second and 900 TB for 90 days.
- Index by age: full-text for recent days, compressed labeled chunks for the rest.
- Put a durable stream between collectors and indexers so indexing trouble never loses logs.
- Logging must never block the application, so drop by priority and count what you drop.
- Use quotas per service to contain log storms, and limit indexed fields.
- Redact at the agent, because logs leak secrets.
Further reading
- J. Kreps, "The Log: What every software engineer should know about real-time data's unifying abstraction", LinkedIn Engineering blog (2013).
- Elasticsearch Reference, "Index lifecycle management" and "Size your shards": rollover, tiers and shard sizing.
- The Twelve-Factor App, factor XI "Logs": treating logs as event streams written to stdout.