liveBook · Manning

ksqlDB

As explained in Kafka Streams in Action, Second Edition

A ksqlDB server is the server-side service that executes ksqlDB statements and manages continuously running stream-processing applications.

ksqlDB is an event streaming database for Kafka. It uses SQL to define continuously running stream-processing applications, with Kafka Streams performing the processing underneath. Queries can produce ongoing results instead of returning once and stopping. section 1.4.6 section 11.0

Create STREAMs for unbounded independent events and TABLEs for keyed update streams. Source queries bind these objects to Kafka topics; persistent queries write results to topics for sharing, while push queries stream results to clients and pull queries run once. section 11.7

Use ksqlDB to:

  • Build real-time applications with SQL rather than application code or configuration files. section 1.6 section 11.0
  • Aggregate, window, and join event streams, including stream–table lookups for enrichment. section 11.0 section 11.6
  • Work with Kafka topic schemas and serialization formats, including Avro, Protobuf, JSON Schema, and format changes through WITH clauses. section 11.7

Customer rewards from correlated purchases

Define coffee and store purchase streams keyed by customer ID, then join purchases occurring within 30 minutes. A CASE expression assigns reward points from the store total; a LEFT OUTER stream–table join can then add member details. The joined topics must be co-partitioned with matching key types and partition counts. section 11.6 section 11.7

Listing 11.34 Creating a stream-stream join for potential customer rewards
CREATE STREAM customer-rewards-stream AS
  SELECT c.custId AS customerId,           #1
       s.total as amount,              #2
       CASE                             #3
         WHEN s.total < 25.00 THEN 15
         WHEN s.total < 50.00 THEN 50
         ELSE 75
        END AS reward_points
  FROM coffee-purchase-stream c
    INNER JOIN store-purchase-stream s
    WITHIN 30 MINUTES GRACE PERIOD 2 MINUTES     #4
    ON c.custId = s.custId           #5

This SQL listing shows a persistent stream–stream join with a time window, grace period, key condition, selected fields, and conditional reward calculation. section 11.6

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Explains streams, tables, query types, serialization, aggregations, and joins, including co-partitioning requirements.
Examples
Demonstrates purchase-reward joins, member lookup enrichment, foreign-key joins, and nested JSON queries.
What it assumes
Assumes SQL familiarity while using Kafka topics and streaming concepts to construct applications.
What you can do after
Builds real-time Kafka applications with SQL streams, tables, persistent queries, and joins.
How it connects
Connects Kafka Streams, Kafka topics, Schema Registry, streams, tables, aggregations, windowing, and joins.

Also explained in

Compare how 2 books explain ksqlDB →

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.