Scrivio Interview library
DebuggingIntermediate6 min read · updated 13 November 2026

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 a TopologyException saying Topics not co-partitioned: [clicks,user-profiles]. Explain the check and compare the ways to fix it.

A join reads partition i of both topics in task i, so equal keys must sit at the same partition number on both sides, and Streams checks during assignment that joined source topics have the same partition count; 12 and 8 cannot line up, so it refuses to start. We can rebuild user-profiles with 12 partitions, repartition one side inside the app to match, or use a GlobalKTable if profiles are small. Equal counts are necessary but not enough: the same key serialisation and partitioner are needed too, and partition counts of shared topics belong in the data contract.

Why this question is asked

This failure is a good example of a dependency nobody wrote down: one team's topology silently relied on another team's partition count. The error is clear, but the fixes have very different costs, and one of them can corrupt a compacted topic if done carelessly. Interviewers ask it to see whether we understand why co-partitioning exists and can choose a fix. In this answer, we will see what the check protects, what it does not check, then compare the three fixes with their costs, and finish with how to stop it happening again.

1What the Co-Partitioning Check Protects

Kafka Streams creates tasks per partition number. For a KStream-KTable join reading clicks and user-profiles directly, task 3 reads partition 3 of clicks and partition 3 of user-profiles, and the join only works if a click for user u-42 and the profile of u-42 both live in partition 3. That holds when both topics use the same key, the same partitioner and the same number of partitions, because the default partitioner computes a hash of the key bytes modulo the partition count.

With 12 and 8 partitions, u-42 might be in partition 7 of clicks and partition 3 of user-profiles, and there is no task that sees both. So during assignment Streams compares the partition counts of topics that must be co-partitioned, and when they differ for source topics it fails with a TopologyException naming them, as here: Topics not co-partitioned: [clicks,user-profiles]. Failing at startup is much better than running and silently missing most joins.

2What the Check Cannot See

Equal partition counts are necessary but not sufficient. If the profile producer serialises the user id as a String and the clicks producer as a UUID in binary, or one uses a custom partitioner, equal keys hash to different partitions even with 12 partitions on both sides. Streams cannot detect that, so the join runs and most records find no match: inner joins drop them, left joins fill in nulls.

So whenever we fix the count, we also confirm the key serialisation and partitioner on both producers.

Where user u-42 lands
TopicPartitionsPartition for u-42Same task?
clicks12hash(u-42) % 12 = 7-
user-profiles (recreated)8hash(u-42) % 8 = 3No: task 7 never sees the profile
user-profiles (fixed)12hash(u-42) % 12 = 7Yes
Example values; the point is that the modulus changes where keys go.

3Fix 1: One Partition Count for Both Topics

The most direct fix is to agree that user-profiles has 12 partitions, like clicks, and rebuild it. The detail that matters is how. Adding partitions to an existing keyed topic does not move the existing records; new records for u-42 would go to a new partition while old ones stay in the old one, and on a compacted topic the old value could then outlive the new one. So the profile topic must be rewritten: create it with 12 partitions and reload it from its source, for example by re-running the CDC snapshot or replaying the producing service.

This is the cleanest result, but it needs the other team's work and a coordinated switch, and it keeps the coupling: the next change on their side breaks us again.

4Fix 2: Repartition Inside Our Application

We can decouple ourselves by repartitioning one side to the other's count inside the app. Here we turn the table into a stream, repartition it to 12 partitions with a stable name, and turn it back into a table.

Java
KTable<String, Profile> profiles = builder.stream("user-profiles", Consumed.with(Serdes.String(), profileSerde))
.repartition(Repartitioned.<String, Profile>numberOfPartitions(12).withName("profiles-by-user"))
.toTable(Materialized.as("profiles-store"));
clicks.join(profiles, (click, profile) -> click.withProfile(profile)); // both now have 12 partitions
// internal topic: <application.id>-profiles-by-user-repartition (12 partitions)

