SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
  • Three Pillars of Observability
  • Logging Best Practices
  • Log Aggregation
  • Metrics and Instrumentation
  • Distributed Tracing
  • Alerts and Monitoring
  • Dashboards and Runbooks
  • SLOs and Error Budgets
  • Incident Management and Postmortems
  • Profiling
  • Audit Logs
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Operations and Security/Observability

Log Aggregation

Collect logs from every machine into one place that you can search.

⏱ 12 min readIntermediateInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

Log aggregation means collecting the logs from every server, container and service into one central place, so you can search them all together.

  • On many machines, logs live in many places and short-lived containers take their logs with them when they disappear.
  • A small agent on each machine ships logs to a pipeline that buffers, parses, indexes and stores them.
  • You then search, filter and alert from one screen, and you pay for the volume you keep, so retention matters.

02Concept: What is it?

Imagine 200 containers, each writing its own log file. An engineer who wants to see what happened to one request would have to log in to dozens of machines, and the container that served it may already be gone. That does not work. Log aggregation solves it by copying every log line to a central system as soon as it is written.

The usual pipeline has four stages: collect (an agent such as Fluent Bit or Filebeat reads the log), transport (often through a buffer such as Kafka, so bursts do not overload the next stage), process (parse JSON, add fields, drop or mask data) and store and search (an index in Elasticsearch, Loki, Splunk or a cloud service).

A log pipeline
🖥️Apps and serverswrite logs
→↓read
🚚AgentFluent Bit, Filebeat
→↓send
📬BufferKafka or queue
→↓pull
⚙️Processorparse, mask, enrich
→↓write
🔎Store and searchindex
The buffer in the middle is what keeps logs from being lost when traffic bursts or the indexer is slow.
🧠Aggregation is also a cost decision
Logs are large. The more you keep, and the longer you keep it, the more it costs. Good pipelines drop noise early and move old logs to cheaper storage.

03Real-Life Example

🍵The Mail Room of a Big Company
A company has hundreds of offices. Each office writes letters and reports. If you wanted to find one letter, you would have to phone every office. So the company builds a central mail room. A courier in each office picks up the mail every few minutes and brings it to a sorting desk. There, mail is labelled, junk is thrown away, private letters are covered, and everything is filed in a big cabinet by date and topic. Someone who needs a letter asks the mail room. If a rush of mail arrives, it waits in a tray until the sorters can catch up. Old files go to a cheaper storage room after a few weeks.
Mail room
Log aggregation
A courier in each office
An agent on each machine
The tray where a rush of mail waits
A buffer queue such as Kafka
Sorters who label and cover private parts
A processor that parses, enriches and masks
The central filing cabinet
The index (Elasticsearch, Loki, Splunk)
Throwing away junk mail
Dropping DEBUG and noisy lines early
Moving old files to a cheaper room
Retention tiers and cold storage
Before and after
No aggregation
🖥️Server 1its own file
🖥️Server 2its own file
📦Containergone with its logs
😩Log in to each, one by one
With aggregation
🖥️Server 1
🖥️Server 2
📦Container
↓shipped at once
🔎One search boxfor all of them

04Why Do We Need It?

🔍One place to search
Find a request across every service with one query.
📦Survive short-lived machines
Logs are saved before a container or a server disappears.
🔗Connect services
Search by request ID to see one story across many services.
🚨Alerts from logs
Count error lines or spot patterns across the whole fleet.
🔒Protected and audited
Access to logs can be controlled, and logs are safe if a server is hacked or wiped.
🧾Keep history
Retention rules keep logs for as long as you need, and no longer.
Logs on one machine help one machine. Aggregated logs help you understand the whole system.

05Where Do We Use It?

🧩Microservices
Dozens of services need one shared place to search.
🐳Containers and Kubernetes
Pods come and go, so logs must leave the pod quickly.
🛡️Security teams
Collect logins, firewall and access logs to detect attacks.
🧾Compliance
Rules may require keeping some logs for a fixed time, tamper-proof.
📈Business insight
Request and event logs can be counted and analysed.
☁️Cloud platforms
Cloud services collect logs from their own managed products by default.

06Types / Parts / How It Works

The stages

