Loki compactor operations and horizontal scaling

The Loki compactor compacts the index, applies retention and processes deletes. This page explains why it runs as a singleton, how to operate it safely and what the experimental horizontal scaling mode changes for heavy line-filter deletions.

On this page

What the Loki compactor does and why teams need it running correctly

The Loki compactor compacts the index, applies retention and processes deletes, so if your self-hosted cluster needs logs removed on schedule or on request, this component is what does the work. Retention is disabled by default, which means Loki keeps logs indefinitely until you deliberately enable retention on the compactor. Storage in Loki is split between compressed log chunks and an index, both held in object storage, and the compactor is the process that keeps that index compact and enforces the rules you set for how long data lives.

Teams that need the compactor configured on purpose include anyone with a retention requirement from a security, privacy or audit framework, anyone who may have to remove log lines after secrets or personal data were written, and any operator running multiple tenants whose retention periods differ. Platform teams should also treat it as a shared dependency: the compactor sits alongside the ingesters, queriers and the object store, and a retention or delete setting that looks correct in configuration can still leave data in place if the compactor is not running, is not reaching the bucket, or is working through a backlog. Confirm the exact retention and delete settings for your Loki version against the Loki retention documentation before you rely on them.

Before enabling anything, decide who owns the compactor, where it runs in your deployment mode, and how you will prove that data is actually removed. Ask your team to confirm which Loki version you run, since the Loki releases page lists the current release line, and to check whether your deployment mode is one the documentation still supports for the long term. Plan an explicit check that compaction and retention are progressing, because a compactor that silently falls behind will keep storage growing without any error at the query layer.

How the compactor sits between the index, object storage and the delete API

The diagram starts with log writes landing in object storage alongside the index. The singleton compactor main reads that index and rewrites it, and it is also where retention is applied. Delete requests enter through the API and are recorded for the compactor to process later. The experimental mode adds optional worker instances that take on line-filter deletions while the main stays in charge. When you review it, confirm which instance runs the main and that only one does so in your deployment.

Compactor main and optional workers acting on the index and object storage.

Why the compactor runs as a singleton by default

The compactor owns index compaction, retention and delete processing, and each of those jobs changes shared state. Running one authoritative instance keeps that state coherent, at the cost of a single component to size, monitor and recover. The cards below cover the reasons behind that default and what to check before changing it.

One writer for compacted index files

Compaction merges many small index files into fewer larger ones in object storage. If two instances compacted the same index period at once, they could write conflicting versions of the same files and leave queries reading an inconsistent index. A single compactor avoids that race by design. Check how your Loki version describes compactor replicas before you add any, and confirm that your deployment does not run more than one compactor by accident, for example through a misconfigured replica count.

Loki storage docs

One authority over retention markers

Retention works by marking chunks and index entries as expired and then sweeping them. The marker state must be written by one process so that a chunk is not marked by one instance and skipped by another. A single compactor keeps that marker state in one place. The trade-off is that marker progress depends on one process, so monitor whether retention is still advancing, not only whether the process is running.

Ordered processing of delete requests

Delete requests must be applied in a defined order, and each must be checked against the data it targets. A single coordinator makes that order easy to reason about and easy to audit when someone asks what was removed and when. Before you submit large or repeated deletes, confirm how your version handles queued requests and cancellation, and whether any deletes are still pending during an incident review.

Simpler recovery after failure

When the single compactor stops, the work it was doing is interrupted, and you restart one process rather than reconciling several. Recovery is simpler because there is one working directory, one set of state and one log stream to read. The cost is that an outage of this process pauses compaction and retention until it returns, so plan alerting on the compactor's own health and a restart procedure your on-call team has rehearsed.

Shared working storage and disk

The compactor needs local disk to stage index files while it works, and that disk belongs to the one instance that runs the job. Sizing that volume for the largest index period you expect is a decision you make once for a singleton. Ask your team to confirm the working directory location and free space in your environment, and to set an alert before the volume fills, since a full disk stops compaction without changing the data already stored.

Horizontal scaling as a separate decision

Scaling out the compactor is a different question from running it as a singleton. The horizontally scalable mode is documented as experimental and targets line-filter deletions, which are the most operationally intensive compactor task. Keep the singleton default unless your deletion workload justifies the experiment, and confirm the current guidance for your exact version in the official documentation before making that change.

Compactor scaling docs

Compactor settings and when each fits

