Streaming More For Less With Apache Kafka Tiered Storage
Extended introduction to Apache Kafka tiered storage, including performance and cost modelling, with extra material covering recent "diskless" Kafka KIPs. Streaming track talk for Community over Code NA 2025.
homogeneous brokers , with local CPU and storage Broker 6 CPU, RAM Disk Broker 1 CPU, RAM Disk Broker 2 CPU, RAM Disk Broker 5 CPU, RAM Disk Broker 3 CPU, RAM Disk Broker 4 CPU, RAM Disk Scalability Reliability Durability Availability
add brokers for more CPU and storage (both) Broker 6 CPU, RAM Disk Broker 1 CPU, RAM Disk Broker 2 CPU, RAM Disk Broker 5 CPU, RAM Disk Broker 3 CPU, RAM Disk Broker 4 CPU, RAM Disk Broker 7 CPU, RAM Disk From now we will simplify to single broker and topic In reality there are multiple brokers, topics, partitions, and replication!
Records sent from Producers to Consumers End to end guaranteed delivery of records in close to real-time Kafka Producers Consumers Record 0 For subscribed consumers, records are delivered in close to real-time from producers, via Kafka, to consumers Guaranteed delivery, even if failures Produced, sent to Kafka
End to end guaranteed delivery of records in close to real-time Kafka Producers Consumers Record 0 For subscribed consumers, records are delivered in close to real-time from producers, via Kafka, to consumers Guaranteed delivery, even if failures Via Kafka
End to end guaranteed delivery of records in close to real-time Kafka Producers Consumers Record 0 For subscribed consumers, records are delivered in close to real-time from producers, via Kafka, to consumers Guaranteed delivery, even if failures Consumer polls Kafka Got it!
multiple consumer groups – fan-out of records Kafka Producers Two consumer groups Multiple consumer groups receive each record How? Kafka does not delete records immediately so records can be consumed multiple times Record 0 Record 0 Record 0 Group 1 got it Group 2 got it
deleted on delivery Kafka Producers Two consumer groups Records are initially retained in broker cache (active segment) Record 3 Record 2 Record 2 Record 0 Record 1 Record 2
fit infinite records in memory? Move to local disk? Kafka Producers Two consumer groups Records are moved to local disk when active segment is full (lots at once) Record 3 Record 1 Record 2 Record 2 Record 0 Record 2 Record 0 Record 1 Record 2
Kafka Producers Two consumer groups More time & records mean older records are available for consumption But more records take up more and more disk space When are older records consumed? Record 4 Record 1 Record 2 Record 0 Record 0 Record 2 Time Older records S p a c e Record 3
Storage = remote storage in the cloud Infinite cheap remote cloud storage What if you want Lots more storage? Cheaper storage? Then use cloud native storage How does this work?
– extra copies stored remotely Kafka Producers Record 4 Record 1 Record 0 Record 2 Record 3 Record 0 Record 1 Record 0 Record 2 3 - Records are also written to remote storage E.g. AWS S3 Multiple brokers and RF copies of records 1 - In cache (active segment) 2 - and then local storage
– but records retained for different times Kafka Producers Record 4 Record 2 Record 3 Record 0 Record 1 Record 0 Record 2 Records retained for a shorter time local.retention < remote.retention Remote records retained for a longer time remote.retention >> local.retention Older records (0 & 1) deleted from local storage But still available in remote storage
dam - water/records are quickly copied to remote storage The Hoover Dam wall with the outflow from the hydroelectric plant way down below (Source: Paul Brebner)
you need? • A Kafka cluster with tiered storage setup • E.g. Instaclustr managed kafka with AWS S3 tiered storage • BYO S3 bucket • Enable tiered storage for the cluster • Enable tiered storage for topics • With local.retention.ms (new config) << retention.ms (now remote retention time) • Write data • Wait a bit • Depending on segment size • Number of partitions etc • And then data will appear in S3 eventually Kafka tiered storage in practice – 1st steps
• Producer write latency is not impacted by tiered storage • Copying to tiered storage is asynchronous • he “ugly” (watch out) • Tiered storage writes use more Kafka cluster resources • +10% CPU • Copying, and deletion to tiered storage • Can take time • Both are lazy, asynchronous • The bad! • Reading from tiered storage • Consumer latency and throughput impacted • Records from tiered storage don’t seem to be cached, so 2nd read is still slow • May need more partitions, consumers, and cluster resources (brokers) to increase tiered storage read throughput • Sensitive to segment size Kafka tiered storage in practice - performance Fake movie poster, ChatGPT
cluster with tiering enabled have to be bigger? Simple sizing calculator Producer workload in Computes IO and Network Load In MBytes/s Tiered storage with local SSDs
this? We can predict the minimum types/size/number of brokers Blue brokers have network bottleneck Green brokers have IO bottleneck A small increase in all cases BUT note that an existing cluster may have sufficient headroom for these already Lots of assumptions, and CPU not yet included – still need to benchmark in practice
storage for local only (1 day) vs local/remote split (1 hour/1 day) 0 50 100 150 200 250 300 EBS local only - local retention 1 day EBS tiered storage - local retention 1 hour, remote 1 day EBS local vs tiered storage disk storage (TB) Local storage (TB) Remote storage (TB) 2.6x reduction
savings! That’s good 0 5000 10000 15000 20000 25000 EBS local only - local retention 1 day EBS tiered storage - local retention 1 hour, remote 1 day EBS local vs tiered storage $ per month EBS $/month S3 $/month
increase the remote retention to 1 month? 0 2000 4000 6000 8000 10000 EBS local only - local retention 1 month EBS tiered storage - local retention 1 hour, remote 1 month EBS local vs tiered storage disk storage (TB) - 1 month Local storage (TB) Remote storage (TB) 8,000 TB local vs. 2,500 TB remote
increase the remote retention to 1 month? 0 100000 200000 300000 400000 500000 600000 700000 EBS local only - local retention 1 month EBS tiered storage - local retention 1 hour, remote 1 month EBS local vs tiered storage $ per month EBS $/month S3 $/month And S3 is 10x cheaper
Storage for Active Log Segment • https://cwiki.apache.org/confluence/display/KAFKA/KIP- 1176%3A+Tiered+Storage+for+Active+Log+Segment • Use fast object store in each AZ • Copy active segments to object store • Followers now • read from the object store (no inter-AZ cost) • not from the leader broker (inter-AZ cost) • Design goal • Reduce inter-AZ costs due to replication
Write path P = Kafka producer AWS charges inter-AZ data transfer fees $0.01 per GB IN and OUT = $0.02/GB Replication cost = $0.04/GB BU If producer isn’t in Z with leader Then extra $0.02/GB! AZ 1 AZ 2 AZ 3 P Single AWS Region, 3 Availability Zones $0.02/GB $0.02/GB $0.02/GB Current inter-AZ costs
C = Kafka consumer Different AZ, inter-AZ cost Probability of different AZ to leader = 2/3 Inter-AZ for consumers is (2/3)*0.02 = $0.013/GB AZ 1 AZ 2 AZ 3 Single AWS Region, 3 Availability Zones P Follower 2 C $0.02/GB C $0.02/GB C Current inter-AZ costs Worst case
C = Kafka consumer But what if we use follower fetching (fetch from follower, KIP-392)? Reduces consumer inter-AZ cost to $0 C.f. worst case of $0.053/GB IN + $0.013/GB OUT =$0.066/GB (1:1 fan-out) AZ 1 AZ 2 AZ 3 Single AWS Region, 3 Availability Zones P Follower 2 C C C Current inter-AZ costs Follower fetching
segment copied to S3 And replicated from S3 Zero inter-AZ replication costs Some inter-AZ cost for producers in different AZ to leader Single AWS Region, 3 Availability Zones P Follower 2 S 3 KIP-1176 Given data replication in S3 → reduce RF???
for Kafka on AWS • KIP-1176 + follower fetching + cloud “cache” would offer substantial savings in inter-AZ costs • Up to 75% cost savings (or more with higher fan-out) • Note that you can’t reduce inter-AZ cost to zero due to inter-AZ producer costs • Cloud costs (e.g. S3 Express) • Contribute 25-33% of the cost + inter-AZ • Sensitivity to increase in fan-out • Minimal with follower fetching • Increased with reduced RF for KIP-1176 • Using follower fetching can increase latency slightly • As the replicas are slightly behind the leader • High watermark (offset up to which all replicas are in-sync) propagation delays which records are available
Relies on cloud object storage for replication Every broker is a “leader” Write and read from anywhere Data is accumulated across brokers Buffered and uploaded to object storage Latency >= 100ms to seconds Single AWS Region, 3 Availability Zones P S 3 Leader Leader P P Buffering KIP-1150 Alternative approach Major architectural changes
latency comparable to tiered storage 100-2000ms All segments are fetched from object storage Single AWS Region, 3 Availability Zones S 3 Leader Leader C C C P P P Not available yet
both normal and diskless topics • Slow • 100-2000+ ms • Zero inter-AZ costs for AWS • Cloud storage costs? • Comparable to tiered storage probably • Depending on retention times • Complex architectural change • Brokers are now stateless and leaderless • Storage and replication pushed to object storage • N-tier architecture with compute and storage separated • Back to the 2000’s ;-)
out! • NetApp Instaclustr Managed Kafka • 30 day free trial of developer sizes • Potential cost savings • Cost/performance tradeoffs • Watch out for: • Turning tiered storage on for existing topic with lots of local data • S3 buckets not automatically deleted if the cluster is deleted • New use cases with • more data, longer histories, different consumer behaviours, etc • Kafka as a database? Maybe! For some use cases • To scale remote workload may need to have • More partitions when writing data to remote storage • More consumers and resources • A bigger cluster for more CPU – easier, as now the cluster CPU and storage are independently scalable Kafka Tiered Storage Conclusions?