Differentiate KStream vs KTable, implement stream-table joins, windowing, state stores with changelog topics, and interactive queries.
0 / 5 completed
1 / 5
What is the difference between a KStream and a KTable in Kafka Streams?
KStream vs KTable: a KStream is like a traditional log — every event is a new row. A KTable is like a database table with upsert semantics — a record with key "user-1" overwrites the previous value for that key. KTables enable streaming joins and lookups: join a KStream of orders against a KTable of product prices to enrich each order.
2 / 5
What is a stream-table join in Kafka Streams and what are the timing semantics?
KStream-KTable join:orders.join(productTable, (order, product) -> enrich(order, product)). The table lookup is non-windowed — the enrichment reflects whatever value the KTable currently holds for that product key. If the table is updated after an order is processed, that order retains the old enrichment. This is useful for dimension table lookups (user profiles, product catalogue).
3 / 5
What is windowing in Kafka Streams and what types of windows are available?
Windowing:stream.groupByKey().windowedBy(TimeWindows.ofSizeWithNoGrace(Duration.ofMinutes(5))).count() counts events per key per 5-minute tumbling window. Session windows close when no new event arrives for a gap period — useful for user session analytics. Late-arriving events are handled by withGracePeriod() to allow updating closed windows.
4 / 5
What are state stores in Kafka Streams and how are they made fault-tolerant?
State stores: Kafka Streams tasks keep state locally in RocksDB for performance. Every state change is also written to a compacted changelog topic. If a task fails and is reassigned to another instance, it restores state by replaying the changelog. Standby replicas (num.standby.replicas) pre-warm state on other instances for faster failover.
5 / 5
What are interactive queries in Kafka Streams and what do they enable?
Interactive queries:streams.store(StoreQueryParameters.fromNameAndType("counts", QueryableStoreTypes.keyValueStore())) returns a ReadOnlyKeyValueStore. External services query this store via a REST API you expose. For distributed deployments, use streams.metadataForKey() to find which instance owns a key and proxy the request there.