Segment-Based Storage vs. Partition-Based Storage: Which is Better for Real-Time Data Streaming?

ScyllaDB 71 views 26 slides Jun 25, 2024
Slide 1
Slide 1 of 26
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26

About This Presentation

Storage is a critical component of any real-time data streaming system, and the choice of storage model can significantly affect the system's performance, scalability, and reliability. Two popular storage models for real-time data streaming systems are segment- and partition-based storage.

In ...


Slide Content

Segment-Based vs Partition-Based Storage: Which is Better for Real-Time Data Streaming? David Kjerrumgaard Developer Advocate at StreamNative

David Kjerrumgaard Developer Advocate at StreamNative Author of Pulsar in Action by Manning Press. My perspective on P99s Committer on the Apache Pulsar project. World-traveler, always looking for the next great place to visit.

Data Streaming Platforms

The Origin of Data Streaming In 2010, LinkedIn needed a way to ingest large amounts of data from its website and internal infrastructure logs and replicate it to multiple databases with a minimal amount of latency.

The Origin of Data Streaming But rather than build a custom solution for every point-to-point integration, they envisioned a more generic solution known as Kafka .

The Log The key to Kafka’s flexibility is its use of the log data structure. A time-ordered, append-only sequence of data. The records are stored in the log as byte arrays, which makes them easily serialized/deserialized into just about anything.

Wait a Minute… Logs aren’t Revolutionary Logs have been used inside databases since 1981. A database uses a log to write out information about the records they will be modifying, before applying the changes, aka changelog .   The log is the record of what happened, and each table or index is a projection of this history into a database table or index. Since the log is immediately persisted it can be used as the authoritative source in restoring all other persistent structures in the event of a crash.

Database Logs: Fast, Single Consumer Records are read from the changelog and applied to the table using ACID semantics to guarantee consistency. Once these changes have been applied, the record is deleted from the log. Consequently, logs inside a database are intended to retain the records for only a short period.

Data Streaming Logs: Multiple Consumers Unlike database logs, streaming logs have multiple consumers that consume at different rates. To accommodate for lagging consumers, streaming platforms were designed to retain data inside their logs for longer periods of time. Retention periods of days, weeks, or even longer are common. Streaming platforms acted as a buffer for data ingestion.

Stream Processing is Born These longer retention periods led to the desire to process and analyze the data inside these streaming platform logs, aka Stream Processing . Stream processing allows users to perform queries that cannot be addressed by traditional, state-based databases; Point-in-time queries such as, “what was the inventory level for this SKU at 8:50 am?” Window analysis such as, “what is the average sensor reading over the five-minute period from 10:41 am to 10:46 am?” This makes data streaming platforms event-based databases .

Stream Storage: Partitions vs. Segments

Horizontally Scalable Log Storage: Longer data retention periods, coupled with the volume of data being ingested, necessitated a log capacity that exceeded the boundaries of a single physical machine. Therefore, a horizontally scalable storage solution was required to accommodate current, and future data volumes. There are two approaches to horizontally scalable storage: Partition-Based Segment-Based

Partition-Based Stream Storage The partition-based storage approach distributes a single logical log across several smaller physically logs known as partitions. These partitions are distributed across several multiple machines, which allows the storage capacity of a single log/topic to exceed that of a single machine. The storage of the logical log can be expanded by adding more partitions.

Partition-Based Storage – Data Distribution

Partition-Based Storage – Physical Placement The topic partitions are distributed across the brokers in Kafka, and the local disk(s) are used to store the messages. Often, a Kafka broker is used to store multiple partitions at the same time. This makes the broker’s local disk a shared resource across multiple topics.

Partition-Based Stream Storage: Pros/Cons The storage model is that it is simple and fast. All reads and writes are sequential. [PRO] A single broker must have enough storage to cope with that replica, so very large replicas can force you to have very large disks. [CON] Scaling out your storage by adding partitions requires a “rebalance”. During this process, the entire topic is offline. [CON]

Segment-Based Storage The segment-based storage approach decomposes a single logical log into several smaller pieces known as segments , which contain ~50K records. These segments are then stored on a separate, horizontally scalable storage layer. This allows a single logical log to have the storage capacity of multiple machines. The storage of the logical log can be expanded by adding more nodes to the storage layer.

Segment-Based Storage Segments are further broken down into fragments . Fragments contain the individual log entries.

Segment-Based Storage – Data Distribution

Segment-Based Storage – Physical Placement In Pulsar, segment-based storage is always kept on a separate layer. A metadata store retains an ordered list of the segments in a topic.

Segment-Based Stream Storage: Pros/Cons The data of a given topic is spread across multiple machines. Distributing reads/writes across multiple disks/disk controllers. Each bookie need only serve a subset of read/write requests, which can increase total throughput and lower latency. When you need to grow your cluster, just add more bookies and they’ll start getting written to when new segments are created. No rebalancing required.

Performance Comparison

Segment vs. Partition Read Throughput Segment-Based Stream Storage achieved 2.5x the maximum throughput of a Partition-Based Streaming Platform

Segment vs. Partition Latency Segment-Based consistently provides single-digit publish latency that is 100x lower than a Partition-Based Streaming Platform

Historical Reads Segment-Based stream storage has a historical read rate that is 1.5x faster than a Partition-Based Streaming Platform

David Kjerrumgaard [email protected] @DavidKjerrumga1 https://streamnative.io Thank you! Let’s connect.
Tags