Inside a logging service
medium 30 minA logging service carries the log lines of all programs to one place where people can search them.
When it comes up
The moments this idea belongs in a design interview, and the moments it does not.
Signals
When to bring it up
| You hear | Say | Because |
|---|---|---|
| Design a logging system | Pipeline with a queue in the middle | Bursts and outages |
| Hundreds of services | Trace id from the entrance | Join lines of one request |
| Search in a second | Inverted index, split by time | Touch little data |
| Keep for seven years | Tiers and object storage | Cost |
| Must not lose audit data | At least once, confirmed on disk | Audit differs from debug |
Saying it in the room
Interviewer
Design a service that stores the logs of all our programs.
You
How many lines, how fresh, how long kept? Let me assume 100,000 a second of 500 bytes. That is 4.3 terabytes a day.
Interviewer
Fine. Why not write directly into the index?
You
Because the index is slowest when things break. A queue in between holds 180 gigabytes for each hour of trouble, before replication, and the programs never notice.
Interviewer
What if the queue is full too?
You
Then the agent keeps lines on its disk and drops debug first. I count what was dropped. Audit lines have a path of their own.
Options
Compare your moves
How do lines get from a program to the store?
BreaksEach request writes to the index and waits
- How
- One network call per line.
- Limit
- A slow index makes every request slow. An outage stops the shop.
- Choose when
- Never for normal logs.
WorksAgent sends straight to the index
- How
- Batches from a local file.
- Limit
- A long outage fills local disks, and bursts hit the index directly.
- Choose when
- Small systems.
StrongLocal file, agent, queue, processors, index
- How
- Each stage confirms, batches and can be late. Dropping follows a rule.
- Limit
- More parts to run and to watch.
- Choose when
- Many services or high volume.