ELK Stack
medium 30 minThe ELK Stack is Elasticsearch, Logstash and Kibana: a place to collect, clean, store and search logs from many machines.
See it run
A log line from a file to a chart, what happens in a crash, and how old data leaves.
Operations
One log line
The payment service logs an error. Follow the line until someone sees it.
Step 1 of 6
Written to a file
request not slowed
The app writes the line and goes on. It does not wait for anything.
Step 1: Written to a file
def one_line(line): batch = shipper.read(line) event = logstash.filter(batch) elasticsearch.bulk("logs-pay-prod", event) wait_for_refresh() return kibana.search("log.level : error")- Delay
- Seconds
- Where it waits
- File, queue, index
Say where the line waits at each step. That shows you know what can be lost.
In the real world
The same elk stack doing real jobs. Pick one and step through it.
A noisy service fills the disk of one node.
Step 1 of 4
85 percent
- Disk
- 85%
low mark
No new shards are placed on this node.
Step 1: 85 percent
Common mistakes
The bugs interviewers watch for, with the fix beside each.
Logging straight to the cluster
criticalA slow Elasticsearch then slows every user request.
Wronges.index(index="logs", document=line)Rightprint(json.dumps(line)) # the shipper does the restIds as field names
criticalEach id becomes a field until the limit of 1,000 refuses documents.
Wrong{"users": {"4711": "ok"}}Right{"user.id": "4711", "status": "ok"}Deleting documents by age
majorDeleted documents stay on disk until merges, and the cluster works hard.
WrongPOST logs-*/_delete_by_queryRight"delete": { "min_age": "30d", "actions": { "delete": {} } }One shard for each service and hour
majorEvery shard costs memory, and a search uses a thread for each.
Wronglogs-pay-2026.11.23-10Rightlogs-pay-prod # rolls over by sizeChanging the filestream id
minorThe state is lost and files are read again from the start.
Wrongid: checkout-log-v2Rightid: checkout-log # never change
Interview tips
How to explain it
- A shipper with a notebook.
- Parsing into fields.
- A search engine, and a screen.
Where data can wait
- In the log files.
- In the Logstash queue.
- In Kafka, replicated.
Reach for it when
- Logs come from many machines.
- People search by any field.
- You can run a cluster or pay for one.
Do not use it for
- Alerting on simple rates.
- Records that must be exact.
- Secrets and personal data.