Describe how you would use Kafka Streams for real-time data processing.

Instruction: Provide an overview of Kafka Streams and discuss how it can be used to build robust, real-time data processing applications.

Context: This question tests the candidate's knowledge of Kafka Streams and their ability to leverage it for developing scalable and fault-tolerant streaming applications.

Updated

Official answer

Kafka Streams is a client library that runs inside an application. It reads Kafka topics, executes a processing topology and writes results to Kafka; it is not a separate processing service inside the broker.

For a page-view dashboard, define a schema with event ID, page ID, event timestamp and event type. Validate records, keep page views, select page ID as the key, group by key and count into one-minute event-time windows. Changing the grouping key can require repartitioning. Publish keyed window-count updates to a result topic that the dashboard materializes as upserts, rather than adding every update as if it were a new independent total.

Choose the timestamp extractor, grace period and retention from the late-arrival contract. A window count may change until the window closes; a timestamp alone does not make every late record acceptable. Define duplicate-event handling separately if repeated business events must count only once.

Use state stores and their configured changelogs for recovery, and provision storage and restoration capacity. Run instances under the same application ID to distribute tasks; parallelism remains constrained by the topology's partitions. Rebalances and state restoration can interrupt useful processing. Disabling store logging changes recoverability.

Choose at-least-once or exactly-once processing from the required Kafka output/state/progress boundary. External calls still need their own retry and idempotency design. Test malformed records, out-of-order timestamps, window edges, restart and replay. Measure result freshness, dropped late records, restoration time and errors against an explicit target instead of assuming a universal latency guarantee.

Streams DSL, processing configuration

Related Questions