<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Neha</title>
    <description>The latest articles on DEV Community by Neha (@neha130).</description>
    <link>https://dev.to/neha130</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4259030%2Fb820faf4-bd75-400d-9f84-4f2c24054213.jpg</url>
      <title>DEV Community: Neha</title>
      <link>https://dev.to/neha130</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/neha130"/>
    <language>en</language>
    <item>
      <title>Understanding Grafana Loki Architecture: Components, Design, and How They Work Together</title>
      <dc:creator>Neha</dc:creator>
      <pubDate>Tue, 24 Nov 2026 07:09:06 +0000</pubDate>
      <link>https://dev.to/neha130/understanding-grafana-loki-architecture-components-design-and-how-they-work-together-2j50</link>
      <guid>https://dev.to/neha130/understanding-grafana-loki-architecture-components-design-and-how-they-work-together-2j50</guid>
      <description>&lt;h2&gt;
  
  
  1. Introduction: What Is Grafana Loki?
&lt;/h2&gt;

&lt;p&gt;It's 2 a.m. and checkout latency is spiking. The failing requests cross a dozen services on hundreds of pods, and half the pods that mattered were rescheduled an hour ago. &lt;code&gt;kubectl logs&lt;/code&gt; shows one pod at a time, and nothing from pods that are gone. Centralized logging exists for this moment.&lt;/p&gt;

&lt;p&gt;Traditional platforms index the full text of every log line. Search is flexible, but the index grows with log volume, and so does the cost. Grafana Loki, a horizontally scalable, multi-tenant log aggregation system inspired by Prometheus, indexes only a small set of labels per stream and stores the log lines as compressed chunks in object storage.&lt;/p&gt;

&lt;p&gt;In the Grafana ecosystem, Prometheus or Mimir holds metrics, Loki holds logs, and Grafana ties them together through shared labels. A typical stack has an agent such as Grafana Alloy that labels and pushes logs, Loki itself, and Grafana for querying.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Why Loki? The Design Philosophy
&lt;/h2&gt;

&lt;p&gt;Loki's architecture follows from a few decisions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Label-based indexing.&lt;/strong&gt; Loki indexes metadata, not content. Labels like &lt;code&gt;{namespace="payments", app="checkout"}&lt;/code&gt; identify a stream, and the index maps label sets to chunks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Streams and chunks.&lt;/strong&gt; A stream is all log lines sharing one tenant and label set. Each stream's lines are compressed into chunks, and a query decompresses only the chunks it needs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Separate index and data.&lt;/strong&gt; A small index and bulky chunks are stored and scaled independently.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Object storage as the durable layer.&lt;/strong&gt; Chunks and index files live in S3, GCS, Azure Blob or similar.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The trade-off is that queries select streams by label first, then filter line content at query time. Elasticsearch chooses the opposite:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Loki&lt;/th&gt;
&lt;th&gt;Elasticsearch&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;What is indexed&lt;/td&gt;
&lt;td&gt;Labels per stream&lt;/td&gt;
&lt;td&gt;Log content (inverted index)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Index size&lt;/td&gt;
&lt;td&gt;Small&lt;/td&gt;
&lt;td&gt;Grows with log volume&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Primary storage&lt;/td&gt;
&lt;td&gt;Object storage&lt;/td&gt;
&lt;td&gt;Mostly node-local disks&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Query model&lt;/td&gt;
&lt;td&gt;Pick streams, then filter lines&lt;/td&gt;
&lt;td&gt;Search the index&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Strength&lt;/td&gt;
&lt;td&gt;Cost-efficient, Kubernetes-native logs&lt;/td&gt;
&lt;td&gt;Ad-hoc full-text search and analytics&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  3. Grafana Loki High-Level Architecture
&lt;/h2&gt;

