Comprehensive guide to log aggregation architecture for production observability and monitoring systems.
Log aggregation architecture is the systematic approach to collecting, processing, and storing logs from distributed systems into a unified, searchable, and analyzable dataset. It matters when applications span multiple services, machines, and cloud regions, and when diagnosing issues requires correlating events across dozens of components. This architecture becomes essential when log files are scattered, unstructured, and growing at high velocity, and when engineers can no longer rely on tail -f /var/log/app.log on a single server.
The foundation of log aggregation is a pipeline that moves raw logs from sources to a central store. The pipeline consists of three stages: collection, enrichment, and storage. Each stage must handle high throughput, tolerate partial failure, and maintain log order across systems.
Logs originate from processes running in containers, VMs, or serverless functions. A typical agent runs on each host or in each container, writing logs to a local file or stdout. The agent collects logs and forwards them to a central system via a network protocol.
The most common approach uses a log forwarder daemon that watches for new log lines and emits them in batches. For example, a systemd-managed service writes logs to journalctl, and a forwarder reads from journalctl --output=json:
journalctl --follow --output=json --unit=app.service --since="10 minutes ago"
This stream is consumed by a forwarder that sends each log entry as a JSON object over HTTP or TCP. The forwarder uses a checkpoint file to track the last processed log position, ensuring no duplicates or gaps during restarts.
A typical log entry in the pipeline has the following structure:
{
"timestamp": "2024-05-10T12:34:56.789Z",
"level": "INFO",
"message": "User login completed",
"service": "auth-service",
"host": "web-01.prod",
"pid": 1234,
"trace_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef",
"fields": {
"user_id": 4567,
"ip": "192.0.2.1",
"duration_ms": 42
}
}
The forwarder sends this data using HTTP POST to a central endpoint, such as https://logs.example.com/v1/logs. The endpoint accepts a batch of logs as a JSON array:
[
{
"timestamp": "2024-05-10T12:34:56.789Z",
"level": "INFO",
"message": "User login completed",
"service": "auth-service",
"host": "web-01.prod",
"pid": 1234,
"trace_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef",
"fields": {
"user_id": 4567,
"ip": "192.0.2.1",
"duration_ms": 42
}
},
{
"timestamp": "2024-05-10T12:34:57.123Z",
"level": "ERROR",
"message": "Database connection failed",
"service": "payment-service",
"host": "worker-02.prod",
"pid": 5678,
"trace_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef",
"fields": {
"error_code": "CONN_TIMEOUT",
"retry_count": 3
}
}
]
The central system acknowledges receipt with HTTP 200 and includes a x-log-id header for each log in the batch, enabling deduplication and idempotent processing.
After collection, logs often undergo enrichment—adding context that was not present at the source. This stage typically runs as a stream processor that consumes logs from a message queue and applies transformations.
Common enrichment steps include:
A typical enrichment job uses a key-value store to resolve service names and configurations. For example, a log entry with service: "auth-service" is enriched by fetching the service’s metadata from a Redis instance:
GET /service/auth-service
The response might be:
{
"version": "v2.3.1",
"environment": "prod",
"region": "us-east-1",
"team": "auth-team",
"slo": {
"uptime": "99.9%",
"latency_95th": "150ms"
}
}
The enrichment processor merges this into the log entry:
{
"timestamp": "2024-05-10T12:34:56.789Z",
"level": "INFO",
"message": "User login completed",
"service": "auth-service",
"host": "web-01.prod",
"pid": 1234,
"trace_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef",
"fields": {
"user_id": 4567,
"ip": "192.0.2.1",
"duration_ms": 42
},
"enriched": {
"version": "v2.3.1",
"environment": "prod",
"region": "us-east-1",
"team": "auth-team",
"slo": {
"uptime": "99.9%",
"latency_95th": "150ms"
}
}
}
Enrichment may also add context from correlated events, such as adding the user session ID from a database query or linking logs to a previous HTTP request in a trace.
Once enriched, logs are stored in a time-series or document store optimized for querying and retention. The store must support fast range queries, filtering by fields, and aggregation over time.
The most common pattern is to use partitioned storage by time and service. A typical storage system accepts a stream of logs and writes them to a format like Parquet or ORC, partitioned by year/month/day and service.
A query engine like Apache Druid, ClickHouse, or Elasticsearch serves the stored logs. Queries are expressed in a SQL-like language or a domain-specific query language.
Example query in ClickHouse:
SELECT
service,
level,
count(*) AS log_count,
avg(fields.duration_ms) AS avg_duration,
min(timestamp) AS first_event,
max(timestamp) AS last_event
FROM logs
WHERE
timestamp >= '2024-05-10T12:00:00Z'
AND timestamp < '2024-05-10T13:00:00Z'
AND service = 'auth-service'
AND level IN ('ERROR', 'WARNING')
GROUP BY service, level
ORDER BY log_count DESC
LIMIT 50;
The result is returned in JSON or columnar format, ready to be consumed by a dashboard or alerting engine.
Logs are expensive to store and query. A well-designed architecture includes retention policies that move logs between storage tiers based on age and access frequency.
A common strategy uses hot, warm, and cold storage:
Retention is managed via lifecycle policies defined as configuration blocks. For example:
{
"policies": [
{
"name": "hot-7-days",
"trigger": {
"type": "time",
"after": "7d"
},
"action": {
"type": "move",
"target": "es-hot",
"index": "logs-hot"
}
},
{
"name": "warm-90-days",
"trigger": {
"type": "time",
"after": "90d"
},
"action": {
"type": "move",
"target": "parquet-warm",
"path": "/data/logs/warm/{year}/{month}/{day}"
}
},
{
"name": "cold-1-year",
"trigger": {
"type": "time",
"after": "365d"
},
"action": {
"type": "compress",
"format": "gzip",
"destination": "s3://logs-cold/{year}/{month}"
}
}
]
}
The lifecycle engine monitors log age and triggers moves automatically. It must handle partial failures: if a move to S3 fails, the system retries with exponential backoff, and logs remain in warm storage until the move completes.
Several common failure modes silently degrade log quality:
x-log-id header is missing.fields.duration_ms may fail when the field is missing or in a different format (e.g., durationMs, duration_ms, duration_ms_ms).For example, a log entry with:
{
"fields": {
"duration_ms": 42,
"error_code": "CONN_TIMEOUT"
}
}
but the query expects fields.errorCode or fields.error_code, the query returns null for errorCode and misses critical data.
Search is the primary way engineers interact with logs. The index must support:
message and fields.level, service, host, timestamp.The index is built incrementally. As logs are written, they are added to a delta index, and a compaction job merges them into a base index.
Index updates are eventually consistent. A log entry may be available in search within 1–30 seconds, depending on the pipeline’s latency. Engineers must expect that a newly written log may not appear in a dashboard until the next compaction.
The search API is typically a simple HTTP endpoint:
GET /search?query=error&from=2024-05-10T12:00:00Z&to=2024-05-10T13:00:00Z&limit=100
The response includes a list of logs with metadata, highlighting matched terms, and a next_cursor for pagination.
The entire log aggregation pipeline must be monitored. Key metrics include:
A failure in any stage is detected via alerting on metrics. For example:
The pipeline is self-healing: if a forwarder process dies, it restarts and resumes from the last checkpoint. If the central storage is unreachable, the forwarder buffers logs locally and sends them once connectivity resumes.
This architecture ensures that engineers can diagnose complex, distributed issues by simply querying logs—without needing to SSH into multiple servers, pull logs manually, or correlate logs across systems. The result is a unified, reliable, and performant foundation for observability.
This page was rewritten on 17 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.
We use cookies for analytics (Google Analytics) and advertising (Google AdSense) to improve your experience and support free content. Privacy Policy