System Design (High-Level Design) Module 20 – Building blocks: control, safety and platform services
Design a logging pipeline
Design a logging pipeline from a volume estimate to node agents, a replicated buffer, redaction, hot and cold storage, retention by class and cost.
What you will learn
- Estimate a fleet's daily log volume, the buffer an outage needs and the storage of each tier
- Design agents, a replicated buffer and aggregators that survive bursts, node loss and store outages
- Choose a log store from the searches engineers run, and partition and batch writes for it
- Remove personal data and secrets before anything is stored, and test the rules like code
- Set a minimum and a maximum retention for each class of log, and price the policy
Before you start
What you’ll learn · Before you start
What you will learn
- Estimate a fleet's daily log volume, the buffer an outage needs and the storage of each tier
- Design agents, a replicated buffer and aggregators that survive bursts, node loss and store outages
- Choose a log store from the searches engineers run, and partition and batch writes for it
- Remove personal data and secrets before anything is stored, and test the rules like code
- Set a minimum and a maximum retention for each class of log, and price the policy
Before you start
On this page
A logging pipeline carries a fleet’s log lines, 120,000 a second in this lesson, from every process to a store where engineers can search them a minute later, at a cost the business can carry and within the rules on what logs may contain and how long they are kept. Agents on each node read and ship the lines, a replicated log buffers them through bursts and outages, aggregators parse, redact and route them, and storage is split into a hot tier for recent, searchable lines and an archive in object storage for the rest of each line’s retention.
Requirements and estimate: storage is the large number
A shopping and payments app runs 40 services on 2,000 pods. Engineers search its logs in every incident, auditors ask for a year of access records, and the storage bill grows faster than traffic. Ask first:
- How soon after a line is written must it be searchable?
- How many lines a second, of what size, and how high is the peak?
- Which lines carry personal data or secrets, and which rules set each kind’s retention?
- May the pipeline ever drop lines under load, and which ones first?
- Do searches look for words in messages, or for fields such as service and level?
The answers here: within a minute; 120,000 lines a second on average, three times that at the evening peak, about 400 bytes each; access and audit records kept a year, application logs 180 days; nothing dropped silently; most searches filter by service, time and level first.
Functional requirements: parse JSON and key-value lines from every pod; redact before storage; search by fields and words; tail one service live; keep each class for its retention, then erase it. Non-functional requirements: searchable within 60 seconds at p99; no line lost to a burst, a lost node or a two-hour store outage; one noisy service never delays the others; storage that grows slower than traffic.
Retention rules in India
CERT-In’s directions require logs of all ICT systems to be kept securely for a rolling 180 days; its published answers allow them outside India if they reach CERT-In within a reasonable time when asked. The DPDP Rules ask for personal data, traffic data and logs of its processing to be kept for at least a year and then erased, unless another law needs longer, from eighteen months after the Rules were published.
The first estimate:
# A first estimate for the logging pipeline of this lesson. Every input is an assumption to replace with
# measurements: line counts from the agents' own counters, line sizes from a day of real logs, and compression
# ratios from loading a sample day into the store you plan to use.
PODS = 2_000
LINES_PER_SECOND = 120_000 # fleet average over a day
PEAK_FACTOR = 3 # the evening peak against that average
BYTES_PER_LINE = 400 # one JSON line with its fields
STORE_COMPRESSION = 8 # raw bytes to bytes on the hot store's disks
ARCHIVE_COMPRESSION = 10 # raw bytes to bytes in object storage (large blocks, zstd)
HOT_COPIES = 2 # the hot store keeps a replica of every shard
HOT_DAYS = 14
RETAIN_DAYS = 365
OUTAGE_HOURS = 2 # the buffer must hold a store outage this long, at peak
WIRE_COMPRESSION = 4 # batches are compressed on their way into the buffer
BUFFER_COPIES = 3 # replicas of each buffer partition
TB, GB, MB = 10**12, 10**9, 10**6
raw_day = LINES_PER_SECOND * BYTES_PER_LINE * 86_400
peak_lines = LINES_PER_SECOND * PEAK_FACTOR
peak_bytes = peak_lines * BYTES_PER_LINE
hot = raw_day / STORE_COMPRESSION * HOT_COPIES * HOT_DAYS
cold = raw_day / ARCHIVE_COMPRESSION * RETAIN_DAYS
buffer = peak_bytes * OUTAGE_HOURS * 3600 / WIRE_COMPRESSION * BUFFER_COPIES
print(f"lines: {LINES_PER_SECOND:,} a second on average, {peak_lines:,} at peak")
print(f"raw volume: {raw_day / TB:.2f} TB a day; {peak_bytes / MB:.0f} MB a second at peak")
print(f"per pod: {LINES_PER_SECOND / PODS:.0f} lines a second, {raw_day / PODS / GB:.2f} GB a day")
print(f"hot tier: {HOT_DAYS} days x {HOT_COPIES} copies at {STORE_COMPRESSION}x = {hot / TB:.1f} TB of disk")
print(f"cold tier: {RETAIN_DAYS} days at {ARCHIVE_COMPRESSION}x = {cold / TB:.0f} TB in object storage")
print(f"buffer: {OUTAGE_HOURS} hours at peak, {WIRE_COMPRESSION}x on the wire, {BUFFER_COPIES} copies = {buffer / GB:,.0f} GB")
print(f"cold share of stored bytes: {cold / (hot + cold):.0%}") Output
lines: 120,000 a second on average, 360,000 at peak raw volume: 4.15 TB a day; 144 MB a second at peak per pod: 60 lines a second, 2.07 GB a day hot tier: 14 days x 2 copies at 8x = 14.5 TB of disk cold tier: 365 days at 10x = 151 TB in object storage buffer: 2 hours at peak, 4x on the wire, 3 copies = 778 GB cold share of stored bytes: 91%
Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 log_plan.py
Runs on this device, in your browser. The first run downloads Python (about 13.5 MB), which is kept for the next runs.
Your run, in this browser
Storage is the large number: 4.15 TB of raw lines a day becomes 151 TB in the archive over a year, while two weeks in the hot tier take 14.5 TB. A store outage at the peak sets the buffer: about 778 GB of replicated log.
Checkpoint
Check the estimate
The first design of the logging pipeline
Text description of the diagram
The diagram shows the first design from top to bottom.
- At the top, 40 services on 2,000 pods write JSON lines to standard output, which lands in files on each node.
- An agent on each of the 250 nodes reads those files, adds the service and pod names, and holds only a few seconds of lines before sending them on as compressed batches.
- The batches go to a replicated log that keeps 24 hours of lines, partitioned by service. It is the pipeline's buffer.
- Aggregators, one consumer group, read the log at a set pace. They parse each line, apply the service's level gate, redact personal data and secrets, decide where the line goes, and batch the writes.
- Storage has two parts side by side: a hot store that keeps 7 to 30 days depending on the class of log and is searchable within a minute, and an archive in object storage that keeps every line until its class reaches its retention.
- At the bottom, search, live tail and exports serve engineers, alerts and legal requests. They read the hot store; a dashed arrow shows that old cases restore lines from the archive.
Follow one line through it:
The drawing shows the whole scene; its 7 steps are listed below.
Every step as text
- A line is written. The checkout service writes one JSON line to standard output, an error with the time it happened, its level and a message, and the node keeps it in the pod's log file.
- Read on the node. The agent on that node reads the file, adds the service and pod names, and ships the line within seconds in a compressed batch with others.
- Kept through bursts. The replicated log keeps every line for hours on several machines, so a burst or a slow store delays the line but never loses it.
- Made safe to store. An aggregator reads the line at a set pace, parses it, masks the personal data and secrets in it, and gives it a class, which sets how long it is kept.
- Written to both tiers. The line goes to the hot store in a large batch, where it can be searched, and to the archive, which keeps every line until its class's retention ends.
- Found within a minute. An engineer filters by service, time and level, and finds the error less than a minute after checkout wrote it.
- An old case. Once the line has left the hot store, a search for an old case restores it from the archive.
Open choices, one sentence each:
- Node agents: a small process on each node that reads log files and ships parsed lines in batches.
- A replicated log as the buffer: a topic that keeps every line for hours, so a slow store loses nothing.
- Aggregators: a stateless tier that parses, redacts, routes and batches lines before storage.
- Full-text indexes: stores such as OpenSearch that index every word of every line.
- Label indexes: stores such as Loki that index a few labels and keep compressed chunks in object storage.
- Columnar stores: databases such as ClickHouse that keep each field as a compressed column.
- Hot and cold tiers: recent lines on fast disks, every line in object storage until its retention ends.
- Redaction: masking personal data and secrets in a line before anything stores it.
The deep dives that decide the design:
- What happens to lines written during a burst, a node failure or a two-hour store outage?
- Where are lines parsed, and how does one malformed or huge line not stall the rest?
- Which store fits the searches engineers run, and how is it partitioned and sorted?
- How is personal data removed before storage, and how do you know it stays removed?
- How long does each class live, in which tier, and what erases it on time?
- What does a day of logs cost, and which levers cut it without blinding investigations?
Answers are judged on the estimate, ingestion and buffering, redaction, storage and search, retention, cost and failures.
Every line becomes one record with two times Pro: opens with a Pro, Premium or Ultimate pass
In this part:
- A replicated log, drained at a pace, survives a two-hour outage
- The aggregators parse, redact and route every line before the first write
- The searches people run choose the store
- Each class gets a minimum and a maximum retention, enforced in every copy
- Failure drills: a missed redaction, a log storm and a skewed clock
- A redaction rule that failed for three hours
- One service in a crash loop
- A node whose clock runs an hour fast
- Bottlenecks at 10× and 100×
- Alternatives rejected
- What each level is expected to cover
- A sample answer and a 45-minute self-mock
- Practise: redact a line without losing the order ID
- Redact emails, tokens and card numbers, but keep order IDs
- Interview questions
- Your log store must be taken down for two hours of maintenance during the evening peak, when the fleet writes 360,000 lines a second of about 400 bytes. How do you make sure no line is lost, and that the store is not overwhelmed when it comes back?
- A weekly scan finds full card numbers in three days of stored application logs. What do you do in the first hour, the first day and the first month, and how do you make sure it cannot happen again?
- Your logging bill doubled in a quarter while traffic grew 20 %. How do you find out why, and bring it down without losing what investigations and audits need?
- Key takeaways
2 diagrams · 5 runnable examples (Python) · 1 exercise with sample tests · 3 interview answers · about 61 minutes
Opening this part with your pass…
This part opens with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so this part can’t be opened at the moment. The free part above stands on its own. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
Read a complete sample first: Rate-limiting algorithms compared
References
- Fluent Bit manual: Buffering and storage (Fluent Bit (CNCF))
- Vector documentation: Buffering model (Vector (Datadog))
- Kubernetes documentation: Logging architecture (The Kubernetes Authors)
- Apache Kafka documentation, Design (Apache Software Foundation)
- OpenTelemetry specification: Logs data model (OpenTelemetry)
- ClickHouse best practices: Selecting an insert strategy (ClickHouse)
- ClickHouse guides: Manage data with TTL (ClickHouse)
- ALTER TABLE … DELETE statement (ClickHouse)
- Grafana Loki: Label best practices (Grafana Labs)
- Logging at Zerodha (Zerodha Tech Blog)
- Logging Cheat Sheet (OWASP Foundation)
- Directions under section 70B(6) of the Information Technology Act on cyber incidents (Indian Computer Emergency Response Team (CERT-In))
- FAQs on the cyber security directions (Indian Computer Emergency Response Team (CERT-In))
- Digital Personal Data Protection Rules, 2025 (Ministry of Electronics and Information Technology, Government of India)
Related tools
Report a problem with this lesson
Kept only in this browser. Your Learn progress