Grafana Loki
Grafana Loki is a system for storing application and infrastructure logs in one place. It lets you narrow logs down by source and time, then search the matching entries for errors or other events.
Also known as: Loki
What Loki does
A checkout service starts throwing errors after a deployment. Its replicas run on several machines, and the failing requests didn't all land on the same replica. Instead of opening each machine's log files, the on-call engineer can look at the service's logs together and zoom in on the minutes after the rollout. Loki is the backend that stores those logs and answers queries. Grafana is a separate tool that can display the results in Explore or on a dashboard.
How Loki stores and finds logs
A collector such as Grafana Alloy reads logs from sources such as containers or files and ships the entries to Loki with labels. A label is a key-value pair, such as environment="production". Entries with the same complete set of labels belong to the same stream. Loki batches a stream's entries into compressed chunks. Production deployments commonly use object storage such as Amazon S3 for the chunks and index.
Loki indexes stream labels rather than building a full-text index of every log line. It uses the label selector and time range to locate relevant chunks, then reads those chunks to apply content filters. That's the core trade-off: the index doesn't have to track words from every message, but a search across lots of services and a long time range can still be expensive, even if it returns only one line.
A LogQL query in practice
Suppose a dashboard shows that the checkout error rate jumped around 14:10. Set a narrow time range around the spike in Grafana Explore and run:
{service="checkout", environment="production"} |= "payment timeout"
The selector inside the braces picks the production checkout streams. The |= filter keeps only lines containing the literal text payment timeout. LogQL can also parse JSON fields or count matching entries over time. That count can feed a dashboard or an alert, but it measures log entries, not failed requests: a single request can produce several messages.
Where teams use it and what to watch for
Loki is useful for incident investigation, rollout checks, and debugging background jobs. It often sits alongside Prometheus: metrics show when an error rate changed, while logs provide context about individual events.
The common configuration mistake is using a request or trace ID as an indexed label. A different ID for each request creates a large number of distinct label combinations, a problem known as high cardinality. That leads to many tiny streams and adds work during ingestion and querying. Keep per-request IDs in the log body or attach them as structured metadata instead. Use labels for the dimensions you filter on often and that have a bounded set of values, such as service and environment.
How it comes up in interviews
An interviewer might ask you to choose labels for a Kubernetes logging setup or explain why a query for an error message is slow. Explain how labels determine the number of streams and why a selective label filter plus a narrow time range cuts down the amount of log data Loki has to read.