This table lists the compactor decisions a team must settle before running Loki in production, with what each controls, when it fits and what to confirm. Read each row against the configuration reference for your Loki version, because defaults and key names change between releases. The main takeaway is that retention and deletes stay off or unused until someone deliberately enables them, so each choice needs an owner.

SettingWhat it controlsWhen it fits and what to confirm
Retention enablementWhether the compactor removes chunks older than the configured retention period at all, since retention is off until it is explicitly enabledEnable only after the retention periods are agreed with compliance owners. Confirm the key name and default for your version in the configuration reference.
Retention scope: globalOne retention period applied to every tenant and stream unless a narrower rule overrides itFits single-team clusters or a simple baseline. Confirm that the period matches the shortest legal or policy requirement you must meet across all data.
Retention scope: per tenantSeparate retention periods for each tenant ID, set through per-tenant limitsFits multi-team or multi-customer clusters with different obligations. Confirm how overrides are loaded and whether changes need a restart or reload.
Retention scope: per stream selectorRetention rules that match streams by label selector, with each rule at least 24 hoursFits data with its own schedule, such as audit or security streams. Confirm selector syntax and rule precedence, and test each rule against sample streams.
Delete request handlingWhether the compactor accepts and processes delete requests for specific streams, time windows and line filtersNeeded when logs containing secrets or personal data must be removed. Confirm the delete API is enabled, who may submit requests and the cancellation window for your version.
Delete request processingHow and when accepted deletes are applied to stored chunks and the indexPlan for the work involved in rewriting data. Confirm the processing interval and whether deletes can run while queries and ingestion continue on your storage.
Compaction and retention intervalHow often the compactor compacts the index and runs retention sweepsSet it with the volume of new index files and the retention workload in mind. Confirm the key names and defaults in the configuration reference and monitor sweep duration after changes.
Horizontal scaling modeWhether the compactor runs as a singleton or distributes line-filter deletion work to worker instancesExperimental. Consider it only when line-filter deletions are heavy and you can accept an unstable feature. Confirm the supported version, configuration and rollback path before enabling it.

Singleton compactor or experimental horizontal scaling

For most Loki clusters, one compactor instance is the right choice. It builds and merges the index, applies retention and processes delete requests, and it runs as a single process because these jobs must not run concurrently against the same index. The singleton is not a sizing shortcut. Its schedules (compaction, retention and delete processing) are predictable, and the operating model is the one the documentation describes in full, so troubleshooting and upgrades follow known paths.

  • Single writer for the index: only one compactor should own index compaction and retention at a time, which keeps the index consistent.
  • Standard supported path: the documented configuration and the upgrade guidance assume this mode.
  • Restart tolerance: plan for the compactor to restart during maintenance and confirm that a delayed run completes on the next cycle.
  • Capacity planning: size the instance's disk and memory for index work, and watch its run duration as data grows.
  • Monitoring: alert on failed or stalled compaction and retention runs, since retention is disabled by default and silent failures leave data longer than intended.

Before you go live, confirm the retention settings, the delete API behavior and the schedules against your own data volume in a non-production environment.

How to set up the compactor and verify its schedule

