Kafka Tiered Storage
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.
| Tier | Holds | Retention setting | Read path |
|---|---|---|---|
| Local | The active segment and recent closed segments, on every replica | local.retention.ms / local.retention.bytes | Page cache and local disk (fast) |
| Remote | Closed segments and their indexes, stored once | retention.ms / retention.bytes | Fetched 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
- 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.
- 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. - Delete locally. Segments older than the local retention are deleted from local disks once they are safely in the remote tier.
- 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.
- 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:
# 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:
# 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 setting | Default | Meaning |
|---|---|---|
remote.storage.enable | false | Whether 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.ms | 7 days | Total 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.bytesandsegment.msdecide 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=truemakes the remote data read-only: no new uploads, existing remote segments stay readable until they expire.- Setting
remote.storage.enable=falsetogether withremote.log.delete.on.disable=trueturns 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
| Advantages | Limitations |
|---|---|
| Much cheaper long retention | Compacted topics are not supported |
| Smaller brokers and faster partition moves and recovery | Kafka ships no production remote storage plugin; you need one for your object store |
| Transparent for producers and consumers | Historical reads have higher latency than local reads |
| Retention can be set per topic | Disabling 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.bytesat 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.
13. Related Reading
- Retention vs compaction: how segments are deleted or compacted
- Message replay: reading historical data again
- Performance tuning: segment size, page cache and throughput
- Monitoring and metrics: watching brokers and storage
14. References
Kafka Tiered Storage Interview Questions and Answers
Common interview questions on Kafka Tiered Storage, from basic to scenario-based, with short answers you can explain in your own words.
Basic questions
Q. What do the RemoteStorageManager and RemoteLogMetadataManager do in tiered storage?
Answer: The RemoteStorageManager is a plugin that copies log segments and their indexes to the remote store, reads them back and deletes them; Kafka defines the interface, and you install an implementation for S3, GCS, Azure or HDFS. The RemoteLogMetadataManager tracks which segments exist remotely, with strongly consistent metadata; its default implementation stores this in the internal topic __remote_log_metadata. Tiered storage itself became production-ready in Kafka 3.9.
Q. Which settings enable tiered storage for a topic?
Answer: First the brokers need remote.log.storage.system.enable=true and a RemoteStorageManager plugin. Then each topic opts in with remote.storage.enable=true. local.retention.ms or local.retention.bytes controls how long data stays on local disk, and retention.ms or retention.bytes controls total retention across both tiers.
Intermediate questions
Q. Which data can be moved to the remote tier, and which always stays local?
Answer: Only closed segments are uploaded, together with their indexes; the active segment that still receives writes is always local. Segment size and roll time (segment.bytes, segment.ms) therefore decide how soon data becomes eligible. After upload, local copies are deleted once they are older than the local retention.
Q. Does tiered storage change read latency for consumers?
Answer: Not for consumers reading recent data, which is still local and usually in the page cache. Consumers reading old offsets, such as a replay from the beginning, are served from the remote tier, which has higher latency per fetch, especially for the first read of each segment. Throughput for large replays can still be good if the broker has enough remote reader threads.
Q. Can tiered storage be used for compacted topics?
Answer: No. Tiered storage supports only topics with the delete cleanup policy. Compacted topics, such as Kafka Streams changelogs or entity-state topics, must keep all their data in the local tier.
Tricky and scenario questions
Q. Tiered storage is enabled on a 90-day topic, but broker disk usage did not change. What would you check?
Answer: First local.retention.ms: its default of -2 means “same as retention.ms”, so segments are uploaded but never deleted locally. Set it to, for example, one day. Then check that uploads actually happen: remote copy lag and plugin errors in the broker metrics and logs, and whether segments ever close; on a low-traffic topic, a large segment.bytes can keep one segment active for a long time.
Q. A team wants to keep two years of events cheaply and occasionally rebuild services from them. How would you design it?
Answer: Use a delete-policy topic with tiered storage: a short local retention such as one day for normal consumers, and retention.ms of two years in the remote tier. Keep replication factor 3 for the local tier, choose a reliable RemoteStorageManager plugin, and size remote reader threads for rebuilds. Rebuilding services then replay from the beginning through the normal consumer API, without anyone sizing brokers for two years of data.