StageJobExamplesWatch out for
CollectRead log files or streams on each machineFluent Bit, Fluentd, Filebeat, Vector, a cloud agentAgent CPU and memory on every host. Do not lose lines on restart.
Buffer / transportHold lines safely between stagesKafka, a cloud queue, the agent's own disk bufferBuffer size. When it is full, lines are dropped or senders slow down.
ProcessParse, add fields, mask, drop, routeLogstash, Fluentd, Vector, ingest pipelinesSlow parsing becomes the bottleneck. Bad parsing loses fields.
Store and indexMake the lines searchableElasticsearch / OpenSearch, Loki, Splunk, cloud log servicesIndex size and cost. Slow queries on wide time ranges.
Search and alertQuery, view and alertKibana, Grafana, vendor consolesAccess control and expensive queries.

Two ways to index

Full-text index versus label index
Index every word
🔡Full-text indexElasticsearch, Splunk
Search flexibilityany word
Storage costhigh
Index labels only
🏷️Label indexLoki style
Search flexibilityfilter by label, then scan
Storage costlower
Index everything Index labels
The first is more flexible to search, the second is usually much cheaper to store.

The bars are only a rough picture of the trade-off, not measured values.

Push or pull

  • Agent on each host (push). A local agent reads files or container output and sends the lines on. This is the most common style.
  • Sidecar per pod. A helper container next to the app ships its logs. Useful when the app writes to a file.
  • Direct from the app. The app sends logs over the network itself. Simple, but a slow log system can slow the app.
VisualizerA busy pipeline: lost lines, delay and storageCompare sending straight to the indexer with using a buffer. Turn on the incident to triple the logging, lower the indexer speed, then drop DEBUG at the agent. Finally slide the retention to see storage grow.
How do logs reach the indexer?

Every agent sends straight to the indexer. When the indexer is full, the extra lines are dropped (or the senders slow down).

Lines arriving per second (the white line is the indexer speed)
Lines lost per second
Delay before a new line is searchable, in seconds
0 s15 s30 s
Lines lost
10,000
20% of 50,000
Worst delay
0 s
until searchable
Normal load
1,000/s
indexer: 2,000/s
Written per day
25.9 GB
before compression
Stored for 14 days
363 GB
grows with retention
The indexer can take 2,000 lines per second, but up to 3,000 arrived. 10,000 lines (20%) were lost, and they are lost exactly during the incident, when you need them most.

A simplified model with a simulated clock (no random numbers). Illustrative assumptions: 300 bytes per line, DEBUG is 60% of all lines, and the buffer holds 60,000 lines. Real systems also compress logs and add index overhead, so real storage differs.

07How to Use It / Steps / Implementation

Setting up log aggregation

  1. 1
    Make apps log to standard output or a known file
    In containers, writing to standard output lets the platform collect logs without custom code.
  2. 2
    Run an agent on every node
    Use a light agent (for example Fluent Bit) as a daemon on each host. It tails logs and adds labels such as service, host and version.
  3. 3
    Put a buffer between collection and indexing
    A queue such as Kafka absorbs bursts, lets you re-read lines after a failure and decouples the stages.
  4. 4
    Parse and enrich
    Parse JSON, add the environment and region, and mask sensitive fields before storing.
  5. 5
    Drop or sample early
    Remove DEBUG and health-check lines at the agent so you do not pay to ship and store them.
  6. 6
    Choose retention in tiers
    Keep recent logs in fast storage (days), older logs in cheap storage (weeks or months), and delete after the required time.
  7. 7
    Control access and watch the pipeline
    Limit who can read logs. Monitor lag, dropped lines and index size, and alert if logs stop arriving.
💡Alert on silence
If a service suddenly sends no logs at all, that is often a worse sign than errors. Alert when the expected log volume drops to zero.
⚠️Do not let logging take down the app
Use a local buffer or disk spool on the agent. If the central system is down, the app should keep running and the agent should catch up later.

08Key Terms to Know

TermMeaning in easy words
Log aggregationCollecting logs from many sources into one central system
Agent / shipperA small program on each machine that reads logs and sends them on
PipelineThe chain of stages from collection to storage
BufferA queue that holds lines between stages, so bursts do not cause loss
ParsingTurning a raw line into named fields
EnrichmentAdding fields such as service name, region or version
IndexA data structure that makes logs fast to search
RetentionHow long logs are kept before they are deleted
Hot / cold storageFast and costly storage for recent logs versus slow and cheap storage for old ones
BackpressureA slow stage telling earlier stages to slow down or wait
ELK / Elastic stackElasticsearch, Logstash and Kibana, a well-known log stack

