Loading...
System Design and AI Engineering, by Roni Das. 980 interactive lessons.
Start LearningSystem design interview guide
Short answer
A distributed logging system collects log lines from every server, keeps them safe and makes them searchable. Apps write structured JSON logs to stdout. An agent on each machine (Fluent Bit, Vector or the OpenTelemetry Collector) adds labels such as service and pod, batches the lines and buffers to disk. Kafka sits in the middle as a durable buffer, so a slow store never pushes back on the apps. Processors parse lines, mask secrets and personal data, and sample noisy DEBUG lines. Recent logs go to a hot store: a full-text index (OpenSearch), a label index with compressed chunks (Grafana Loki) or a column store (ClickHouse). Older logs go to cheap object storage such as S3. At 500,000 lines a second of 500 bytes, that is 21.6 TB a day raw, so indexing and retention choices set the cost.
in this guide
8 parts open to everyone · 3 with a free account · 3 with the course
It tests whether a candidate can design a write-heavy pipeline where the data is huge, mostly never read, and urgently needed at the worst moment. A weak answer draws 'apps send logs to Elasticsearch' and stops. A strong answer estimates the volume and turns it into storage cost. It separates collection from storage with a buffer, so the logging system can never take down the apps. It chooses how to index with a reason, because indexing every word of 21.6 TB a day is the single biggest cost. It plans retention tiers, handles bursts by sampling and dropping in a known order, and treats logs as sensitive data that can leak passwords and personal details.
This page is the free part.
₹499 in India$49 everywhere elseonce, for the whole course
The System Design course covers the distributed logging system design across a run of lessons, not one page. These 4 alone are about 56 minutes of step-by-step reading, every one with a quiz.
Live from the course bench
Real interview questions, live diagrams and measured lab results, pulled at random from the lessons. A new set every time you come back.
Always clarify these in the first 5 minutes of the interview. Do not start drawing boxes until both lists are agreed.
This guide is built on these 6 lessons. Each one teaches one piece of the distributed logging system design above, step by step.
Lifetime access for ₹499 in India or $49 elsewhere. Interactive diagrams, quizzes, and 20 capstone projects to practise on.
This one question is not enough for the interview.
Each question has why it is asked, a full answer, what the interviewer listens for, the follow-ups, the common mistakes and a diagram (268 diagrams in all). A PDF you keep, junior to staff level.
Two courses by the author of this page:
770 lessons · 18 free to read
₹499 in India · $49 elsewhere, once
Get System DesignYou own this course
210 lessons · 10 free to read
₹999 in India · $49 elsewhere, once
Get AI EngineeringYou own this course
Save your progress and get the interview checklist PDF
Every program writes a diary as it runs: 'order 812 paid', 'database timeout after 2 s', 'user 42 logged in'. Each line is a log. On one server you read the file. Now run 5,000 servers and hundreds of services (separate programs that each do one job). A user says checkout failed at 10:42. The answer is in one line, on one of 5,000 machines, among 500,000 new lines a second. Machines are replaced every day, so their local files vanish. A logging system collects every line from every machine into one place, keeps it safe, and lets an engineer search all of it in seconds. It must never slow down the apps it watches, and it must survive the worst moment, when everything is failing and every server suddenly logs ten times more.
A distributed logging system collects log lines from many servers, stores them centrally, and makes them searchable. First, some terms. A log line is one record a program writes, such as an error with a time and a message. Structured logs are written as fields (JSON is common), for example level=ERROR, service=checkout, trace_id=abc, instead of free text, so machines can filter them. An agent is a small program on each server, such as Fluent Bit, Vector or the OpenTelemetry Collector, that reads the logs and ships them. Kafka is a system that stores a stream of messages on disk, in order, so other programs can read them later. Object storage, such as Amazon S3, is cheap storage for whole files. The usual design has five stages. Collect: apps write to standard output or a file, and an agent on each machine reads it. It adds labels such as the service and the pod (one running copy of an app in Kubernetes), and buffers on disk if the next stage is slow. Buffer: a durable queue, usually Kafka, takes everything, so a slow or broken store never pushes back on the apps. Process: consumers (programs that read from Kafka) parse lines, remove secrets and personal data, drop or sample noise, and route by team. Store: a hot tier keeps recent logs ready to search. It is one of three kinds: a full-text index of every word (Elasticsearch or OpenSearch), a small index of labels with the text in compressed chunks (Grafana Loki), or a column store (ClickHouse). Then a cheap cold tier in object storage keeps logs for months or years. Query: a UI such as Grafana or Kibana, plus alerts on error patterns. With 5,000 servers writing 100 lines a second of 500 bytes each, that is 250 MB a second, 21.6 TB a day before compression, which is why indexing choices and retention decide the cost.
Where it shows up
Asked as 'design a logging system', 'design a distributed logging system', 'design a centralised log aggregation system' or 'design Splunk or the ELK stack' (Elasticsearch, Logstash and Kibana). Common at cloud, infrastructure, observability and SRE teams, and at any company with many microservices (many small services). It is also a frequent follow-up in other designs: 'how would you debug this in production?' leads straight here.
Spec sheeta distributed logging system
worked through below, with the maths
The hard parts of this design are taught step by step in the System Design course: Log Aggregation, Centralized Logging and Structured Logging.
Collecting logs from every service into one searchable place, finding the needle in the haystack.
One place for all logs, the operational backbone of distributed systems.
Logs as data, not text, making every log line queryable and machine-parseable.
Retention, rotation, access control, and lifecycle policies, keeping logs useful without drowning in them.
all part of
System Design Masterclass
770 lessons · about 283 hours · 18 free to read
₹499in India, by UPI
$49everywhere else, by PayPal
You own this course
Continue with Log Aggregationpay once,
yours for life
Show your math. Pulling numbers from thin air signals you have not thought about the load.
Ingest rate
500,000 lines a second on average, 1.5 million at peak
Interview assumptions: 5,000 servers, each writing 100 log lines a second on average. 5,000 x 100 = 500,000 lines a second. Plan for a peak of 3 times that, 1,500,000 lines a second, because error storms are exactly when logs matter most.
Bytes per second
250 MB a second on average, 750 MB at peak
Assume an average structured (JSON) line of 500 bytes. 500,000 x 500 = 250,000,000 bytes, which is 250 MB a second. At peak, 1,500,000 x 500 = 750 MB a second.
Raw volume per day
21.6 TB a day
250 MB a second x 86,400 seconds in a day = 21.6 TB a day before compression. This number drives every cost decision in the design.
Storage: hot and cold tiers
about 60.5 TB hot, about 1.58 PB cold
Assume logs compress 5 times; real ratios depend heavily on the data, so measure your own. 21.6 / 5 = 4.32 TB a day. Hot tier: 7 days kept searchable with one replica (one extra copy), 4.32 x 7 x 2 = 60.5 TB on fast disks. Cold tier: a year in object storage, 4.32 x 365 = 1,577 TB, about 1.58 PB (a petabyte is 1,000 TB). This ignores the index; a full-text index adds a large share on top of the hot tier, which is why the indexing choice matters.
Kafka buffer for a storage outage
1.8 TB of logs, 5.4 TB of disk with 3 copies
Goal: if the store is down for 2 hours, keep everything. 250 MB a second x 7,200 seconds = 1.8 TB. With a replication factor of 3, a common choice (Kafka keeps 3 copies of each partition), that is 5.4 TB of disk across the Kafka cluster, before compression. This is at the average rate. If the outage happens during a 3 times peak, you need three times as much.
Kafka partitions
at least 75
A topic is a named stream of messages in Kafka. A partition is one ordered slice of a topic that only grows at the end. In each consumer group (one team of readers), only one consumer reads it at a time. Planning assumption: each partition carries at most 10 MB a second. Peak 750 MB a second / 10 = 75 partitions. Round up for growth, for example to 96 or 128, because adding partitions later reshuffles which keys go where.
Agent disk buffer
a 1 GB buffer holds about 5.6 hours on one server
One server writes 100 x 500 = 50 KB a second. 1 GB / 50 KB a second = 20,000 seconds, about 5.6 hours. So if Kafka is unreachable, each agent can keep logs on its own disk for hours before it must drop anything, at normal volume. In a 10 times burst, that falls to about 33 minutes.
Sampling saves
keeping 1 in 10 DEBUG lines leaves 46% of the bytes
Assume DEBUG lines are 60% of the volume. Keep every ERROR and WARN, keep 1 in 10 DEBUG lines: 1 - 0.6 x 0.9 = 0.46, so 46% of the bytes remain and storage cost roughly halves, without losing a single error.
Draw five stages, left to right. One: collection. Apps write logs to standard output and standard error. In Kubernetes (a system that runs containers across many machines), the container runtime writes those streams to files on the node, the machine. An agent runs once on every node (a DaemonSet). The agent, for example Fluent Bit, tails the files, which means it reads new lines as they are added. It adds labels from Kubernetes (namespace, pod, container), batches lines, compresses them, and sends them on. If the next stage is slow, it buffers on its own disk. Two: the buffer, a Kafka cluster. Agents write to log topics, split by team or log type, partitioned so that load spreads evenly. Kafka keeps a few hours of logs on disk, so the stores behind it can fall behind, restart or be upgraded without any effect on the apps. Three: processing. A pool of consumers, which can be Vector, Logstash, Fluentd or your own code, reads from Kafka and parses each line into fields, drops or masks secrets and personal data, samples noisy DEBUG lines, enforces per-service quotas, and routes each line to the right store and retention. Four: storage, in two tiers. The hot tier holds recent days and answers searches in seconds. It can be OpenSearch or Elasticsearch (a full-text index), Grafana Loki (a label index plus compressed chunks in object storage), or ClickHouse (a column store, which Uber moved to). The cold tier is compressed files in object storage such as S3, kept for months or years for audits and rare investigations, and loaded back only when needed. Five: query and alerts. Grafana or Kibana for search and dashboards, and alert rules that run on the stream or on the hot store, for example 'more than 100 ERROR lines a minute from checkout'. Every line carries a trace ID where possible, so an engineer can jump from a log line to the full trace of that request.
In a real interview, sketch this on the whiteboard before diving into any single box.
Follow one ERROR from the checkout service. This is a good order to explain it in an interview.
checkout writes one JSON line to standard output: time, level=ERROR, message 'payment timeout', order_id, trace_id. Writing to stdout is fast and never waits on the network.
Fluent Bit on the node reads the new line from the container's log file within a second, adds labels (service=checkout, pod, namespace, region) and puts it in a batch.
Every second or so, or when the batch is full, the agent compresses the batch and sends it to the Kafka topic for the payments team. If Kafka does not answer, the batch waits in the agent's disk buffer.
A consumer reads the batch, checks the JSON, masks anything that looks like a card number or password, keeps the ERROR line (errors are never sampled), and writes it to the hot store and to the archive stream.
The hot store adds the line to its index. In OpenSearch every word becomes searchable; in Loki only the labels are indexed and the text sits in a compressed chunk. Either way, it is searchable within about a minute.
An alert rule counts ERROR lines from checkout. The count crosses its limit, and the engineer on duty gets an alert on their phone, with a link to a saved search.
The engineer searches service=checkout, level=ERROR for the last 15 minutes, finds the line, and follows its trace_id to the trace, which shows the payment provider call that timed out.
Walk through each service. The interviewer wants to hear what each one owns, not just the names.
Fluent Bit, Vector, the OpenTelemetry Collector or Filebeat. Tails files or reads stdout, adds labels, batches, compresses, retries, and buffers to disk. It must use little CPU and memory, because it runs on every machine next to the apps.
Takes every line and keeps hours of history, so the rest of the pipeline can be slow, down or replayed without affecting the apps. Topics per team or log type let each have its own retention and consumers.
Stateless consumers that parse, enrich, mask secrets and personal data, sample, apply per-service quotas and route lines. They scale by adding consumers, up to one per partition.
Recent logs, searchable in seconds. A full-text index (OpenSearch, Elasticsearch), a label index with compressed chunks (Grafana Loki), or a column store (ClickHouse). The choice sets most of the cost.
Compressed files in object storage (S3, GCS, Azure Blob), partitioned by date and service. Cheap to keep for a year or more; slow to search, so data is loaded back only for audits or rare investigations.
Grafana or Kibana for search, saved queries and dashboards. Alert rules on error counts and patterns, with links back to the search and to traces.
log record (one line). This follows the OpenTelemetry logs data model, which names Timestamp, SeverityText and SeverityNumber, Body, Attributes, TraceId and SpanId. Keeping trace_id is what…
Every table for a distributed logging system, its keys, and which store fits it and why.
Structured logs and what every line should carry. Free text, such as 'Payment failed for order 812 after 2000ms', is easy to write and hard to use. To find all payment failures over 1 second, a machine has to guess…
8 deep dives on the parts that break at scale, with 3 diagrams: Structured logs and what every line should carry; Collecting logs from every machine without hurting the apps; Why Kafka sits in the middle.
Full-text index vs label index vs column store. A full-text index (OpenSearch) finds any word fast but pays heavily on every write and in disk. A label index (Loki) is cheap to write and store but slow for searches…
6 decisions an interviewer expects you to defend, each with the alternative and why it loses here.
During an incident, searches are slow and the newest logs are 20 minutes old. What is happening?
5 follow-up questions with model answers, the interview scorecard for this question, and a mock interview on Design a distributed logging system with the AI tutor.
Uber ran Elasticsearch-based logging from 2014, at 20+ clusters per region, and moved to ClickHouse in a schema-agnostic design, reporting 300,000 logs a second per node and hardware cost cut by more than half (2021). Grafana Loki indexes only labels and keeps log text in compressed chunks in object storage. Fluent Bit documents both memory and filesystem buffering and what happens at each limit. Kubernetes documents the node-level agent pattern, with containers writing to stdout and stderr. The OpenTelemetry logs data model gives a common shape for log records, including trace and span IDs.
If any of these topics are fuzzy, the interviewer will catch it. Each lesson is 15 to 60 minutes with diagrams, code, and a quiz.
Log Aggregation
intermediate / observability monitoring
Centralized Logging
intermediate / observability monitoring
Structured Logging
intermediate / observability monitoring
Log Management
intermediate / observability monitoring
Log Levels
intermediate / observability monitoring
Correlation IDs
intermediate / observability monitoring
ELK Stack
intermediate / observability monitoring
Fluentd
intermediate / observability monitoring
OpenTelemetry
intermediate / observability monitoring
Message Queues
intermediate / messaging event systems
Inverted Index
intermediate / database types storage
Tiered Storage
intermediate / database types storage
PII Handling
intermediate / data governance compliance
Backpressure
advanced / reliability resilience
interview readiness
Three questions from this guide. Answer them without scrolling up, the way you would have to in the room.
India: UPI, cards or netbanking through Razorpay. Elsewhere: card or PayPal. Download at once from My packs.
NEWSystem Design Hands-On
Postgres Sharding: Complete Hands-On (PgBouncer + Citus). 2 h 36 min and 20 chapters: one PostgreSQL loaded until it breaks, then four shards behind a router you write, PgBouncer and Citus, with the 139-page slide deck. The first 15 minutes are free to watch.
Free PDF · 79 pages
25 real tech interview questions, answered in full
Five from each of our AI, GenAI, Inference, Maths for ML and Forward Deployed packs. Each with a diagram and a model answer. Free by email.
It is really nice and good Please join the course