liveBook · Manning

Foreign key

As explained in Kafka Streams in Action, Second Edition

A foreign key is a field whose value references a key in another table or record set.

A foreign key is a value-field reference to a key in another table. In Kafka Streams, it enables a KTable join when the tables use different primary keys. section 8.6.4

A Kafka Streams foreign-key join works by:

  • Extracting the referenced key from the left-side value with a java.util.Function. section 8.6.4
  • Skipping the join when the extractor returns null. section 8.6.4
  • Supporting inner and left-outer joins without requiring co-partitioned tables. section 8.6.4
  • Triggering potential results when either table receives an update. section 8.6.4

Client contracts and commodities

A client-contract KTable uses client ID as its key, while its value contains a commodity code. A commodity-price KTable uses that commodity code as its key. Extract the code from each contract value and pass the extractor to clientContractTable.join(commodityPriceTable, foreignKeyExtractor, joiner). section 8.6.4

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Explains extraction, null handling, update triggers, and repartitioning, then illustrates lookup and matching internals.
Examples
Uses client contracts keyed by client ID whose values reference commodity codes keyed in a commodity table.
What it assumes
Assumes familiarity with tables, primary keys, and KTable joins while contrasting them with foreign-key joins.
What you can do after
Apply it via Kafka Streams by supplying a foreign-key extractor and joiner to KTable.join.
How it connects
Connects foreign keys to primary keys, KTable joins, repartition topics, state stores, and co-partitioning.

Also explained in

Compare how 18 books explain foreign key →

Related concepts

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