09Pros, Cons and Trade-offs

✅ Pros
  • One place to search the whole system
  • Logs survive when a server or container is gone
  • Easy to search by request ID across services
  • Central access control and retention
  • Feeds alerts and security monitoring
⚠️ Cons
  • Large storage and network cost
  • Extra moving parts to run and monitor
  • Delay between a line being written and being searchable
  • Lines can be lost if the pipeline is not buffered
  • A central store of logs is a target if it holds sensitive data

Trade-offs

ChoiceWe gainWe lose
Straight to the indexerA simple pipelineLines are lost in a burst or an outage
Through a buffer (Kafka)No loss in bursts, replay is possibleOne more system, and some extra delay
Index everythingSearch any word in any lineHigh storage and CPU cost
Index labels onlyMuch lower costSearching text inside lines is slower
Long retentionInvestigate old incidents and meet audit rulesCost grows with every day kept
Short retentionLow cost and less data to protectOld evidence is gone

10Common Problems and Mistakes

Common mistakes

  1. No buffer. A burst during an incident overloads the indexer, and the lines you need most are dropped.
  2. Shipping everything. Health checks and DEBUG lines can be most of the volume and bring little value.
  3. Unlimited retention. The bill grows every day, and old personal data stays longer than it should.
  4. No structure. Unparsed free text cannot be filtered by field, so every search is slow and fragile.
  5. Sensitive data in the index. Once a password is indexed, it is copied and searchable by many people.
  6. No monitoring of the pipeline. Logs silently stop and nobody notices until they are needed.
  7. Clock problems. Wrong timestamps make lines appear out of order.

Things to watch

🌊Log bursts
Errors cause more logs, which can overload the pipeline just when you need it.
🕐Ingestion delay
A backlog means searches show the past, not now.
💸Cost surprises
One chatty service can double the bill. Track volume per service.
🔐Access control
Logs often hold sensitive context. Limit and audit who can search them.

11Real-World Examples

🔎Elastic stack
Elasticsearch with Logstash or Beats and Kibana is a very common open-source stack.
🪵Grafana Loki
A log store that indexes labels, not full text, to keep cost down.
🏢Splunk
A long-established commercial platform for searching machine data and logs.
☁️Cloud log services
Each big cloud has its own managed log service for its resources.
🚚Fluent Bit and Fluentd
Popular open-source agents and processors for shipping logs.
📬Kafka in the middle
Large systems often use Kafka as the buffer between agents and storage.
📝Note
Features, defaults and prices differ between products and change often. Compare them with your own volume and retention numbers.
Mini case: a growing fleet
🖥️300 serversplain files
→↓agents
📬Kafkaabsorbs bursts
→↓processors
🔥Hot index7 days, fast
→↓age out
🧊Cold storagemonths, cheap
As traffic grew, the team added a buffer, dropped debug at the source and tiered retention.

12Related Topics to Read Next

Three Pillars of Observability→

Logs next to metrics and traces.

Logging Best Practices→

What to write into the logs that you aggregate.

Distributed Tracing→

Traces tie requests together the same way a request ID ties logs.

Message Queues→

A buffer queue is the safety valve of a log pipeline.

Full-Text Search Engines→

Many log systems are built on a search index.

Alerts and Monitoring→

Alerts can be built on log counts and on missing logs.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔What: logs from all machines, shipped to one searchable place.
  • ✔Pipeline: agent, buffer, processor, index, search and alert.
  • ✔Buffer: Kafka or a queue, so bursts do not drop lines.
  • ✔Cost: drop DEBUG early, sample, tier storage, set retention.
  • ✔Index: full-text (flexible, costly) or labels (cheaper, narrower).
  • ✔Safety: mask sensitive fields and control who can search.
  • ✔Watch: lag, drops, volume per service, and alert on silence.
  • ✔One line: “Ship every log to one place, through a buffer, and keep only what you can afford and need.”
← Previous
Logging Best Practices
Next →
Metrics and Instrumentation