00:00

Kafka Tiered Storage

Last updated:

Kafka tiered storage splits a topic’s log into two tiers: recent data stays on the brokers’ local disks, and older, completed log segments move to cheaper remote storage such as Amazon S3, Google Cloud Storage, Azure Blob Storage or HDFS. Consumers keep reading through the same Kafka API, whether the data is local or remote.

Tiered storage (KIP-405) became production-ready in Apache Kafka 3.9. This tutorial explains how it works internally, which broker and topic settings enable it, how reads and retention behave across tiers, and the limitations to know before turning it on.

1. What Is Tiered Storage?

Without tiered storage, every byte a topic retains lives on the local disks of every replica. Tiered storage adds a remote tier: once a log segment is closed (it no longer receives new records), the leader copies it to remote storage, and after the local retention period the broker deletes its local copy. The segment remains readable from the remote tier until the topic’s overall retention expires.

TierHoldsRetention settingRead path
LocalThe active segment and recent closed segments, on every replicalocal.retention.ms / local.retention.bytesPage cache and local disk (fast)
RemoteClosed segments and their indexes, stored onceretention.ms / retention.bytesFetched from object storage by the broker (higher latency)

2. Why Kafka Needs a Remote Tier

Kafka is often used as a long-term event store: replaying months of events into a new service, rebuilding a search index, or keeping an audit trail. Storing all of that on broker disks is expensive, because every byte is replicated (typically three times) on fast block storage. It also makes operations slower: adding a broker or replacing a failed one means copying all of that data across the network.

  • Lower cost: old data is stored once in object storage instead of three times on broker disks.
  • Longer retention: keep months or years of data without sizing brokers for it.
  • Faster operations: brokers hold less local data, so rebalancing partitions and recovering a broker move far less data.
  • Separation of concerns: broker disk size follows the write rate and local retention, not total retention.

3. How Tiered Storage Works

Kafka tiered storage architectureOn the partition leader, the log consists of older closed segments, recent closed segments and the active segment. The remote log manager copies closed segments to remote object storage through a RemoteStorageManager plugin and records segment metadata in the internal __remote_log_metadata topic. After local retention, older segments exist only in the remote tier. A consumer reading recent offsets is served from local disk; a consumer reading old offsets is served by the broker, which fetches the data from remote storage. Partition leader (broker) old segmentsdeleted locally recent closed segmentslocal + remote copy active segmentlocal only Remote log manager Remote object storageS3, GCS, Azure Blob, HDFSvia RemoteStorageManager plugin __remote_log_metadatasegment metadata upload Tail consumerserved from local disk Replay consumerold offsets fetched from remote
Closed segments are copied to object storage; reads of old offsets are served from the remote tier through the broker.
  1. Copy. On the partition leader, the remote log manager periodically copies closed segments, with their offset and time indexes, to remote storage through a RemoteStorageManager plugin.
  2. Record metadata. A RemoteLogMetadataManager records which segments exist remotely. The default implementation stores this in the internal topic __remote_log_metadata, so no extra database is needed.
  3. Delete locally. Segments older than the local retention are deleted from local disks once they are safely in the remote tier.
  4. Serve reads. When a consumer fetches an offset that is no longer local, the broker reads the segment from remote storage and returns the records through the normal fetch path. Clients need no changes.
  5. Expire. When a segment passes the topic’s overall retention, it is deleted from the remote tier too.

4. Broker Configuration

Tiered storage is disabled by default and must first be enabled on every broker. Apache Kafka defines the plugin interface but does not ship a production RemoteStorageManager: you install a plugin for your storage system (several open-source and vendor plugins exist) and point the broker at it:

server.properties (tiered storage excerpt)
# turn on the remote log subsystem
remote.log.storage.system.enable=true

