Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. What is ksqlDB?

Kafka · Advanced Kafka

What is ksqlDB?

Mediumkafka-26
ksqldbksqlsqlstream processing

Question

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

Solution

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

What it feels like

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
SQL-first continuous pipelines  → ksqlDB
Code-first embedded processing → Kafka Streams library

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

PreviousNext