Kafka Streams, Connect and CDC
37 questions in 9 subtopics.
Kafka Streams, Kafka Connect and change data capture are how most teams process data inside Kafka and move it in and out of other systems. Kafka Streams is a Java library for stateful stream processing with local state stores, windows, joins and exactly-once guarantees. Kafka Connect runs connectors that copy data between Kafka and databases, search engines and object storage, with transforms and converters along the way, and Debezium turns database changes into events. In production these tools fail in characteristic ways: long state restores, dropped late records, stuck transactions, connectors that stop on one bad record, and gaps after database failover. The questions cover the core abstractions, state and time, joins, exactly-once processing, connector operation, transforms, CDC and streaming SQL with ksqlDB and Flink.
KStream, KTable and GlobalKTable
Kafka Streams models a topic either as a stream of independent events, as a table holding the latest value per key, or as a global table copied to every instance. Understand how each treats keys and null values, how table updates are cached and forwarded, and how the choice affects partitioning, memory, disk and startup time.
A topic customer-profiles is keyed by customer id. Over an hour it receives three updates for customer 42 and then a record for key 42 with a null value.
A developer reads the topic once withbuilder.stream("customer-profiles") and once with builder.table("customer-profiles"), and aggregates per key downstream of each. What does each version see, and what does the null value mean in each case?Spring Boot can build and start a Kafka Streams topology for you; this exercise writes a small stateful topology end to end and looks at what it creates in Kafka.
Using Spring Boot with@EnableKafkaStreams, write the topology that reads the topic orders (key orderId, value Order with customerId and status), keeps only orders with status PAID, counts paid orders per customer and writes the running count to paid-orders-per-customer. Which Spring Boot properties are required, and which extra topics does the topology create?A Kafka Streams app counts updates per product into a KTable and writes toStream() to an output topic. In tests with TopologyTestDriver every input record produces an output update, but in production a product receiving 200 updates a minute shows only one output record about every 30 seconds.
An order-enrichment service reads order-line events from a 24-partition topic on 6 instances and must enrich each line with product data. The product catalogue has 80 million products (about 40 GB serialized) and changes about 50,000 times a day; instances restart several times a week.
Compare a GlobalKTable, a KTable join after re-keying by product id, and a remote lookup to a product service, covering startup time, disk per instance, consistency and failure behaviour, and recommend one.State stores and stateful processing
Aggregations, joins and windows keep state in local stores, usually RocksDB, backed by changelog topics in Kafka so the state can be rebuilt elsewhere. Understand where state lives, how restoration and standby replicas work, how internal names tie a topology to its stores, and how memory is used outside the JVM heap.
A Kafka Streams app with application.id inventory-app counts stock movements per warehouse with count(Materialized.as("stock-store")).
state.dir at its default a problem in containers?A Kafka Streams service runs on 6 instances and keeps a store order-totals-store with the running total spent per customer. Product wants a REST endpoint GET /customers/{id}/total served from that state.
Explain how you implement it so any instance can answer for any customer, which settings you need, and what the endpoint must do during a rebalance.A team added a filter() step near the start of a Kafka Streams topology and redeployed.
After every deployment of a Kafka Streams service (8 pods, 64 input partitions, about 300 GB of state in total), the application stays in state REBALANCING for 40 to 50 minutes and lag on the input topics climbs to several million records. Logs show tasks restoring from changelog topics.
The pods useemptyDir volumes and default Streams settings. How do you shorten this?A platform team hosts 25 Kafka Streams applications on Kubernetes. Several pods with a 4 GiB memory limit and -Xmx2g are OOMKilled every few hours while JVM heap usage stays under 1.5 GB.
One such pod hosts 48 tasks with 3 stores each, two of them windowed. Explain where the memory goes and what standard you would set for state-heavy Streams applications across teams.Windowing and time semantics
Windowed operations group records by time, and Kafka Streams uses each record's timestamp, not the wall clock, to decide which window it belongs to. Understand the window types, how stream time advances, what grace periods do with late records, and why results can be delayed or dropped when data arrives out of order or traffic is sparse.
Kafka Streams offers several kinds of time window, and choosing the wrong one silently changes what a count or an alert means.
For each requirement choose a Kafka Streams window type and write its definition: (a) page views per user per fixed 5-minute period, (b) a moving 1-hour count of failed logins updated every minute, (c) shopping sessions that end after 30 minutes without activity, (d) detecting two payments from the same card within 10 seconds of each other. Which timestamp does Streams use by default?A fraud service counts card transactions per merchant with windowedBy(TimeWindows.ofSizeAndGrace(Duration.ofMinutes(5), Duration.ofMinutes(1))).count().suppress(Suppressed.untilWindowCloses(Suppressed.BufferConfig.unbounded())) to emit one final count per window.
A Kafka Streams app counts mobile app events in 1-minute tumbling windows defined with TimeWindows.ofSizeWithNoGrace(Duration.ofMinutes(1)), using a TimestampExtractor that reads the event time from the payload.
The business wants a real-time revenue dashboard built from Kafka events and expects it to match finance's end-of-day figures exactly. Some events arrive days late from offline stores, refunds and corrections arrive as separate events, and regions close their day in different time zones.
As the senior engineer accountable for it, how do you set expectations and choose the architecture?Joins and co-partitioning
Kafka Streams can join streams with streams, streams with tables and tables with tables, each with its own triggering and windowing rules. Most joins need both inputs co-partitioned: the same key and the same partition count. Understand the join types, foreign-key joins, global table joins and when a repartition is needed.
Kafka Streams can join streams and tables in several combinations, and each kind of join has its own timing and partitioning rules.
List the joins Kafka Streams supports between KStream, KTable and GlobalKTable. For each, say whether it is windowed, which side's records trigger a result, and whether the input topics must be co-partitioned.Matching each payment to its order within a time limit is a classic streaming join problem, with the added need to report orders that were never paid.
Write a Kafka Streams join that matches each payment on topic payments (keyed byorderId) with its order on topic orders (keyed by orderId) when the payment arrives within 15 minutes after the order, tolerating records up to 2 minutes out of order. Orders without a payment must also be emitted so another service can chase unpaid orders. What does Streams store, and when is an unpaid order emitted?A Kafka Streams app joins a clicks stream (12 partitions) with a user-profiles KTable.
After another team recreated user-profiles with 8 partitions, the app fails at startup with aTopologyException saying Topics not co-partitioned: [clicks,user-profiles]. Explain the check and compare the ways to fix it.An order service publishes order-lines (key orderLineId, 48 partitions, 20,000 records per second); customers (key customerId, 30 million rows) and products (key productId, 5 million rows) are compacted topics owned by other teams.
Exactly-once in Kafka Streams
With exactly-once processing, Kafka Streams commits input offsets, state changelog writes and output records together in one Kafka transaction. Understand what that covers and what it does not, such as calls to external systems, how transactions affect consumers that read committed data, and what it costs in latency and operations.
A Kafka Streams app reads transfers, updates per-account balances in a state store and writes balance-updates. The team sets processing.guarantee=exactly_once_v2.
A service reads the output topic of an exactly-once Kafka Streams app with isolation.level=read_committed. Its lag on partition 7 has grown for three hours while other partitions are fine, and a test consumer with read_uncommitted reads partition 7 normally.
An exactly-once Kafka Streams app aggregates order items and, inside a Processor, calls an email API to send an order-ready email when an order's last item arrives. After a rebalance during a deployment, some customers received the same email two or three times.
The team argues that exactly_once_v2 should have prevented this. Explain what happened and redesign it.Customer account balances in your company are computed by Kafka Streams applications with exactly_once_v2 and shown in a banking app. Internal audit asks you to prove that balances are correct and will stay correct as code and platform change.
How do you answer, and which controls and investments do you put in place?Kafka Connect source and sink connectors
Kafka Connect runs connectors as tasks on a cluster of workers, keeping configuration, offsets and status in internal Kafka topics. Source connectors bring data into Kafka and sink connectors write it out. Understand how tasks are distributed, how offsets are tracked, how error tolerance and dead-letter queues work, and how a shared Connect platform is run.
Kafka Connect is the framework for moving data between Kafka and other systems through configuration rather than hand-written producers and consumers.
Explain the parts of a Kafka Connect deployment in distributed mode: workers, connectors, tasks, converters and the three internal topics. Where are source connector offsets and sink connector offsets stored, and how do you create, check and restart a connector?A JDBC sink connector writing orders to PostgreSQL shows task 2 FAILED with a trace containing BatchUpdateException and 'duplicate key value violates unique constraint'.
errors.tolerance=all and errors.deadletterqueue.topic.name=dlq-orders-sink, yet the task still failed and the DLQ is empty. Explain why, what you do now, and how you configure the connector to cope with such records.Forty teams move data between Kafka and databases, search clusters and object storage.
Today each team runs its own Kafka Connect cluster with different versions and plugins; incidents include a plugin upgrade breaking another connector on the same workers, and database passwords readable through the Connect REST API. Design Kafka Connect as a shared platform.Your company integrates Kafka with about 60 external systems. Some flows use open-source connectors, some use vendor connectors under source-available or commercial licences, some use custom connectors, and some teams wrote their own consumer services instead.
Leadership asks for a strategy that controls cost, licence risk and reliability. How do you decide which path each integration should take?Single message transforms and converters
Converters turn Kafka bytes into Connect's internal data format and back, and single message transforms change one record at a time on its way through. Understand the order of the stages, which errors each stage can tolerate, common transform chains, and why transforms must stay simple, stateless and free of calls to other services.
A source connector writes customer rows to topics named prod-db.public.customers.
A sink connector reads JSON events produced by a Spring Boot service with JsonSerializer and fails at once with DataException: JsonConverter with schemas.enable requires "schema" and "payload" fields and may not contain additional fields.
In Kafka Connect, a record passes through several pluggable stages between the external system and the Kafka topic, and each stage fails in its own way.
Describe the path of a record through Kafka Connect for a source connector and for a sink connector: where the connector, transforms, predicates, converters and header converters sit, which stageserrors.tolerance covers, and why single message transforms should not call external services.Over three years teams have written 30 custom SMTs: some look up customer data over HTTP, some reshape nested JSON into flat rows, and one keeps an in-memory set to drop duplicates.
Incidents include a connector stalling when the lookup service slowed down and duplicates appearing after worker restarts. You own the integration platform. What rules do you set, and how do you migrate the existing transforms?Change data capture with Debezium
Debezium reads a database's transaction log and publishes every insert, update and delete as an event in Kafka. Understand the event envelope, snapshots and incremental snapshots, replication slots and log positions, what happens during database failover, and the governance questions that arise when whole tables flow into shared topics.
Debezium captures an UPDATE of the row with id 1001 in table public.orders on PostgreSQL.
A Debezium PostgreSQL connector has streamed 20 tables for a year. A new requirement needs the 500-million-row table shipments captured too.
Stopping streaming for a full snapshot would take about 10 hours, which is not acceptable. How do you add the table, and how does Debezium avoid mixing up snapshot rows and live changes for the same rows?Debezium captures changes from a PostgreSQL 16 primary that has a hot standby. During a planned failover the standby is promoted; the connector, pointed at the new primary, fails because its replication slot does not exist there.
The team recreates the slot and resumes, and a week later reconciliation shows a few hundred order updates missing from Kafka. Explain the gap and design CDC so database failover does not lose changes.Debezium connectors capture changes from 60 operational databases into Kafka, and 25 teams consume the topics.
A privacy review finds that personal data such as emails, addresses and dates of birth flows into topics retained for 30 days and is copied into several downstream stores, mostly by teams that never use those fields. As the engineering leader for the data platform, what policy do you set and how do you roll it out?KsqlDB and Flink with Kafka
ksqlDB and Flink let teams express stream processing on Kafka topics in SQL or a higher-level API, running as separate clusters rather than inside the application. Understand their models of streams and tables, how they achieve exactly-once results with Kafka transactions, and what changes when queries must be upgraded, migrated or offered as self-service.
ksqlDB lets you express stream processing on Kafka topics as SQL statements, with its own kinds of collections and queries.
In ksqlDB, explain the difference between a STREAM and a TABLE, and between a persistent query, a push query and a pull query. What actually runs on the ksqlDB servers when you executeA Flink job reads the Kafka topic orders, enriches each record and writes to orders-enriched, and must not produce duplicates on failure.
Show the sink configuration, explain how Flink achieves exactly-once with Kafka, and explain the startup error: The transaction timeout is larger than the maximum value allowed by the broker (as configured bytransaction.max.timeout.ms).An analytics engineering team runs 40 persistent queries on a self-managed ksqlDB cluster. Upgrades have been painful, some queries cannot be changed without rebuilding state, and the product's future is uncertain.
Leadership approves a move to Flink SQL. Plan the migration so that consumers of the 40 output topics see no gaps and no flood of duplicates.Analysts and product teams ask for self-service streaming SQL on production Kafka topics so they can build real-time metrics without engineers. The options include a shared Flink SQL platform, a streaming database, or loading topics into a real-time analytics store and querying there.
As head of data platform engineering, how do you decide what to offer, and what guardrails come with it?