Kafka · Advanced Kafka

What is ksqlDB?

Mediumksqldbksqlsqlstream processing

Interview question

What is ksqlDB, and when would you use it versus Kafka Streams?

How to answer

The short answer

ksqlDB (historically KSQL) lets you build stream processing with SQL-like statements on , instead of writing a Java Streams app.

What it feels like

SQL
CREATE STREAM orders (
  order_id VARCHAR KEY,
  amount DOUBLE,
  country VARCHAR
) WITH (KAFKA_TOPIC='orders', VALUE_FORMAT='JSON');

CREATE TABLE orders_by_country AS
  SELECT country, COUNT(*) AS order_count
  FROM orders
  WINDOW TUMBLING (SIZE 1 HOUR)
  GROUP BY country
  EMIT CHANGES;

Under the hood

ksqlDB builds on Kafka Streams concepts: continuous queries, materialized views, push/pull queries (product features vary by version/deployment).

When ksqlDB shines

  • Analysts / DE teams who want SQL for continuous transforms
  • Fast prototyping of filters, enrichments, simple aggregates
  • Materialized views over event streams

When Kafka Streams (code) shines

  • Complex business logic, custom processors
  • Tight integration with existing Java services
  • Fine-grained control over state, punctuations, app packaging

Interview tip: "ksqlDB = SQL interface for stream processing on Kafka; Kafka Streams = the code library underneath / alongside."