Part 4: Loki's Secret: Why It's So Cheap to Run
Observability Series - Part 5 of 5

Inside Promtail's Brain (And the "Negative Compression" Trap)

• 7 min read • Observability
Promtail Loki Networking Alloy

TL;DR

Promtail is the unsung hero of the logging stack. It reads your files and pushes them over the network. But how does it survive a Loki outage, and when does it actually lose data? And why do tiny logs sometimes take up MORE network space than they did on disk? We strip away the noise to see exactly what Promtail is doing.

A note on Promtail: Promtail reached end-of-life on March 2, 2026, and Grafana AlloyGrafana's current telemetry collector and the official replacement for Promtail. It can collect logs, metrics, and traces with one agent. is its replacement. Everything in this post (the positions file, batching, the overhead trap) applies to Alloy's loki.source.file and loki.write components too, just with different config syntax.

We've covered the databases (Prometheus and Loki), but databases are useless without data. That data is delivered by Promtail, the agentA lightweight program that runs in the background of a server, collecting data and sending it to a larger, centralized system. installed directly on your production server alongside your application.

Promtail tails your physical log files, packages them up, and fires them across the network via HTTP POST requests.

1. The positions.yaml Bookmark

What happens if your Loki server reboots and goes offline for 10 minutes? Promtail is trying to send logs, but getting connection errors. Where does it store the unsent logs while it waits?

Mostly, it doesn't. By default, Promtail has no database or Write-Ahead Log of its own (newer versions added an optional, experimental one).

Instead, it uses a lightweight trick: it uses your actual log files as the buffer. Promtail maintains a tiny file on your server called positions.yaml. It is quite literally a bookmark. It looks like this:

positions:
  /var/log/django/app_log.log: "31726866"

That number is a Byte OffsetA position within a file, measured by counting the exact number of bytes from the very beginning of the file.. It means, "I have read the first 31,726,866 bytes of this file." Promtail saves this bookmark every 10 seconds, so after a restart it picks up where it left off instead of re-reading the whole file.

When Loki goes down, Promtail holds on to the batch it was trying to send and retries it with increasing delays. While it's stuck retrying, it stops reading new lines. Your Django app keeps writing logs, so the file grows, and the unread part of the file becomes the backlog. When Loki comes back, Promtail sends the stuck batch, then reads the backlog from its bookmark and catches up.

But the safety net has holes:

  • Retries run out. With the default backoff settings (10 retries, waiting up to 5 minutes between them), Promtail gives up after roughly 8–9 minutes and drops the batch it was holding. A 10-minute outage can cost you that batch. Raise max_retries in backoff_config if your Loki outages tend to run long.
  • Files disappear. If log rotation deletes or compresses a file before Promtail has read it, those lines are gone.
  • Crashes can duplicate. Because the bookmark is only saved every 10 seconds, a Promtail crash can cause a few lines to be sent twice.

So the file-as-buffer trick is very good, but "can never lose data" would be overselling it.

2. The Negative Compression Trap

Promtail saves network bandwidth by compressing each batch of logs with the SnappyA compression algorithm developed by Google. Unlike ZIP, which aims for the smallest possible files, Snappy prioritizes raw speed. algorithm before sending it. But sometimes, a strange thing happens: Payload Inflation (or Negative Compression).

If you check Prometheus, you might see that Promtail read 100 bytes of logs from your disk but sent 200 bytes over the network!

This is the Envelope vs. The Letter problem again. Every push is wrapped in a ProtobufProtocol Buffers: a compact binary format from Google for sending structured data between programs. Smaller and faster to parse than JSON. API payloadThe actual data being transmitted in an API call, excluding the lower-level network headers (like IP addresses or routing data).. Each log line carries its own timestamp, and each stream in the batch carries its full set of labels, plus some structural formatting. If your application only writes a few extremely short lines (e.g., [INFO] OK) per second, each batch holds just a handful of lines, and the envelope is heavier than the letters inside it. On top of that, compression can't do much with a few short lines; it needs repetition to work with.

The fix is to make Promtail more patient, so each batch carries more letters per envelope. Promtail sends a batch when either of two limits is hit: a time limit (batchwait, default 1s) or a size limit (batchsize, default 1 MiB). On a quiet server, the 1-second timer always fires first. So raise the timer:

clients:
  - url: http://localhost:3100/loki/api/v1/push
    batchwait: 10s      # Wait up to 10 seconds (default: 1s)
    batchsize: 1048576  # ...or until 1 MiB is collected (the default)

By grouping more logs into each batch, the label overhead is shared across many lines, and the compression algorithm finally has enough text to squeeze. The trade-off is latency: logs show up in Grafana up to 10 seconds later. Rerun the compression-ratio query from Part 1 before and after to see the difference.

3. Seeing the API Calls (Filtering the Noise)

If you turn on Promtail's debug logging (-log.level=debug) to see if it's working, your terminal fills with text: details about every file it watches, every target it discovers, and every pipeline stage it runs.

If your app generates 1,000 logs a second, the terminal scrolls so fast you can't see the actual network pushes.

To find the network activity, pipe the logs through a grep filter:

journalctl -u promtail -f | grep -iE "flush|batch|push"

The terminal now stays quiet until a line about batching or pushing appears, and failed pushes (like error sending batch, will retry) jump right out. The exact wording of these messages varies between Promtail versions, so adjust the filter words if needed.

For proof that pushes are succeeding, the most reliable source is Promtail's own metrics:

curl -s localhost:9080/metrics | grep promtail_request_duration_seconds_count

Each successful push shows up with status_code="204" (Loki's "accepted" response). Run it twice, a few seconds apart, and watch the count climb: that's one tick for every envelope the mail carrier delivers.

You've officially watched the mail carrier deliver the envelope.

4. Wrapping Up the Series

Over five posts, we've followed data through the whole stack:

  • Part 1: Prometheus and Loki are separate databases. Grafana just shows them side by side.
  • Part 2: Prometheus keeps recent data in RAM, protects it with a WAL, and squeezes it with Gorilla compression.
  • Part 3: Heavy queries can OOM-kill Prometheus, and flags like --query.max-samples are your guardrails.
  • Part 4: Loki stays cheap by indexing only labels, and deletes old logs on a deliberate delay.
  • Part 5: Promtail uses your log files as its buffer, and batching keeps its envelopes efficient.

The common thread: each tool is fast because it refuses to do something. Prometheus refuses to store text, Loki refuses to index it, and Promtail refuses to keep its own copy. Once you know what each tool refuses to do, its limits stop being surprises.

That's the end of the series.

Thanks for reading all five parts! New here? Start from the beginning.

Part 1: The Grand Illusion