Quick revision
The short answer
I would check four things, in this order. First, co-partitioning: for a KStream-KTable join both topics need the same number of partitions and the same key, serialized and partitioned the same way. Second, the key itself: if orders are not keyed by customer id, the stream must be re-keyed, which adds a repartition topic. Third, timing: an order that arrives before its customer record is not joined, unless we use a GlobalKTable or a versioned table with a grace period. Fourth, serde mismatches that make equal-looking keys different bytes. Throughout, the topology description and the repartition topics show what is actually running.
What to remember
In this answer, we debugged a KStream-KTable join that drops some orders. We checked co-partitioning, meaning the same partition count, key and partitioner on both topics; the order's key, which must be the customer id, with re-keying adding a repartition topic; timing, since an order processed before its customer is not joined unless we use a GlobalKTable or a versioned table with a grace period; and serdes that make equal-looking keys differ. Reading the topology description and the repartition topics shows what actually runs.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would check four things, in this order. First, co-partitioning: for a KStream-KTable join both topics need the same number of partitions and the same key, serialized and partitioned the same way. Second, the key itself: if orders are not keyed by customer id, the stream must be re-keyed, which adds a repartition topic. Third, timing: an order that arrives before its customer record is not joined, unless we use a GlobalKTable or a versioned table with a grace period. Fourth, serde mismatches that make equal-looking keys different bytes. Throughout, the topology description and the repartition topics show what is actually running.
Why this question is asked
Join bugs in Kafka Streams are frustrating because there is no error: most orders are enriched correctly and a few just disappear, or come out with an empty customer in a left join. The customer clearly exists when we look it up. Interviewers ask this debugging question because each likely cause tests a different part of how Kafka Streams joins work. In this answer, we will recap how a stream-table join works, then go through co-partitioning, re-keying, timing and serdes, and finish with how to read the topology to see what is really executed.
1A Quick Recap of a Stream-Table Join
In a KStream-KTable join, each order record that arrives triggers a lookup: Kafka Streams takes the order's key, looks it up in the local state store that holds the customer table, and if it finds a customer, emits the joined result. Updates to the customer table do not trigger output on their own; they only change what future orders will find. An inner join emits nothing when the lookup fails, and a left join emits the order with a null customer.
The lookup is local. The task processing orders partition 3 can only see the customers stored for customers partition 3. So the whole join depends on the order for customer 42 and the customer 42 record ending up in the same partition number of their topics, and on the order arriving after the customer.
- Same partition count on both topics?YesNext checkNoFix: co-partition or use a GlobalKTable
- Is the order keyed by customer id?YesNext checkNoRe-key with selectKey (adds a repartition topic)
- Did the customer arrive before the order?YesNext checkNoTiming: GlobalKTable, or versioned table + grace
- Same key bytes on both sides?YesInspect topology and repartition topicsNoFix the key serde / partitioner
4 steps in order. Play them, or step through them one at a time.
2Check 1: Co-Partitioning
Co-partitioning means both input topics have the same number of partitions, are keyed by the same thing, and were written with the same partitioning strategy, so that a given key lands on the same partition number in both. Kafka Streams checks the partition counts of joined source topics when it starts and fails with a topology error if they differ, but it cannot check how producers chose partitions.
So if the customers topic was written by a producer with a custom partitioner, or by a non-Java client whose default partitioner hashes differently, customer 42 may sit on partition 5 while orders for customer 42 sit on partition 3. The task for partition 3 never finds the customer. The fix is to write both topics with the default partitioner, or to repartition one side through Kafka Streams, or to join against a GlobalKTable, which holds all customers on every instance and needs no co-partitioning.
3Check 2: Is the Order Keyed by Customer Id?
Orders are often keyed by order id, because that is natural for the order service. A KStream-KTable join uses the stream's key, so joining orders keyed by order id against customers keyed by customer id compares the wrong things and almost nothing joins. We must re-key the stream with selectKey or map so that the key is the customer id.
Re-keying has a consequence: the record's new key may belong in a different partition, so Kafka Streams writes the re-keyed stream to an internal repartition topic and reads it back, partitioned by the new key. That is correct and expected, but it adds a topic, latency and some cost, and the repartition topic must exist and be readable.
4Check 3: Did the Order Arrive Before the Customer?
This is the most common cause when the customer 'clearly exists'. It exists now, but the join ran when the order was processed. If customer 42 is created and immediately places an order, the order event can be processed before the customer event has reached the table, for example because the customer service publishes slightly later, or because the customers topic's task is behind. A stream-table join does not wait and does not retry: the order looks up an empty slot and is dropped, or emitted with null in a left join.
There are a few fixes. A GlobalKTable is bootstrapped fully at startup before processing begins, which helps for reference data but not for customers created seconds before their order. Since Kafka 3.5 a KTable can be backed by a versioned state store that keeps a history of values by timestamp, so the join looks up the customer as of the order's timestamp; since 3.6 a stream-table join can also be given a grace period that buffers stream records for a while, so a slightly late customer record can still be joined. Check your version for the exact API. Otherwise, a design option is to route unjoined orders to a retry topic.
5 messages in order. Play them, or step through them one at a time.
The customer exists, but not when the order was looked up.
5Check 4: Serdes That Make Keys Different
Keys are compared as bytes, after serialization. If the customers topic was written with a Long key serializer and our topology reads orders with a String key, the customer id 42 is eight bytes of a long on one side and the two characters '4' and '2' on the other. They never match, and they also hash to different partitions. Similar trouble comes from JSON keys with different field order or whitespace, or Avro keys with different schemas.
The fix is to use the same key type and serde on both sides, explicitly, with Consumed.with and Joined.with, rather than relying on default serdes. Reading a few raw records from each topic with kafka-console-consumer and print.key=true shows the actual key bytes quickly.
6Read the Topology to See What Runs
Kafka Streams can describe the topology it has built. Printing builder.build().describe() at startup lists every sub-topology, its source and sink topics, processors, state stores and repartition topics. It shows whether a repartition happens where we expected, which store the join uses and which topics feed it. Comparing that with the topics' partition counts and a sample of their keys usually locates the problem within minutes.
7Follow-up questions
Why not always use a GlobalKTable to avoid all of this?
A GlobalKTable avoids co-partitioning and repartitioning, but every instance stores the whole table, and it does not solve the timing problem for records that are created just before the order. It is a good fit for small reference data, not for a customer table with tens of millions of rows.
How can we find out how many orders failed to join?
Use a leftJoin instead of join and count or route the records where the customer is null, for example to an unjoined-orders topic. That turns silent drops into a visible metric and gives a place to retry them.
8Conclusion
In this answer, we debugged a KStream-KTable join that drops some orders. We checked co-partitioning, meaning the same partition count, key and partitioner on both topics; the order's key, which must be the customer id, with re-keying adding a repartition topic; timing, since an order processed before its customer is not joined unless we use a GlobalKTable or a versioned table with a grace period; and serdes that make equal-looking keys differ. Reading the topology description and the repartition topics shows what actually runs.
Open with
A stream-table join is a local lookup: when an order arrives, the task looks up its key in the customer table's store for the same partition number. So first I'd check co-partitioning.
Then, if they want more
Both topics need the same partition count, and Kafka Streams checks that at startup, but they also need the same key and the same partitioning, so if the customers producer uses a custom or non-Java partitioner, customer 42 can be on a different partition than its orders and never found.
Second, the order's key: if orders are keyed by order id, I need selectKey to the customer id, which creates a repartition topic. Third, and most common, timing.
A stream-table join doesn't wait; if the order is processed before the customer record reaches the table, the inner join emits nothing and the left join emits null, even though the customer exists a second later.
Fixes are a GlobalKTable for small reference data, or since 3.5 and 3.6 a versioned table and a grace period on the join, or routing unjoined orders to a retry path. Fourth, serdes: if one side has a Long key and the other a String key, the bytes never match.
To see what's really executed I'd print topology.describe() and look at the repartition topics, and I'd switch to a leftJoin that counts null customers so drops become visible.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Kafka 3.5
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Kafka documentation, Spring for Apache Kafka reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A Kafka Streams application joins orders with customers, but some orders never produce a...": https://scrivio-interview-library.netlify.app/spring-boot/kafka/2b4005d7b7/