Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

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.

  • Intermediate
  • 30 minutes
  • Examples run with Python 3.14.8, Pyodide 314.0.7, Node.js 24.21.0 and quickjs 0.32.0
  • By MySmartCoPilot
Free intro, Pro: 5 of 30 minutes free
Free: Requirements and estimate: storage is the large number. With a pass: the other 13 sections and 3 interview answers, about 25 minutes.

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:

Volume, buffer and storage for the fleet Python · plan/log_plan.py
# 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

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

  1. Question 1 of 3 A fleet writes 80,000 log lines a second on average, 500 bytes each. About how many TB is that a day, before compression?

    Type a number.

    A hint

    A day has 86,400 seconds.

    Show the answer: Question 1 of 3

    Answer: 3.46 TB (anything from 3.11 to 3.81 counts)

    80,000 × 500 bytes = 40 MB a second, and 40 MB × 86,400 seconds = 3.46 TB a day.

  2. Question 2 of 3 The hot store compresses those lines 8 times and keeps 2 copies of everything. How many TB of disk do 7 days in the hot tier need?

    Type a number.

    Show the answer: Question 2 of 3

    Answer: 6.05 TB (anything from 5.45 to 6.65 counts)

    3.46 TB ÷ 8 = 0.43 TB a day on disk, × 2 copies = 0.86 TB, × 7 days = 6.05 TB.

  3. Question 3 of 3 The peak is 3 times the average. How many GB must the buffer hold for a 2-hour store outage at peak, if batches are compressed 4 times on the wire and every partition has 3 copies?

    Type a number.

    Show the answer: Question 3 of 3

    Answer: 648 GB (anything from 583 to 713 counts)

    The peak is 240,000 lines a second × 500 bytes = 120 MB a second. Two hours is 7,200 seconds, so 864 GB of raw lines; ÷ 4 for compression = 216 GB, × 3 copies = 648 GB.

Pods write lines; node agents ship them to a replicated log; aggregators redact them and write a hot store and an archive.40 services on 2,000 podswrite JSON lines to standard outputAn agent on each of 250 nodesreads the files, adds service and pod,holds a few seconds of linesReplicated log: the buffer24 hours of lines, partitioned by serviceAggregators, one consumer groupparse · level gate · redact · route · batchStorageSearch, live tail and exportsfor engineers, alerts and legal requestsHot store7 to 30 days by classsearchable within a minuteArchive in object storageevery line, until its classreaches its retentionfiles on the nodecompressed batchesread at a set pacelarge batcheshourly filesrestore for old cases

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:

Interactive · stage by stage One log line through the first design Step through one line from the service that writes it to the search that finds it, one part of the design at a time.
One log line through the first design, step 7 of 7. Showing Checkout service, Node agent, Replicated log (kept for hours), Aggregators (parsed, redacted, classed), Hot store, Archive, Search.restore for old casesCheckout servicewrites a JSON lineNode agentreads the pod's log fileReplicated logkept for hoursAggregatorsparsed, redacted, classedHot storerecent and searchableArchivein object storageSearchservice, time, levelrestore for old cases

The drawing shows the whole scene; its 7 steps are listed below.

Every step as text
  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. Found within a minute. An engineer filters by service, time and level, and finds the error less than a minute after checkout wrote it.
  7. 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:

  1. What happens to lines written during a burst, a node failure or a two-hour store outage?
  2. Where are lines parsed, and how does one malformed or huge line not stall the rest?
  3. Which store fits the searches engineers run, and how is it partitioned and sorted?
  4. How is personal data removed before storage, and how do you know it stays removed?
  5. How long does each class live, in which tier, and what erases it on time?
  6. 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.

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

Related tools

Report a problem with this lesson

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.