This sequence takes a self-hosted Loki cluster from a confirmed object store and index setup to a compactor that runs retention and delete processing on a known schedule. Each step ends with a check you can record before moving on.

  1. Confirm the storage backend and index store

    Before touching the compactor, confirm that Loki writes chunks and its index to object storage and that the active schema period uses the TSDB index store. Check the schema_config and storage_config sections in the Loki configuration your team is running, and confirm the object store is one the Loki storage documentation lists for production, such as Amazon S3, Google Cloud Storage or Azure Blob Storage. The step is done when you can point to the store type and index store in the running configuration and the object store has a bucket or container that the Loki process can read and write. Ask your platform or storage team to confirm any S3-compatible or on-premises store against the storage documentation before you rely on it.

  2. Configure the compactor working directory

    Add a compactor block to the Loki configuration and set working_directory to a path on persistent disk that survives pod or process restarts. The compactor downloads and rebuilds index files there while it works, so an ephemeral path forces repeated full downloads and slows every cycle. Set compaction_interval only to a value your team has reviewed against the Loki compactor documentation, and do not carry over values from other clusters without checking them. The step is done when the compactor starts without configuration errors and the working directory exists, is writable by the Loki user and is backed by a volume your team can size and monitor.

  3. Enable retention deliberately

    Retention is disabled by default, so Loki keeps logs indefinitely until you set retention_enabled to true in the compactor configuration. Decide the retention periods with the owners of each tenant or log source before you enable it, because the compactor will delete data past the period it applies. Record the global retention_period and any per-tenant or per-stream overrides in a change record, and confirm that each stream rule is at least 24 hours. The step is done when the change record names every retention rule and an approver has signed off on the values in the running configuration.

  4. Set delete request handling

    Deletion through the compactor's delete API is controlled separately from retention. Decide who is allowed to submit delete requests, how requests are reviewed and what cancellation window applies to them, then set the matching delete-related keys in the compactor block, such as delete_request_store and the delete mode your team has chosen. Confirm the exact key names against the current Loki compactor documentation for your version, because they change between releases. The step is done when a test request is accepted or rejected as your access process expects, and the team knows how to cancel a pending request during the cancellation period.

  5. Confirm one main compactor is running

    The compactor runs as a singleton in the standard deployment, so only one instance should perform compaction, retention and delete processing at a time. In Kubernetes, run it as a single replica with a deployment or stateful set strategy that prevents overlap during rollouts. Check the process list, pod list or service inventory and confirm that exactly one compactor instance is active. If you are considering the experimental horizontally scalable mode, treat that as a separate decision and read its documentation before changing replica counts. The step is done when a single compactor instance is confirmed as the owner of these tasks and the rollout behavior has been tested.

  6. Verify compaction and retention cycles with logs

    After a restart, read the compactor logs and confirm that it starts a compaction pass, reports the index tables it processes and completes the pass without repeated errors. When retention is enabled, look for log lines showing that the retention pass ran and which tenants or streams it evaluated. Compare the first pass against a known sample stream that should be older than its retention period. The step is done when you have a dated log excerpt for at least one completed compaction pass and one completed retention pass, and any warnings are understood and recorded.

  7. Verify cycles with metrics and an alert

    Scrape the compactor's metrics endpoint with your monitoring stack and chart the metrics that show compaction and retention runs and their outcomes. Confirm the metric names in the Loki monitoring documentation for your version, then build a panel for each run and an alert for a run that stops completing or repeatedly fails. Also watch the working directory volume for growth, since a full disk stops the compactor. The step is done when the dashboard shows recent successful runs, the alert has been tested with a deliberate failure in a non-production environment, and the on-call owner knows the expected run cadence.

How retention and line-filter deletes behave in production

Retention and deletion both run inside the compactor, so their timing and load are set by the compactor's schedules rather than by the moment a setting is changed. Retention is disabled by default, which means logs are kept indefinitely until retention_enabled is turned on. Once it is on, the compactor applies the configured periods on its own cycle, and data outside those periods is removed during a later run, not at the instant a rule is written. Delete requests follow a separate path: the compactor accepts them through its delete API, records them, and processes them on its own schedule. Expect a lag between requesting a delete and seeing the data disappear from query results, and confirm the cycle and cancellation settings for your Loki version in the compactor documentation before relying on either timing.

Line-filter deletes are the most resource-intensive case the compactor handles. A line filter forces the compactor to read and rewrite the affected chunks to remove matching lines, so the work scales with the volume of data inside the selected streams and time window, not with the number of requests. During a heavy delete, watch compactor CPU, memory, disk and object store request rates, and check that ingestion and queries on the same storage are not slowing down. Also watch for requests that stay pending for longer than you planned, and for the compactor restarting while it works through a large backlog. Because the compactor is a singleton, one slow delete delays the other compactor work behind it.

Plan a maintenance window for any delete large enough to load the compactor, and agree its start, end and rollback path with the teams that query the affected streams. Before running a delete in production, rehearse the same selector, time window and line filter on a non-production copy of the data, measure how long it takes and what load it creates, and confirm the result with a query that shows the matching lines are gone. Record the exact request, who approved it and the verification output, since these are the artifacts a compliance reviewer will ask for. The horizontally scalable compactor mode, described in the preceding section, is experimental and should not be the only plan for a large line-filter delete.

Security and operational risks of running the compactor

The compactor is the component that removes data, so its risks are mostly about removing too much, letting the wrong people trigger removal, and losing the evidence of what was removed. The cards below cover the decisions that shape those risks and the checks to make before the compactor touches production data.

Retention set too broadly

Retention is disabled by default, so Loki keeps logs indefinitely until retention_enabled is set. When it is enabled, a global, per-tenant or per-stream rule removes data on the compactor's schedule, and a rule written for one tenant or selector can match more streams than intended. Before enabling it, review each rule against the tenants and label selectors it will match, and confirm the period against the data your policies require you to keep.