&lt;p&gt;Loki compiles every component into one binary, and the &lt;code&gt;-target&lt;/code&gt; flag decides which ones a process runs. Optional components are marked in the diagram.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart LR
    AG[Agent&amp;lt;br/&amp;gt;Grafana Alloy]
    GR[Grafana]
    GW[Gateway&amp;lt;br/&amp;gt;reverse proxy]
    subgraph WP[Write path]
        D[Distributor]
        I[Ingester&amp;lt;br/&amp;gt;with WAL]
    end
    subgraph RP[Read path]
        QF[Query Frontend&amp;lt;br/&amp;gt;optional]
        QS[Query Scheduler&amp;lt;br/&amp;gt;optional]
        Q[Querier]
        IG[Index Gateway]
    end
    subgraph BG[Background services]
        C[Compactor]
        R[Ruler]
    end
    OS[(Object Storage&amp;lt;br/&amp;gt;chunks and index files)]
    AG --&amp;gt;|push| GW
    GR --&amp;gt;|query| GW
    GW --&amp;gt; D
    GW --&amp;gt; QF
    D --&amp;gt;|replicated writes| I
    I --&amp;gt;|flush| OS
    QF --&amp;gt; QS
    QS --&amp;gt; Q
    Q --&amp;gt;|recent data| I
    Q --&amp;gt;|chunk refs| IG
    IG --&amp;gt; OS
    Q --&amp;gt;|chunks| OS
    C --&amp;gt;|compaction and retention| OS
    R --&amp;gt;|reads rules| OS
    R -.-&amp;gt;|optional remote evaluation| QF&lt;/code&gt;&lt;/pre&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Gateway.&lt;/strong&gt; Not a Loki target but a reverse proxy in front of it; the Helm chart ships an NGINX that routes pushes and queries to the right components. Talks to: agents, Grafana, distributors, query frontend.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Distributor.&lt;/strong&gt; Stateless entry point of the write path. Validates streams, enforces per-tenant rate limits, then hashes each stream onto the ring to pick its ingesters. Talks to: ingesters.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ingester.&lt;/strong&gt; Stateful. Builds chunks in memory, protects them with a WAL, flushes to object storage, and serves recent data to queriers. Talks to: object storage, queriers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Query Frontend&lt;/strong&gt; (optional). Splits large queries, caches results and queues work. Queriers pull sub-queries from it. Talks to: query scheduler, queriers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Query Scheduler&lt;/strong&gt; (optional). Per-tenant queues for fairer scheduling than the frontend's basic queue. Talks to: query frontend, queriers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Querier.&lt;/strong&gt; Executes LogQL against ingesters (recent data) and object storage (the rest), deduplicating replicated results. Talks to: ingesters, index gateway, object storage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Index Gateway.&lt;/strong&gt; Serves index lookups for shipper stores such as TSDB, so queriers get chunk references without holding the index themselves. Talks to: object storage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compactor.&lt;/strong&gt; Merges shipped index files into one per day and tenant, and enforces retention and deletion. Usually a single instance. Talks to: object storage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ruler.&lt;/strong&gt; Evaluates alerting and recording rules stored in object storage, and can delegate evaluation to the query frontend.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Object storage.&lt;/strong&gt; Not a Loki process, but the single long-term home for chunks and index files.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. How Loki Components Work Together
&lt;/h2&gt;

&lt;p&gt;Two paths cover almost everything Loki does.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Write path.&lt;/strong&gt; The agent pushes labeled streams to the gateway, which routes them to a distributor. The distributor validates and hashes each stream, then sends it to the configured number of ingesters (the replication factor, typically 3) and waits for a quorum of acknowledgments. Ingesters batch lines into chunks and flush them to object storage later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Read path.&lt;/strong&gt; Grafana sends a LogQL query through the gateway to the query frontend, which splits it into sub-queries, via the query scheduler if one is deployed. Queriers pull the sub-queries, check ingesters for recent data, read the rest from object storage, and the frontend merges the results.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart TB
    subgraph W[Write path]
        direction LR
        A1[Agent] --&amp;gt; G1[Gateway] --&amp;gt; D1[Distributor] --&amp;gt; I1[Ingester] --&amp;gt; S1[(Object storage)]
    end
    subgraph R[Read path]
        direction LR
        U[Grafana] --&amp;gt; G2[Gateway] --&amp;gt; F[Query Frontend and Scheduler] --&amp;gt; Q2[Querier&amp;lt;br/&amp;gt;asks Ingesters too] --&amp;gt; S2[(Index and object storage)]
    end&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The internals of both paths are the subject of the next two articles.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Loki Deployment Modes
&lt;/h2&gt;

