Understanding data stream processing
Stream processing Frameworks
The most popular stateful stream processing frameworks in the open source space are Apache Flink, Apache Kafka, and Apache Spark – all developed at the Apache Software Foundation and therefore available under the Apache license. All are written in Java or Scala and at home in the Java Virtual Machine (JVM). Apache Flink was born as a stream processor. Apache Spark came out of the batch-processing environment and, over time, added stream processing capabilities in the form of processing in micro-batches. Apache Kafka is actually a tool for storing data streams and is very popular as a stream processing source and sink. In recent years, however, Kafka has also been given a number of functions that enable it to operate as a stream processor.
Each stream processing framework has a different programming model, but the tools do have some similarities. For example, all three have programming interfaces (APIs) with varying degrees of expressiveness: from relatively close to the system to more abstract interfaces to languages such as SQL (see the box entitled "Databases and Stream Processing").
Databases and Stream Processing
Databases and stream processing often appear together, but it is important to distinguish between databases and stream-processing frameworks. SQL only acts as a description language for a program. In a streaming context, the application usually runs continuously and processes the infinite data stream chunk by chunk, adjusting the internal state and the output as a new event becomes available.
To use SQL at all, stream-processing frameworks often define a duality between a data stream and a dynamic table. (If you look at a table and observe all changes over time, you ultimately have a data stream.) Databases often even allow access to this data stream, either through a kind of binary log, or in the form of a Change Data Capture (CDC) data stream.
Listing 1 shows how to implement the example of linking the video playback events to video ads using the Apache Flink SQL API. In this case, you only have to define p.playTime
and i.impressionTime
as event-time attributes, including defining the watermark strategy, and you have quite a compact program that continuously outputs all display events for each video playback up to one hour before playback. In Flink's system-level DataStream API (Java or Scala), the code for this scenario would be a little more complicated: The programmer would have to take care of temporarily buffering the events while reading the data streams until the watermark signals that the input is complete.
Listing 1
SQL example in Flink
01 SELECT 02 p.userid, p.title, p.playTime, COLLECT(DISTINCT i.title) AS impressions 03 FROM 04 Plays p, 05 Impressions i 06 WHERE 07 p.userid = i.userid AND 08 i.impressionTime BETWEEN p.playTime - INTERVAL '1' HOUR AND p.playTime 09 GROUP BY p.userid, p.title, p.playTime
A special class of APIs called stateful functions allow easy and flexible creation of event-based distributed applications that use a stream processor as a substructure but feel comfortable in a serverless environment. A program of this kind is not modeled as a data stream but with stateful functions for each object of the system, where each function can freely interact with others. Programs written with stateful functions can use a number of different programming languages, because the functions use HTTP to communicate with each other and are completely independent of each other. Ververica was one of the first companies to publish a stateful functions API for this type of modeling and programming in the stream processing environment a year ago, and it is now an official component of Apache Flink.
Conclusions
Stream processing has become an important tool for processing as much distributed data as possible in real time. The stream processing paradigm offers an easy approach to creating distributed real-time applications of arbitrary complexity. Open source frameworks help programmers produce correct results and also handle task distribution, network communication, and fault tolerance in the underlying cluster. Stream processing might seem confusing at first glance, especially event time and watermarks, but once you have internalized the various elements, you'll be well on your way to building your own stream processing applications.
In order to make stream processing available to an even wider audience, SQL APIs have already been created to enable software engineers, data engineers, and scientists to benefit from the advantages of integrating a database. These APIs, as well as the ecosystem that surrounds them, are undergoing continuous development.
« Previous 1 2 3
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.