liveBook · Manning

Database

As explained in Apache Kafka in Action

A database is a software system that durably stores, organizes, and supports querying of data.

An order service needs to answer a question immediately: what is the current state of an order? A relational database is well suited to storing that service’s data and querying its current state with SQL. It can execute complex queries across tables and provides ACID guarantees. Kafka serves a different question: what happened, and how did the system reach its current state? section 17.4 section 18.5.1

Keep the boundary between internal data and exchanged data clear:

  • Use a relational database for service-specific data, particularly when the service needs SQL queries, joins, or immediate access to current state. section 17.4.1 section 18.5.1
  • Avoid making one database the shared interface for many services. Changes then become tightly coupled and may require coordination across teams. section 17.4.1
  • Use Kafka for asynchronous data exchange between services. Each service can build the view it needs from the event history; Kafka is not a substitute for a relational database’s synchronous queries or full ACID guarantees. section 17.4.2 section 18.5.1

Sending customer and order data

Suppose customer and order details live in separate, normalized database tables. A consumer may need both in one message. Joining the tables in the relational database before writing a flattened message to Kafka avoids making consumers perform the join—and avoids an expensive, complex join in a real-time pipeline. section 18.5.1

A database also has a log of its own. Its commit log records changes before tables are updated and supports recovery and replication. Kafka makes a log central to data exchange instead; services can turn that history into their own materialized views. Kafka Connect can link databases and Kafka with relatively little configuration effort. section 4.1.1 section 17.4.2

Figure 17.5 Relational databases excel with their consistency guarantees, but when a database is used by many services, this leads to very strong coupling, and even small changes must be coordinated with all teams.
A group of colored circles with text

AI-generated content may be incorrect.

The diagram illustrates the cost of sharing a database across services: even a small database change can require coordination with every dependent team. section 17.4.1

How Apache Kafka in Action covers it

How deep it goes
Explains queries, ACID guarantees, normalization, joins, and commit logs, but does not walk through database setup or SQL commands.
Examples
Uses customer and order tables to illustrate denormalization and a shared-database diagram to illustrate service coupling.
What you can do after
Evaluate/understand when to retain service-specific state in a relational database and use Kafka instead of a shared database for exchange.
How it connects
Connects databases to SQL, ACID guarantees, Kafka, commit logs, denormalization, and materialized views.

Also explained in

Compare how 24 books explain database →

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.