# plugin that talks to your object store (class name and path come from the plugin you install)
remote.log.storage.manager.class.name=<your RemoteStorageManager implementation>
remote.log.storage.manager.class.path=/opt/kafka/plugins/tiered-storage/*

# default metadata manager (internal topic); it needs a listener to connect through
remote.log.metadata.manager.listener.name=PLAINTEXT

# plugin-specific settings use the configured prefix, for example
# rsm.config.storage.bucket.name=kafka-tiered-prod

For a quick experiment, the Kafka project provides LocalTieredStorage, a test implementation that simulates remote storage in a local directory. It is built from the Kafka sources and is meant only for trying the feature out.

5. Enabling Tiered Storage for a Topic

Enabling the broker side alone changes nothing. Each topic opts in with remote.storage.enable=true and usually a short local retention:

Terminal
# new topic: keep 1 day locally, 180 days in total
bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic payment-events \
  --partitions 12 --replication-factor 3 \
  --config remote.storage.enable=true \
  --config local.retention.ms=86400000 \
  --config retention.ms=15552000000

# existing topic
bin/kafka-configs.sh --bootstrap-server localhost:9092 --alter \
  --entity-type topics --entity-name order-events \
  --add-config remote.storage.enable=true,local.retention.ms=86400000
Topic settingDefaultMeaning
remote.storage.enablefalseWhether this topic uses tiered storage
local.retention.ms-2 (use retention.ms)How long segments stay on local disk; must not exceed retention.ms
local.retention.bytes-2 (use retention.bytes)Size limit for the local part of each partition
retention.ms7 daysTotal retention across both tiers

If you enable tiering but leave local.retention.ms at its default, local and total retention are equal, so local disk usage does not shrink at all. The saving comes from setting local retention well below total retention.

6. How Reads and Retention Behave

  • Tail reads stay fast. Most consumers read the newest data, which is still local and usually in the page cache. Tiered storage does not change their latency.
  • Historical reads are slower. Fetching an old offset means reading from object storage. Throughput can still be high, but the first fetch of a segment has noticeably higher latency. Size remote.log.reader.threads (default 10) for replay workloads.
  • Data is stored once remotely. Only the leader uploads; followers do not store separate remote copies. Durability of the remote tier comes from the object store.
  • Segment size matters. Only closed segments are uploaded, so segment.bytes and segment.ms decide how soon data becomes eligible for the remote tier and how large each upload is.

7. Delaying Uploads and Disabling Tiering

By default a segment is uploaded as soon as it is closed, so recent segments briefly exist in both tiers. If remote storage does not need to be that fresh, remote.copy.lag.ms and remote.copy.lag.bytes delay uploads to reduce this overlap.

To stop tiering a topic, two topic settings are available:

  • remote.log.copy.disable=true makes the remote data read-only: no new uploads, existing remote segments stay readable until they expire.
  • Setting remote.storage.enable=false together with remote.log.delete.on.disable=true turns tiering off for the topic and deletes its remote data.

Tiering must be disabled on every topic that uses it before the feature can be disabled on the brokers.

8. Real-World Use Cases

  • Long-term event retention for event-sourced systems and audit topics.
  • Replays and backfills: rebuilding a new service’s state from months of history with message replay.
  • Machine learning and analytics jobs that occasionally read large historical ranges.
  • Cost control for high-volume topics where only the last day is read frequently.

9. Advantages and Limitations

AdvantagesLimitations
Much cheaper long retentionCompacted topics are not supported
Smaller brokers and faster partition moves and recoveryKafka ships no production remote storage plugin; you need one for your object store
Transparent for producers and consumersHistorical reads have higher latency than local reads
Retention can be set per topicDisabling requires disabling every tiered topic first; admin actions need clients 3.0 or newer

10. Common Mistakes

  • Leaving local retention at the default. Data is copied to the remote tier but never removed locally, so costs go up instead of down.
  • Enabling it on compacted topics, such as changelog or __consumer_offsets-style topics; tiered storage supports only delete-policy topics.
  • Very large segments. With segment.bytes at 1 GiB on a low-traffic topic, a segment may stay active for days and never reach the remote tier.
  • Ignoring the object store’s own costs. Request and retrieval charges matter for heavy replay workloads.
  • Not monitoring remote copy lag. If uploads fall behind, local disks still fill up; watch the remote log metrics and plugin errors.

11. Best Practices

  • Size local retention for normal consumers, for example a few hours to a day, so tail reads never touch the remote tier.
  • Test the plugin under failure: object-store outages, throttling and credential rotation.
  • Enable tiering per topic, starting with large, append-only topics with long retention.
  • Keep replication factor 3; tiered storage does not replace replication of the local tier.
  • Watch remote fetch latency and reader thread usage when teams start large replays.

12. Summary

Tiered storage keeps recent data on broker disks and moves closed segments to object storage, so a topic can retain far more data at lower cost while producers and consumers use the normal Kafka API. Enable it on the brokers with a RemoteStorageManager plugin, then per topic with remote.storage.enable=true and a local retention well below total retention. Remember that compacted topics are not supported, historical reads are slower, and uploads and plugin health need monitoring.

14. References