liveBook · Manning

State

As explained in Apache Kafka in Action

Current state is the complete information representing the present condition of a system or entity.

An online store needs to know a product’s price and stock now. A state message records the complete information of interest about that product, rather than just its latest change. A product message can therefore carry its ID, name, price, and stock together. section 3.2.1

# One message per line
{"id": 123, "name": "coffee pad", "price": "10", "stock": 101010}
{"id": 234, "name": "cola", "price": "2", "stock": 52}
{"id": 345, "name": "energy drink", "price": "3", "stock": 42}

Each line is a separate product state message. Notice that price and stock appear together even though one might change without the other. section 3.2.1

A delta carries only changed values, saving repetition but often needing an earlier state to be useful. An event describes what happened, such as a delivery; a state answers what the object looks like. When only the latest state matters, message keys and log compaction can reduce storage. section 3.2.1 section 3.3

State can also be derived from a stream of changes. Replaying messages to find a machine’s latest status or a customer’s balance may be expensive, so stream processing uses techniques such as aggregations and joins. Its results remain intermediate: new messages can arrive, and processing is eventually consistent. section 12.4 section 12.1.2

A relational database is useful for a service’s current state. Kafka retains history from which different services can reconstruct the state their own use cases need. Sharing one database across many services instead risks tightly coupling them. section 17.4.1 section 17.4

How Apache Kafka in Action covers it

How deep it goes
Defines complete state messages and explains reconstruction costs, but defers log-compaction details.
Examples
Uses product price and stock messages, a machine’s latest status, and a customer’s account balance.
What you can do after
Evaluate/understand it: distinguish complete state from changes and assess when reconstructing current state from Kafka history is costly.
How it connects
Connects state to deltas, events, message keys, log compaction, stream processing, and relational databases.

Also explained in

Compare how 39 books explain state →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Apache Kafka in Action. The section links point to the parts of the book it draws on.