Search⌘ K
AI Features

Branching Streams

Explore how to use the split operator in Kafka Streams to branch a single stream into multiple streams based on predicates. Understand direct branch consuming and collecting branches for downstream processing, enabling you to handle different record types effectively within stateless processing topologies.

As specified in the requirements given to us, each record we receive should be treated differently, depending on whether it is an instrumental or a noninstrumental track. When we need to treat records differently in the same topology, we can use the split operator to split a single stream into multiple streams based on a series of predicates.

Splitting the stream
Splitting the stream

You might find other tutorials or guides using an operator named branch instead of split. This operator is deprecated and should not be used.

The split operator

The split operator is powerful and flexible. It works by calling split on the stream, followed by calls to branch, to which we should provide a predicate. Each record is evaluated against the predicate, and is routed to the first branch for which its respective predicate ...