Quick revision
The short answer
120,000 partitions with replication factor 3 is 360,000 replicas, and each one costs file handles, memory, controller metadata and recovery time, which is why restarts take 25 minutes, while most of them carry almost no traffic. We consolidate to shared topics per event type or aggregate, keyed by tenant id plus entity id, with the tenant id in a header and the payload, and sized by total throughput. Per-tenant ACLs, retention and deletion move into the services, with keyed tombstones or crypto-shredding for deletion, and only the two contractually isolated tenants keep dedicated topics or a dedicated cluster. We migrate through a bridge that copies old topics into the new ones and move consumer groups one at a time.
What to remember
In this answer, we saw that 120,000 partitions mean 360,000 replicas, each costing file handles, memory, metadata and recovery time, which explains the 25-minute restarts, while most partitions sit nearly idle and produce tiny batches. We consolidated to shared topics per event type keyed by tenant plus entity, with the tenant in headers and payload, and sized by throughput. We replaced per-topic ACLs, retention and deletion with service-level enforcement, tombstones or crypto-shredding, and kept dedicated topics or a cluster only for the two contractual tenants. A bridge, producer moves, timestamp-based consumer moves and idempotent consumers complete the migration.
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.
120,000 partitions with replication factor 3 is 360,000 replicas, and each one costs file handles, memory, controller metadata and recovery time, which is why restarts take 25 minutes, while most of them carry almost no traffic. We consolidate to shared topics per event type or aggregate, keyed by tenant id plus entity id, with the tenant id in a header and the payload, and sized by total throughput. Per-tenant ACLs, retention and deletion move into the services, with keyed tombstones or crypto-shredding for deletion, and only the two contractually isolated tenants keep dedicated topics or a dedicated cluster. We migrate through a bridge that copies old topics into the new ones and move consumer groups one at a time.
Why this question is asked
Topic-per-tenant designs feel natural when a SaaS product is young: isolation is easy to explain, ACLs are simple and deleting a customer means deleting a topic. They break down as tenants grow into thousands, because Kafka's costs scale with partitions, not with bytes. Interviewers ask this scenario to see whether we can quantify that cost, design a shared layout that keeps what really matters, handle the contractual exceptions, and migrate without downtime. In this answer, we will measure the problem, design the shared layout, account for what we lose and how we replace it, and plan the migration.
1Why 120,000 Partitions Hurt
Every partition replica is a directory with log segments and index files on a broker, open file handles, memory for indexes and buffers, a replication fetch slot, and an entry in the controller's metadata. With 2,500 tenants, 8 event types and 6 partitions, that is 120,000 partitions, and with replication factor 3 it is 360,000 replicas spread over the brokers.
That is why broker restarts are slow. When a broker starts, it must open and check its logs, rejoin the in-sync replica set for every partition and take back leadership, and the controller must process leadership changes for tens of thousands of partitions. Twenty-five minutes per broker turns a rolling restart of a 12-broker cluster into a five-hour operation.
Meanwhile, most of those partitions are almost idle. A small tenant might send a few events an hour to each topic, split over 6 partitions. Producers then send tiny batches, often one record per batch, which wastes request overhead and compresses badly. The cluster pays for 120,000 partitions to carry traffic that 100 well-used partitions could handle.
2The Shared Layout
We consolidate to one topic per event type or aggregate, shared by all tenants: for example tenant.orders.events instead of 2,500 orders topics. The key is tenant id plus entity id, such as acme:order-1001. That keeps per-entity order, since every event of order-1001 for acme lands on the same partition, and it spreads a large tenant across many partitions, so one big tenant does not create a hot partition the way a key of tenant id alone would.
The tenant id also goes into a header and the payload, so consumers can filter or route by tenant without parsing the key. Partition counts follow total throughput and consumer parallelism, not tenant count: perhaps 24 to 48 partitions per shared topic, and a few hundred partitions in total instead of 120,000.
| Aspect | Topic per tenant | Shared topics |
|---|---|---|
| Partitions (RF 3 replicas) | 120,000 (360,000) | about 300 (900) |
| Tenant onboarding | create 8 topics | nothing to create |
| Consumer subscription | regex over thousands of topics | 8 named topics |
| Per-entity order | yes | yes, key tenant:entity |
| Tenant isolation | per-topic ACLs | enforced in services |
| Tenant deletion | delete topics | tombstones or crypto-shredding |
3What We Lose, and How We Replace It
Consolidation removes three things that topics gave us for free. Per-tenant ACLs disappear, because a consumer that can read the shared topic can read every tenant's records, so tenant access must be enforced in the consuming services, which already have to respect tenancy in their own databases. Per-tenant retention disappears too, as the topic has one retention, so tenants that pay for longer history get it from a downstream store rather than from Kafka.
Per-tenant deletion is the third. When a tenant leaves, we can no longer delete their topics. On compacted topics, we write tombstones for every key of that tenant, and compaction removes the data. On delete-policy topics, data ages out with retention, and if it must disappear sooner, crypto-shredding helps: each tenant's payloads are encrypted with a tenant key, and destroying the key makes the remaining records unreadable.
The two enterprise tenants whose contracts require isolated storage keep dedicated topics, or, if the contract means separate infrastructure, a dedicated small cluster. Producers route their records there by tenant id. Exceptions for two tenants are cheap; exceptions for 2,500 were the problem.
4Regex Subscriptions Go Away
Consumers today subscribe with a pattern such as tenant-.*-orders. With thousands of matching topics, every metadata refresh is large, and every time a topic is created for a new tenant, the subscription changes and the consumer group rebalances, pausing all consumers in the group. Onboarding one tenant briefly stalls processing for everyone. With shared topics, consumers subscribe to a fixed list of eight names, metadata stays small, and onboarding a tenant creates no topics and triggers no rebalance.
5Migrating Without Stopping
We cannot move 2,500 tenants at once, so we run a bridge: a small Kafka Streams or Connect job that reads the per-tenant topics and writes each record into the matching shared topic with the new key and header. While it runs, producers move to the shared topics service by service; once a producer writes directly, the bridge stops copying that producer's topics so records are not duplicated.
Consumer groups then move one at a time. For each group, we find the starting offsets in the shared topics by timestamp, using offsetsForTimes or kafka-consumer-groups.sh --reset-offsets --to-datetime, a little before the moment the group stopped on the old topics. The overlap means some records are seen twice, so consumers must be idempotent, deduplicating by event id. After all groups have moved and a full retention period has passed with no clients on the old topics, we delete them, and broker restarts drop from 25 minutes to a few.
- Create shared topics with new keys
- Start bridge: per-tenant topics -> shared
- Move producers service by servicebridge stops copying moved topics
- Move consumer groups one at a timestart by timestamp, dedupe overlap
- Wait one retention period with no clients
- Delete per-tenant topics
6 steps in order. Play them, or step through them one at a time.
6Follow-up questions
Would a key of tenant id alone be simpler?
Simpler, but it puts a whole tenant on one partition. A large tenant would create a hot partition and cap that tenant's processing at one consumer, while small tenants leave partitions idle. Keying by tenant plus entity keeps the order that matters, per entity, and spreads load evenly.
How do we stop one noisy tenant from slowing everyone down on a shared topic?
Producer quotas apply per client, so if tenants produce through their own client identities we can quota them; otherwise the ingestion service rate-limits per tenant before producing. On the consumer side, per-tenant work queues or limits inside the service stop one tenant's backlog from starving others.
7Conclusion
In this answer, we saw that 120,000 partitions mean 360,000 replicas, each costing file handles, memory, metadata and recovery time, which explains the 25-minute restarts, while most partitions sit nearly idle and produce tiny batches. We consolidated to shared topics per event type keyed by tenant plus entity, with the tenant in headers and payload, and sized by throughput. We replaced per-topic ACLs, retention and deletion with service-level enforcement, tombstones or crypto-shredding, and kept dedicated topics or a cluster only for the two contractual tenants. A bridge, producer moves, timestamp-based consumer moves and idempotent consumers complete the migration.
Open with
The root cause is partition count. 2,500 tenants times 8 event types times 6 partitions is 120,000 partitions, and with replication factor 3 that is 360,000 replicas. Each one costs open files, memory, controller metadata and recovery work, so restarts and leader elections are slow, and most partitions carry almost no traffic, so producers send tiny batches.
Then, if they want more
I would consolidate to one topic per event type or aggregate shared by tenants, keyed by tenant id plus entity id, so per-entity order is kept and a big tenant spreads over partitions, with the tenant id also in a header and the payload. Partitions are sized by total throughput, so we go from 120,000 to a few hundred.
We lose per-tenant ACLs, retention and topic deletion, so tenant access is enforced in the consuming services, and tenant deletion uses keyed tombstones on compacted topics or crypto-shredding. The two enterprise tenants whose contracts require isolation keep dedicated topics or a dedicated cluster.
Shared topics also remove regex subscriptions over thousands of topics, which cause slow metadata refreshes and rebalances whenever a tenant is onboarded.
To migrate, I would run a bridge copying per-tenant topics into the shared ones while producers move, then move consumer groups one at a time from offsets found by timestamp, relying on idempotent consumers for the overlap, and delete the old topics after a retention period.
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 "Broker restarts take 25 minutes, onboarding a tenant means creating 8 topics, and...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-design/a1e97fe3d0/