Loki retention docs

Who may request deletes

Deletion through the compactor's delete API removes log lines by stream, time window and line filter, and it is the step most likely to be used in an incident, such as after secrets were logged. Restrict which accounts can reach the API, keep it off public networks, and agree in writing who may approve a delete request. Treat the approval path as a control, not a convenience.

Object store permissions

The compactor reads, rewrites and removes objects in the bucket that holds chunks and index files. Grant it only the object actions its work requires, scoped to the Loki bucket or prefix, and avoid sharing its credentials with other workloads. Confirm with your storage vendor how bucket lifecycle rules interact with retention, so that an external rule does not remove data earlier or later than your policy states.

Persistent disk for working state

The compactor keeps working state on local disk while it compacts the index and processes deletes. If that volume is lost or reset mid-run, operators must know which deletes completed and which must be reissued. Give it a persistent volume, document where that volume lives, and include it in the backup and restore plan so that a restarted singleton resumes from a known state.

Singleton failure during deletes

The main compactor runs as a singleton, so one instance owns scheduled retention and delete processing. A failed pod or node can pause those jobs without an obvious error in ingestion dashboards. Monitor the compactor's own job status, alert when scheduled work stops advancing, and confirm your restart and failover approach before depending on the schedule for compliance.

Audit evidence of deletion

Removing data is only defensible if you can show what was removed, when, by whom and under which approved request. Keep a record of each delete request, its approval, the query scope and the completion status, and store it outside the Loki cluster it describes. Ask your auditors which evidence they expect for log deletion before you design the record.

Questions teams ask before running the Loki compactor

Is a singleton Loki compactor a single point of failure?

Yes, the compactor runs as one instance, so its failure stops index compaction, retention and delete processing until it returns. Ingestion and queries on the other components generally continue, but storage housekeeping falls behind. Reduce the exposure by running it under a supervisor or Kubernetes controller that restarts it automatically, keeping its working directory on persistent storage, and alerting on its health. After a restart, check that compaction and retention have resumed and that pending deletes are still queued. Confirm the exact failover and recovery behavior for your Loki version in the official documentation before you write a runbook.

Should we run horizontal compactor scaling in production?

Not as a default. Horizontal scaling for the compactor is experimental. It spreads the work of line-filter log deletion, the compactor's most operationally intensive task, across worker instances, while a singleton main coordinates the work. If your organization has heavy line-filter deletes, such as removing secrets or personal data from many streams, test the mode in a non-production environment with a copy of your data and delete volume first. Ask whether the behavior, metrics and upgrade path are acceptable for your risk profile, and plan a rollback to the single-instance setup. The compactor horizontal scaling documentation is the starting point for the configuration.

How much effort does the compactor setup take, and what drives it?

The effort depends mostly on the deployment shape and the rules you need. The main drivers are the deployment mode, since the Loki documentation lists monolithic, simple scalable and microservices modes, and simple scalable is being deprecated and removed with Loki 4.0. Other drivers are the object store, the number of tenants, the number of global, per-tenant and per-stream retention rules, expected delete volume, and whether the cluster runs on Kubernetes. Setup is usually a one-time design and build cost, while upgrades, monitoring and periodic retention reviews recur. Ask any provider for a fixed-scope quote with written deliverables, the environments covered and the test plan. DeployOpen agrees scope and timelines in writing before work starts.

Can an internal team run the Loki compactor alone?

Yes, if the team already operates Loki and the chosen object store, and has a clear change process. The compactor is one component, but it changes what is stored and removed, so a mistake in retention or delete configuration can destroy data that cannot be recovered from Loki itself. Before you decide, confirm that someone can design retention rules, review every delete request against your privacy and audit obligations, test changes outside production, and respond to a stalled compactor at night. If any of these are thin, a fixed-scope engagement can cover the design, build, runbook and handover, with ongoing support available as a retainer.

How long do retention and delete requests take to show effect?

No general duration applies, because the result depends on your Loki version, compaction settings and the object store. Retention is disabled by default, so nothing is removed until retention is enabled, and each stream rule must be at least 24 hours. Deletes work on a cancellation period and are applied by the compactor on its own schedule. Check the schedule and the cancellation behavior for your version in the Loki retention documentation, then verify removal with test queries on a known stream. Also review any object store lifecycle rules, since they can remove data on a different timeline from Loki.

