Marlow Navigation, a world leader in commercial ship management services, wanted to understand if...
![](https://blog.oso.sh/hubfs/Asset-57@2x.png)
Kafka Streams vs Flink
With the rise of Apache Flink, and Confluent now starting to offer a cloud native Flink service I thought I would compare both popular stream processing frameworks: Kafka Streams and Flink. When it comes to Kafka Streams vs Flink both frameworks offer powerful capabilities for processing real-time data, but they have some key differences in terms of their architecture and features.
Kafka Streams vs Flink: Stateful Operations and Backends
Both Kafka Streams and Flink support stateful operations, which allow you to maintain and update state as data is processed. However, there are some differences in how they handle state and backends.
Kafka Streams: In Kafka Streams, the state is stored in a local cache and periodically flushed to a state store, which is backed by a RocksDB instance. The state is also written to a change log topic for data robustness. In the event of a failure, Kafka Streams can restore state from the change log topic. Kafka Streams also supports flexible deployments and high availability for processing, with standby tasks to mitigate state restoration time.
Flink: Flink uses checkpoints for fault tolerance and state management. Checkpoints are triggered periodically by the cluster itself, and each task manager serialises its state and stores it in a file externally. In the event of a failure, Flink can recover quickly by reopening the RocksDB from the checkpoint file. Flink is highly optimised for large stateful operations and offers efficient snapshot capabilities for quick recovery.
Kafka Streams vs Flink: Key Value Data Model
One notable difference between Kafka Streams and Flink is their approach to the key-value data model.
Kafka Streams: Kafka Streams has a key-value data model, where keys are associated with the data records. Kafka Streams allows you to extract and manipulate keys using a Kafka record deserialization scheme. You have full control over adding, extracting, and populating keys in the records.
Flink: Flink does not have a built-in key-value data model. Instead, keys are virtual and determined by the functions you provide. Flink aligns individual keys into key groups for distribution among operators. You can set the maximum parallelism to determine the number of key groups and limit the number of parallel tasks.
Time Semantics
Both Kafka Streams and Flink support event time semantics for stream processing. Event time is used to track the progress of the stream and drive window behaviour.
Kafka Streams: In Kafka Streams, the highest timestamp received by an operator is called stream time. Stream time is used internally to mark the progress of the stream and drive window behaviour. Kafka Streams uses a timestamp extractor to extract timestamps from the incoming records. If records arrive out of order, stream time does not move backwards.
Flink: Flink also uses event timestamps to track time internally. Flink uses watermarks to signal to windowed operators when they can trigger computations. Watermarks indicate that all records with timestamps earlier than the watermark have been seen. Flink allows you to set a watermark strategy globally for the job, but each task slot can have its own watermark generator.
Should I use Kafka Streams or Flink?
Kafka Streams offers flexible deployments and high availability for processing. It is well-suited for scenarios where fault tolerance and state restoration are important. Flink is highly optimised for large stateful operations and offers efficient snapshot capabilities for quick recovery. It does not have a built-in key-value data model, but allows you to determine keys based on the functions you provide. Flink is a good choice for scenarios that require high performance and scalability.
While there are some differences between Kafka Streams and Flink, it’s important to note that there is also a lot of overlap between the two frameworks. The choice between them ultimately depends on your specific requirements and use case.
For more content:
How to take your Kafka projects to the next level with a Confluent preferred partner
Event driven Architecture: A Simple Guide
Watch Our Kafka Summit Talk: Offering Kafka as a Service in Your Organisation
Successfully Reduce AWS Costs: 4 Powerful Ways
Kafka performance best practices for monitoring and alerting