liveBook · Manning

Immutable collection

As explained in Apache Kafka in Action

Immutability is the property of data that prevents its existing contents from being changed or removed after creation.

An immutable collection preserves its existing contents after creation: entries are not changed or removed. New information is added separately, so readers can reconstruct how the represented state evolved over time. section 4.1.2

This property is especially useful for data exchanged between services. Once another service may have consumed a record, altering or deleting it can create disagreement; preserving the original record supports loose coupling while internal data models evolve independently. section 17.1

Immutability changes how data is read and investigated:

  • Treat entries as an ordered history: older entries precede newer ones, and new entries are written at the end. section 4.1.2
  • Represent corrections or later facts as additional information rather than silently rewriting an earlier entry. section 4.1.2
  • Use the history to investigate failures or recover an earlier state by replaying entries up to a chosen point. section 4.1.2

An event exchanged between services

A service publishes outside data describing a change. Other services may already have consumed it, so the record remains available as created instead of being altered or deleted. Each service can maintain an internal representation suited to its own needs while sharing a stable history of exchanged data. section 17.1

Figure 4.1 A log is a sequential list where we add elements at the end and read them from a specific position (offset). For example, we read from offset 0, then choose to read from offset 4, and so on.
A red rectangular box with black text

AI-generated content may be incorrect.

The sequential-log diagram shows immutable entries being added at the end and read from selected positions identified by offsets. section 4.1.2

How Apache Kafka in Action covers it

How deep it goes
Explains the property through logs, debugging, restoration, and service coupling, without detailing collection implementation.
Examples
Uses a diary, application logs, database commit logs, and data exchanged between services as concrete examples.
What it assumes
Assumes basic familiarity with logs, services, databases, and data models while developing the immutability idea incrementally.
What you can do after
Evaluate/understand how immutable histories support debugging, state restoration, and independent service evolution.
How it connects
Connects immutable data with logs, databases, services, data models, loose coupling, and consistency guarantees.

Also explained in

Compare how 24 books explain immutable collection →

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.