What does the compactor need from our infrastructure and staff?

The compactor needs write and delete permission on the object store for the index and chunks, preferably through an identity such as an IAM role or workload identity rather than long-lived static keys. It also needs persistent local storage for its working files, configuration that defines retention and delete behavior, and monitoring that reports whether it is running. On the people side, you need an owner who approves delete requests, a change window for upgrades, and log owners who understand which streams contain sensitive data. Confirm these prerequisites against your environment before the build starts, so the handover is not blocked by missing access or storage.

How do we know the compactor is working correctly?

Watch three things: that the compactor process stays healthy, that its logs show compaction and retention cycles completing, and that the data you expect to be removed actually disappears. Health and cycle checks catch a stalled singleton early, while periodic test queries against a known stream confirm that retention and deletes take effect. Record the metric and log names for your Loki version, set alerts for a missing cycle, and review pending delete requests on a fixed schedule. A written verification step in your runbook lets an auditor or security reviewer see how removal was checked.

When an implementation partner adds value for compactor work

The compactor is a singleton that touches your stored data, so the real decision is whether your own platform team can own its configuration, deletion procedures and any move to the experimental horizontally scalable mode, or whether a partner should carry part of that load. An internal team usually wins when it already runs Loki in production, has someone who reads the Loki release notes before each upgrade, and can staff a change window for deletions. A partner tends to add the most value when the first deployment is new to the team, when a deletion request arrives under time pressure (for example, after credentials or personal data were logged), or when leadership wants a second review of retention rules before they go live. Confirm which of these applies to you before you ask for a quote.

A written scope should name each compactor task in your environment: the retention settings and which tenants or stream selectors they cover, the deletion request process and who approves it, the schedule and monitoring of compaction runs, and the decision criteria for trying horizontal scaling. The client must provide the things a partner cannot invent: read and write access to the object store bucket and its lifecycle configuration, named owners for each retention policy with the authority to sign off on shorter or longer periods, access to the Loki configuration repository, and a non-production environment with representative log volume where deletions and mode changes can be rehearsed. Ask for the scope to state which of these items are included, and which remain with your team after handover.

Because the horizontally scalable mode is documented as experimental, a partner should not be the party that promotes it into production without a written agreement on who carries the risk. Ask that any proposal to adopt it include a rollback path back to the single compactor, a test of a large line-filter deletion in the non-production environment, and a named owner who will track changes in the official Loki compactor horizontal scaling documentation. Whether your team or a partner runs that work, the output should be a decision record, not an informal assumption that the mode works as expected.

Decision path for choosing retention, deletes and scaling mode

The path starts from the need: retention for age-based removal, a targeted delete for specific lines, or heavy line-filter deletion. Retention and targeted deletes both run through the compactor's configuration, and line-filter deletes at volume are where the experimental horizontally scalable mode is evaluated. That evaluation should happen in a non-production environment first, with the compactor's delete workload measured on a copy of your data before any change reaches production.

Decision path from removal need to compactor configuration and scaling mode.

How DeployOpen scopes and supports Loki compactor work

DeployOpen plans, implements and hands over Loki compactor work inside your own infrastructure, including the singleton compactor, its retention and delete schedules, and any evaluation of the experimental horizontally scalable mode. Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.

How we scope

  • Written scope covering compactor placement, working directory, retention settings and delete request handling for your Loki version
  • Inventory of your object storage buckets, lifecycle rules and retention requirements to confirm what the compactor will and will not remove
  • Decision record on whether the experimental horizontally scalable mode is in or out of scope, with the reasons documented

How we build

  • Deploy a single compactor instance with persistent storage, then verify its schedules and logs in your environment before enabling retention
  • Test retention and line-filter deletion against non-production data, confirming removal from object storage and index results
  • Run the horizontal scaling evaluation only in a staging copy, with main and worker roles tested for failure and restart behavior

How we hand over

  • Runbooks for compactor restarts, stuck delete requests, retention verification and the monitoring signals your team should watch
  • Configuration and deployment records kept in your repositories, with the chosen Loki version and every changed setting noted
  • Knowledge transfer sessions with your platform and security engineers, followed by a sign-off checklist agreed in the written scope

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers for compactor changes after handover
  • Review of each Loki version upgrade for compactor configuration and storage changes before your team applies them
  • Confirm with DeployOpen during scoping which support hours, response expectations and escalation paths apply to your retainer

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.