Tombstones pass through repartition and toTable() treats them as deletes, so the table stays correct. The cost is an extra internal topic holding a copy of the profiles and the traffic to write and read it. We could equally repartition clicks down to 8, but clicks is usually the larger stream, so copying the profiles is cheaper. The big benefit is that our app no longer depends on the other team's choice of partition count.

5Fix 3: A GlobalKTable for Small Profiles

If the profiles fit comfortably on every instance, say a few hundred megabytes, a GlobalKTable removes the requirement entirely: every instance reads all 8 partitions into a full copy, and clicks look up profiles by key. It costs memory and disk per instance and a full load on startup, and its lookups are not synchronised by timestamp, but the partition count of user-profiles stops mattering.

Step throughChoosing a fix
  1. Can user-profiles be rebuilt with 12 partitions?
    YesRewrite it from its source (Fix 1)NoFix it on our side
  2. Are profiles small enough for every instance?
    YesGlobalKTable (Fix 3)NoRepartition inside the app (Fix 2)
  3. Confirm key serialisation and partitioner match
  4. Record partition counts in the data contract

4 steps in order. Play them, or step through them one at a time.

6Preventing the Next One

Whatever we choose, the real lesson is that partition counts of shared topics are part of the data contract, just like the schema. We list consumers that depend on co-partitioning in the contract, review partition changes to shared topics like schema changes, and add a startup or CI check in consuming apps that compares the partition counts they rely on. Then a change like this is a conversation before the fact rather than an outage after it.

7Follow-up questions

Why does Streams only check source topics directly joined, not repartition topics?

Streams creates repartition topics itself, so it simply creates them with the right partition count to match the other side. Only topics it does not own, the source topics, can have a count it cannot change, so those are what it checks and refuses.

Could we increase clicks to match a larger profiles topic instead?

The same rule applies: adding partitions to clicks changes where keys go for new records, which breaks ordering per key across the change. It also changes nothing for the join until both are equal. Shrinking is not possible at all, so matching a smaller count means a new topic.

Would a foreign-key join avoid the problem?

A foreign-key join needs two KTables, and clicks are events, so it does not fit here. For table-to-table joins it is another way to avoid co-partitioning, because Streams routes through its own subscription topics.

8Conclusion

In this answer, we saw that a join runs per partition number, so Streams checks that directly joined source topics have the same partition count and refuses to start when they do not, while the key serialisation and partitioner must also match, which it cannot check. We compared rewriting user-profiles with 12 partitions, repartitioning the profiles to 12 inside our app at the cost of an internal topic, and switching to a GlobalKTable for small profiles, and we made partition counts of shared topics part of the data contract.

What to say in the interviewAbout 90 seconds aloud

Open with

A join in Kafka Streams runs inside a task, and task i reads partition i of both topics, so a click and the profile for the same user must be in the same partition number.

Then, if they want more

When the topology joins two source topics directly, Streams checks during assignment that they have the same partition count. With 12 and 8 the keys hash to different partition numbers, so it refuses to start rather than silently missing joins.

Equal counts are not enough, though: both producers must use the same key serialisation and partitioner, which Streams cannot verify, and a mismatch there just produces missing join results. I see three fixes.

One, agree on 12 partitions and rebuild user-profiles from its source, because adding partitions to a keyed compacted topic moves where keys hash, so it must be rewritten, not just expanded.

Two, repartition one side inside our app, for example profiles to a stream, repartition to 12 with a fixed name, then back to a table; that costs an internal topic and a copy of the data but decouples us from the other team. Three, if profiles are small, a GlobalKTable needs no co-partitioning at all.

In every case I would make partition counts of shared topics part of the data contract and review changes to them.

About this answer

Last updated
13 November 2026
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
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 "After another team recreated user-profiles with 8 partitions, the app fails at startup...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-streams-connect/81b83d32f7/