&lt;p&gt;Because every component ships in one binary, a deployment mode is just a choice of which &lt;code&gt;-target&lt;/code&gt; each process runs. One caveat for anyone planning a new cluster: &lt;strong&gt;Simple Scalable Deployment (SSD) is deprecated and will be removed in Loki 4.0.&lt;/strong&gt; Grafana points SSD users to microservices or HA monolithic mode.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Monolithic&lt;/th&gt;
&lt;th&gt;Simple Scalable (SSD)&lt;/th&gt;
&lt;th&gt;Microservices&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Layout&lt;/td&gt;
&lt;td&gt;All components in one process (&lt;code&gt;-target=all&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;Three targets: &lt;code&gt;write&lt;/code&gt; (distributor, ingester), &lt;code&gt;read&lt;/code&gt; (query frontend, querier), &lt;code&gt;backend&lt;/code&gt; (compactor, index gateway, query scheduler, ruler)&lt;/td&gt;
&lt;td&gt;One process per component&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scale&lt;/td&gt;
&lt;td&gt;About 20 GB/day; HA via two instances, shared object storage, replication factor 3&lt;/td&gt;
&lt;td&gt;Close to 1 TB/day; read and write scale independently&lt;/td&gt;
&lt;td&gt;Very large clusters; every component scales on its own&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Strengths&lt;/td&gt;
&lt;td&gt;Simplest to run&lt;/td&gt;
&lt;td&gt;Easy to scale; Helm chart default at the time of writing; needs a reverse proxy&lt;/td&gt;
&lt;td&gt;Most control and efficiency; designed for Kubernetes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Limits&lt;/td&gt;
&lt;td&gt;Scaling out is limited&lt;/td&gt;
&lt;td&gt;Deprecated, so plan a migration&lt;/td&gt;
&lt;td&gt;Most complex to set up and operate&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Typical use&lt;/td&gt;
&lt;td&gt;Evaluation, small volumes&lt;/td&gt;
&lt;td&gt;Existing mid-size installs&lt;/td&gt;
&lt;td&gt;Very large clusters needing fine-grained scaling&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Component lists change between versions, so run Loki with &lt;code&gt;-list-targets&lt;/code&gt; to see yours.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Key Architectural Concepts
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Labels and streams.&lt;/strong&gt; Labels identify a stream. Keep them low-cardinality: every unique combination creates another stream and grows the index.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chunks.&lt;/strong&gt; Compressed containers of one stream's lines for a time range, flushed to object storage when full, idle, or on a flush.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Index.&lt;/strong&gt; A table of contents mapping label sets to chunks. TSDB is the recommended format, shipped to object storage like chunks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Object storage.&lt;/strong&gt; The single durable backend for chunks and index files, which keeps long-term durability out of Loki's own nodes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hash ring.&lt;/strong&gt; A consistent-hashing ring, shared via memberlist or a key-value store such as Consul, that maps each stream to its ingesters.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Replication.&lt;/strong&gt; Each stream is written to several ingesters and needs a quorum of acknowledgments, so rollouts and restarts don't fail writes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;WAL.&lt;/strong&gt; Ingesters persist incoming writes to disk and replay them after a crash. Replication and the WAL complement each other: data is lost only if both fail.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  7. Conclusion
&lt;/h2&gt;

&lt;p&gt;Loki makes a deliberate trade: index only labels, keep log lines in compressed chunks on object storage, and put most of the work in stateless services (distributors, queriers, frontends) around a small stateful core, chiefly the ingesters. That is why it costs less to run than systems that index full content, and why label design matters so much.&lt;/p&gt;

&lt;p&gt;The write path accepts and buffers data, the read path fans out and merges queries, and background services keep the index tidy and alerts firing. A deployment mode only decides how these pieces are packaged.&lt;/p&gt;

&lt;p&gt;In the next article, we will explore how Grafana Loki handles log ingestion internally, following the complete journey of logs from applications and Grafana Alloy through the Distributor and Ingester into long-term storage.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://grafana.com/docs/loki/latest/get-started/overview/" rel="noopener noreferrer"&gt;Loki overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://grafana.com/docs/loki/latest/get-started/architecture/" rel="noopener noreferrer"&gt;Loki architecture&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://grafana.com/docs/loki/latest/get-started/components/" rel="noopener noreferrer"&gt;Loki components&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://grafana.com/docs/loki/latest/get-started/deployment-modes/" rel="noopener noreferrer"&gt;Loki deployment modes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>observability</category>
      <category>devops</category>
      <category>kubernetes</category>
      <category>grafana</category>
    </item>
  </channel>
</rss>
