Course contentsShow
← System Design
Lesson 1169 of 1,91929. Observability: LoggingFree lesson

Centralized vs Localized Logging

Ship logs to central aggregation immediately; avoid relying on local disk logs in ephemeral environments.

Centralized vs Localized Logging

What You'll Learn

You'll learn why shipping logs to a central system immediately is critical in modern distributed systems, and why storing logs only on local disk is a dangerous anti-pattern in ephemeral environments.

The Problem with Localized Logging

Localized logging means writing logs directly to disk on the server where your application runs. This was common in traditional infrastructure where servers lived for months or years. You could SSH into a box, grep through /var/log, and debug issues.

But in cloud-native and containerized environments, instances are ephemeral—they spin up and disappear in minutes. If your container crashes or auto-scales down, those local disk logs vanish forever. When you need them most (during an incident), they're already gone.

The Centralized Solution

Centralized logging means shipping logs to an external aggregation system (like Elasticsearch, Loki, or Splunk) as soon as they're generated. Think of it like the difference between keeping personal diaries scattered across temporary hotel rooms versus mailing every entry to a permanent archive immediately.

Benefits:

  • Durability: Logs survive instance termination
  • Searchability: Query across all services in one place
  • Correlation: Connect logs from multiple services using correlation IDs
  • Scale: Handle thousands of ephemeral containers

Implementation Approach

Use asynchronous log shipping with a local buffer. Your application writes to memory, a sidecar agent (like Fluentd or Filebeat) ships logs immediately to the central system. If shipping fails temporarily, buffer locally—but never rely on local disk as your source of truth.

In Kubernetes, logs from stdout/stderr are automatically collected and can be forwarded centrally. Avoid writing to files inside containers.

Key Takeaway: In ephemeral infrastructure, centralized logging isn't optional—it's mandatory. Ship logs immediately to survive instance failures and enable cross-service debugging.