Quick revision
The short answer
A GlobalKTable would put the full 40 GB catalogue on every one of the 6 instances and make each restarted or new instance read the whole product topic before processing, and its lookups are not time-synchronised. Re-keying order lines by product id and joining with a partitioned KTable costs a repartition topic but keeps only a sixth of the catalogue per instance, restores only that share, and joins by timestamp. A remote lookup is light but ties availability to the product service and replays see today's data. With 80 million keys and frequent restarts, I recommend the partitioned KTable join with persistent volumes and standby replicas.
What to remember
In this answer, we sized the catalogue at 40 GB with restarts several times a week and compared three enrichment options. A GlobalKTable is simple but puts 40 GB on every instance, makes new instances load everything first and joins without time synchronisation. A remote lookup is light but couples us to another service and changes replays. Re-keying order lines and joining with a partitioned KTable costs a repartition topic but spreads the state, restores quickly with persistent volumes and standbys, and joins by timestamp, so it is the recommendation here.
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.
A GlobalKTable would put the full 40 GB catalogue on every one of the 6 instances and make each restarted or new instance read the whole product topic before processing, and its lookups are not time-synchronised. Re-keying order lines by product id and joining with a partitioned KTable costs a repartition topic but keeps only a sixth of the catalogue per instance, restores only that share, and joins by timestamp. A remote lookup is light but ties availability to the product service and replays see today's data. With 80 million keys and frequent restarts, I recommend the partitioned KTable join with persistent volumes and standby replicas.
Why this question is asked
Enriching a stream with reference data looks like one decision, but at this scale it decides how long a restart takes, how much disk we buy and what happens when another team's service goes down. Interviewers ask this design to see whether we can reason with the numbers rather than reach for the most convenient API. In this answer, we will size the problem, look at each of the three options in turn, compare them side by side, and explain the recommendation and how to make it run well.
1The Numbers That Drive the Choice
The catalogue is 80 million products, about 40 GB serialised, and it changes about 50,000 times a day, which is under one update per second, so it is large but slow-moving. Order lines arrive on 24 partitions processed by 6 instances, so each instance runs 4 tasks. Instances restart several times a week, which means startup and restore time is not a rare event but a weekly cost.
A useful rule follows: whichever option we pick, its cost on restart will be paid many times a month, so a design that needs minutes of loading per restart is expensive even if it is simple.
2Option 1: A GlobalKTable
A GlobalKTable gives every instance a full copy of the table, read from all partitions of the product topic by a separate global thread. The appeal is simplicity: an order line keyed by order id can look up any product through a key-selector function, with no repartitioning.
The cost here is size. Each of the 6 instances holds about 40 GB of RocksDB state, 240 GB in total, and a new instance, or one whose disk was lost, must read the whole product topic before it starts processing; at a sustained 100 MB per second that is about 7 minutes, and in practice RocksDB writes often make it slower. Lookups are also not time-synchronised: a line is joined against whatever product version the global thread has loaded at that moment, so replays and catch-up after an outage can join old lines with new prices, and product updates never trigger a join result.
3Option 2: Re-Key and Join With a KTable
Here we re-key each order line by product id with selectKey, which makes Streams write the lines to a repartition topic, and then join them with a KTable built from the product topic, which must have the same 24 partitions. Each task holds only the products for its partition, so an instance holds about 40 / 6, roughly 7 GB of active state, plus the same again for standbys.
The costs are an extra internal topic carrying a copy of the order lines, a second repartition if consumers need the result keyed by order again, and the loss of per-order ordering across lines of different products. In return, restarts restore only a share of the catalogue, standbys make failover almost instant, and Streams chooses records across both inputs by timestamp, so joins are time-consistent and replays behave predictably.
4Option 3: A Remote Lookup
The instances could call the product service for each line. They stay light, with no state to restore, and always see current data. But every line now costs a network call, the stream's throughput and availability are tied to the product service, and a replay of last week's orders joins against today's products, which changes historical results. To make it workable we need a local cache, timeouts, retries with back-pressure, and a plan for when the service is down, at which point we have rebuilt a weaker version of the KTable.
5Comparing and Recommending
Put side by side, the trade-offs are clear.
| Concern | GlobalKTable | Re-keyed KTable join | Remote lookup |
|---|---|---|---|
| Disk per instance | About 40 GB | About 7 GB plus standby | None |
| Restart of a new instance | Reads all 40 GB first | Restores its share; standby takes over | Immediate |
| Extra topics | None | Repartition topic(s) | None |
| Join consistency | Not time-synchronised | Synchronised by timestamp | Current data only |
| Failure dependency | None at runtime | None at runtime | Product service |
With 80 million keys and restarts several times a week, I recommend the re-keyed KTable join. We give each instance a persistent volume (a StatefulSet on Kubernetes) so a restart replays only the changelog tail, set num.standby.replicas=1 so a lost instance's tasks move to a warm copy, and name the repartition and store explicitly. GlobalKTable stays the right tool for small, slowly changing reference data such as currencies or country codes, where a full copy per instance costs megabytes, not tens of gigabytes.
6Follow-up questions
How would you measure and bound GlobalKTable bootstrap time if you kept it?
We would register a global state restore listener with KafkaStreams.setGlobalStateRestoreListener() to log start, progress and end of restoration, and chart the global consumer's lag at startup. To bound it, we keep the product topic compacted so it holds about one record per product, put the state directory on a persistent volume so a restart reads only the tail after its checkpoint, tune the global consumer's fetch settings, and set a startup readiness check that fails the deployment if bootstrap exceeds a budget, say 10 minutes.
Why must the product topic have 24 partitions for the KTable join?
Task i joins partition i of the repartitioned order lines with partition i of the products table. Equal product ids must land on the same partition number in both, which requires the same partition count and partitioner; otherwise Streams refuses to start with a co-partitioning error.
Would a foreign-key join avoid re-keying the order lines?
If order lines were a KTable keyed by line id, a foreign-key join could match them to products without re-keying the lines ourselves, but Streams would still route data through internal subscription topics. For a stream of lines, re-keying and a stream-table join is the natural fit.
7Conclusion
In this answer, we sized the catalogue at 40 GB with restarts several times a week and compared three enrichment options. A GlobalKTable is simple but puts 40 GB on every instance, makes new instances load everything first and joins without time synchronisation. A remote lookup is light but couples us to another service and changes replays. Re-keying order lines and joining with a partitioned KTable costs a repartition topic but spreads the state, restores quickly with persistent volumes and standbys, and joins by timestamp, so it is the recommendation here.
Open with
I would start from the numbers: 80 million products, about 40 GB, changing slowly, and instances restarting several times a week, so restore time is a weekly cost.
Then, if they want more
A GlobalKTable is the simplest code, no repartitioning, but every one of the six instances holds the full 40 GB, a new or rebuilt instance has to read the whole product topic before it processes anything, which can take many minutes, and the lookups are not time-synchronised, so replays can join old lines with current products and product updates never trigger results.
A remote lookup keeps instances light and current, but every line costs a network call, our availability depends on the product service, and replays see today's data; it needs caching, timeouts and back-pressure.
The partitioned option re-keys order lines by product id, which adds a repartition topic and maybe another to key back by order, but each instance holds about a sixth of the catalogue, restores only its partitions, and joins are synchronised by timestamp.
With these numbers I would choose the KTable join, with persistent volumes, one standby replica and explicitly named internal topics, and keep GlobalKTable for small reference data like currencies or country codes.
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 "Compare a GlobalKTable, a KTable join after re-keying by product id, and a remote lookup...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-streams-connect/9b8bc1fa53/