Skip to content
tezvyn:

Loki: The Log System That Indexes Labels, Not Text

Source: grafana.comHardHow cards are made

Loki: The Log System That Indexes Labels, Not Text

Loki is a log system that indexes only metadata labels, not the full log content. This makes it cheaper and simpler to run than full-text indexing systems, storing compressed logs in object storage.

Why it exists

Traditional logging systems index the full text of every log line. This creates a massive index that is expensive to store and complex to manage. Loki was created to provide a more cost-effective and operationally simple logging solution by challenging this core assumption.

The mental model

Loki's philosophy is "index metadata, not content." Think of it like the index at the back of a book. Instead of listing every word on every page (full-text search), it lists key topics (labels) and the page numbers where they appear (log stream pointers). This makes the index incredibly small and cheap to maintain, just like Prometheus does for metrics.

How it works

Loki is a set of components that separates log processing into two parts: the index and the data. When logs arrive, Loki extracts predefined labels (e.g., app="api", env="prod") and adds them to a small index. The raw log message itself is not indexed. Instead, it's compressed with other recent logs from the same stream and stored as a "chunk" in a low-cost object store like Amazon S3 or Google Cloud Storage. To query, you use LogQL to first select log streams using the indexed labels, and then Loki fetches the relevant chunks and searches the raw text within that smaller subset.

When to use it

Use Loki when your primary goal is cost-effective, large-scale log aggregation, especially in cloud-native environments using object storage. It excels when you can define a consistent, low-cardinality set of labels for your services and primarily need to query logs based on service, environment, or cluster. It's ideal for teams already familiar with the Prometheus and PromQL mental model.

When not to use it

Loki is not a good fit if your primary use case is exploratory full-text search across all logs without any prior filtering. If you frequently need to find a single log line based on a unique string without knowing which service it came from, a full-text indexing system is more appropriate. The system's performance depends on well-designed labels; if you cannot enforce good label hygiene, you will encounter performance issues.

One canonical example

A common setup involves using a client like Promtail to scrape log files. You configure it to attach labels like job="nginx" and cluster="us-east-1" to the logs. These are sent to Loki. An engineer can then use a LogQL query like {job="nginx", cluster="us-east-1"} in Grafana to see all NGINX logs from that cluster, without Loki ever having indexed the content of the access logs themselves.

Interview question

For which use case would Loki likely be a suboptimal choice compared to a traditional full-text indexing log system?

  • a.Aggregating logs from hundreds of microservices in a cost-effective manner.
  • b.Storing large volumes of compressed log data in cloud object storage for long-term retention.
  • c.Querying logs based on consistent, low-cardinality labels like service name or environment.
  • d.Performing exploratory searches for a unique error string across all logs without knowing its source.Correct
Why?

Loki's core design indexes only metadata labels, not full log content, making it inefficient for broad, exploratory full-text searches without prior label filtering. Its strength lies in cost-effective aggregation and querying via predefined labels.

Just read this? Test yourself on what you have been reading.

Read the original → grafana.com

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.

See open roles