Kafka Data Storage

Published
Length
3 min read

Luis Felipe Dias

All posts

You manage kafka data storage by splitting event streams into topic partitions on disk. The system writes each incoming event to the end of an append-only log file. Most teams set up these topics with shared admin roles to move fast. Broad roles let any user or app read every event in the cluster. One bad command can delete whole topics or expose private customer events. How kafka data storage works on disk The system does not keep messages in memory like a simple queue. Instead, it writes ev

Data Storage: the complete guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free white paper. No spam. Unsubscribe anytime.

You manage kafka data storage by splitting event streams into topic partitions on disk. The system writes each incoming event to the end of an append-only log file. Most teams set up these topics with shared admin roles to move fast. Broad roles let any user or app read every event in the cluster. One bad command can delete whole topics or expose private customer events.

How kafka data storage works on disk

The system does not keep messages in memory like a simple queue. Instead, it writes every event straight to the host disk drive. A topic holds a stream of events of the same type. The system splits each topic into smaller parts called partitions. Each partition lives inside its own folder on the server disk.

Inside that folder, the server breaks the partition into smaller segment files. New events always go to the end of the active segment file. Sequential disk writes run very fast on modern drives. When a segment file reaches a set size, the server closes it. Then the server opens a brand new segment file for new writes.

Each event in a partition gets a unique number called an offset. Consumers use this offset number to read events in the exact order. Reading events does not delete them from the disk folder. Multiple apps can read the same partition at their own pace. Index files help the server find the right offset position on disk fast.

How retention rules and tiered storage manage space

Because reads do not delete data, disk folders grow over time. Teams set up retention rules to keep disks from filling up. You can tell the server to delete segment files after several days. You can also set a size limit for each topic partition. Once the folder hits that size, the server deletes the oldest segments.

Some teams use log compaction instead of deleting old segment files. Compaction keeps only the newest event for each unique message key. This method works well when you store the current state of records. Teams also use tiered storage to save space on local server drives. Tiered storage moves closed segment files to cheap cloud object storage buckets. Local disks keep only the newest events for fast reads.

Data Storage: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native storage rules solve and where gaps remain

Native storage rules control disk use and replication across servers very well. Built-in access control lists also decide which user or app can log in. You can grant a role permission to read or write specific topics. These rules stop outside users from touching your event logs.

Still, native access rules only check who logs in at the topic level. They do not inspect what individual commands or queries do in flight. A developer with topic read rights gets every field inside those events. Those payloads often hold emails, phone numbers, card numbers, or national IDs. Admin roles for fixing disk issues also allow risky topic changes. Shared keys make it hard to see which person ran a command.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Does Kafka delete messages after a consumer reads them?

No, the server keeps messages on disk even after apps read them. The system only removes old segment files when retention time or size limits hit.

How does replication protect stored events from server crashes?

The cluster copies each partition across multiple servers using a leader and follower setup. If the leader server fails, a follower server takes over without losing stored events.

What is the difference between log deletion and log compaction?

Log deletion removes whole segment files based on their age or total byte size. Log compaction keeps the latest value for every unique key and removes older updates.

Save the open-source gateway.

hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.