Stateful processing

Many SQL queries keep state. Aggregations, joins, and deduplication remember information from earlier rows. Each new row can update a result. Flink stores this state locally in a state backend, and saves it with checkpoints when you turn on checkpointing.

Stateful operations process a data flow with operators that store and read information across multiple events. Flink has two basic types of state:

  • Keyed state is bound to a key, and you can use it only on keyed streams. In SQL, a GROUP BY or a join key creates a keyed stream. Flink stores one value of state for each key.
  • Operator state is bound to one parallel instance of an operator.

Flink stores and reads the working copy of the state locally, preferably in memory. The implementation of these local stores is called a state backend. Flink also creates asynchronous, periodic snapshots of the state, which are the checkpoints. When you turn on checkpointing, Flink saves the snapshots in durable storage.

Cloudera SQL Stream Builder (SSB) supports the RocksDB and Hashmap state backends. Hashmap is for small and moderate state. RocksDB is the production solution for large state, and it supports incremental checkpoints. For more information, see State backends.