Quick revision
The short answer
The rule is that single message transforms may only do cheap, stateless, per-record shaping such as renaming, masking, routing, casting, flattening and filtering with predicates; anything with I/O, state, joins or business rules moves to a stream processor or an owned service. The HTTP lookups move into Kafka Streams or Flink jobs that write enriched topics, the in-memory dedup set is replaced by idempotent upserts in the sink, and the migration is tracked per connector with owners and dates while config review blocks new violations.
What to remember
In this answer, we traced both incidents to Connect's design: transforms run synchronously on the task thread, so a slow lookup stalls the connector, and they keep no durable state, so an in-memory dedup set is lost on restart and blind across tasks. We set the rule that transforms only do cheap, stateless shaping, moved enrichment into stream processors writing enriched topics, replaced dedup with upserts, preferred built-in transforms, and tracked the migration with owners while config review blocks new violations.
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.
The rule is that single message transforms may only do cheap, stateless, per-record shaping such as renaming, masking, routing, casting, flattening and filtering with predicates; anything with I/O, state, joins or business rules moves to a stream processor or an owned service. The HTTP lookups move into Kafka Streams or Flink jobs that write enriched topics, the in-memory dedup set is replaced by idempotent upserts in the sink, and the migration is tracked per connector with owners and dates while config review blocks new violations.
Why this question is asked
Custom transforms are tempting because they let a team add one small feature to a connector without building a service. Thirty of them later, the integration platform depends on code nobody owns, and the incidents described here are the predictable result. Interviewers ask this scenario to see whether we can explain the failures from Connect's design rather than blame individual teams, and whether we can migrate thirty pieces of running code without breaking the pipelines that use them. In this answer, we will explain why each incident happened, state the rule, plan the migration for each kind of transform, and set up the controls that keep the rule in place.
1Why the Lookup Stalled the Connector
A single message transform runs synchronously, once per record, on the connector task's own thread. The task cannot hand the next record to Kafka until the transform returns. So when the customer lookup service slowed from 5 ms to 500 ms per call, each task dropped from hundreds of records per second to two, the connector fell hours behind, and from the outside it looked as if the connector had stalled.
Worse, the transform's behaviour on a failed call decides what happens to the data. If it throws, the record fails the transform stage; with errors.tolerance=all it is silently skipped, and with the default the task fails. If it catches the error and continues, records go out without the enrichment. None of these is a good outcome, and none is visible in the connector's configuration.
2Why the In-Memory Dedup Can Never Be Correct
The dedup transform keeps a set of record ids it has seen and drops repeats. Here is the essence of it.
The set lives in one task's memory. When a worker restarts or a rebalance moves the task, the set is gone, and Connect redelivers records since the last committed offset, exactly the duplicates the set was meant to catch. And with several tasks, each holds a separate set, so a duplicate handled by another task is never seen. Duplicates after restarts are therefore not a bug in the code but a consequence of putting state where Connect provides none.
3Setting the Rule
I would state the rule in one sentence and back it with a short list of what is in and out, published for all teams. Transforms may do cheap, stateless, per-record shaping. Anything that performs I/O, keeps state, joins data or applies business rules belongs in a stream processor or an owned service.
| Job | In a transform? | Where instead |
|---|---|---|
| Rename, mask, route, cast fields | Yes | built-in transforms |
| Flatten nested JSON into columns | Yes | Flatten, or a tested custom transform |
| Filter records | Yes | Filter with a predicate |
| Look up customer data over HTTP | No | Kafka Streams or Flink enrichment job |
| Drop duplicates | No | idempotent upserts in the sink |
| Apply business rules | No | owned service or stream processor |
Alongside the rule, we prefer built-in and well-maintained transforms over custom code. Kafka ships transforms for most shaping needs, including Flatten for nested structures. Where a custom transform is still justified, it must have tests, a version, a performance check against a records-per-second target, and it ships as a plugin in the curated worker image, not as a jar a team drops on a worker.
4Migrating Enrichment to a Stream Processor
For each lookup transform, we build a Kafka Streams or Flink job that reads the raw topic and writes an enriched topic. Instead of calling the customer service per record, the job joins against a customer table built from a topic of customer changes, so lookups are local and a slow service no longer slows the pipeline. The sink connector then reads the enriched topic and keeps only shaping transforms.
We migrate one connector at a time. The new job runs in parallel and writes the enriched topic while the old connector keeps running; we compare the two outputs for a few days, then point the sink at the enriched topic and remove the lookup transform. Each step can be rolled back by switching the topic back.
- Before: source -> connector with HTTP lookup SMT -> sinkone slow service stalls the task
- After, step 1: raw topicwritten by the source connector, shaping only
- After, step 2: enrichment jobKafka Streams or Flink joins a customer table
- After, step 3: enriched topiccontract with consumers
- After, step 4: sink connectorupserts on a business key, no custom state
5 layers, from the top down. Step through them one at a time.
5Replacing Dedup With Idempotent Writes
The dedup transform tried to stop duplicates from reaching the target. The reliable approach is to let duplicates arrive and make them harmless: the sink writes with upserts on a business key, so a repeated record updates its row to the same values.
For targets that cannot upsert, such as an append-only file store, the dedup belongs in a stream processor with durable state, or in the query layer that reads the files. The nested-JSON reshaping transforms are the easiest group: most can be replaced by the built-in Flatten plus Cast and ReplaceField, and the rest kept as tested custom transforms that obey the rule.
6Tracking the Migration and Holding the Line
I would list all 30 transforms in a tracker with the connector, owning team, category (shaping, lookup, dedup, business rule), target replacement and a date. Teams get support from the platform team, a deadline, and a clear reason in terms of the incidents they already lived through. New custom transforms that break the rule are blocked at config review: the pipeline that applies connector configs rejects transform classes not on the approved list, so the rule does not depend on memory.
7Follow-up questions
Is a cache inside the lookup transform a reasonable fix?
It reduces calls but keeps every underlying problem: the first lookup for each key still blocks the task, a cache miss storm after a restart hits the service hard, stale entries go unnoticed, and the cache disappears with the task. A changelog-backed table in a stream processor gives the same speed with proper state.
What if a team cannot take on a stream processing job?
The platform can offer a template enrichment job, or run shared enrichment jobs for common lookups such as customer data, so teams only declare which topic and which fields they need.
How do you avoid duplicates during the cutover itself?
Because the sink writes upserts on a business key, records written by both the old and the new path during the switch simply update the same rows, so the cutover does not need to be perfectly timed.
8Conclusion
In this answer, we traced both incidents to Connect's design: transforms run synchronously on the task thread, so a slow lookup stalls the connector, and they keep no durable state, so an in-memory dedup set is lost on restart and blind across tasks. We set the rule that transforms only do cheap, stateless shaping, moved enrichment into stream processors writing enriched topics, replaced dedup with upserts, preferred built-in transforms, and tracked the migration with owners while config review blocks new violations.
Open with
I would set a simple rule: transforms may only do cheap, stateless, per-record shaping, like renaming, masking, routing, casting, flattening and filtering with predicates. Anything with I/O, state, joins or business rules belongs in a stream processor or an owned service.
Then, if they want more
Then I would explain the incidents in those terms, so it does not feel arbitrary. A transform runs synchronously on the task thread, so an HTTP lookup that slows down blocks the whole connector.
The in-memory dedup set lives in one task's memory; it is lost on restart or when the task moves, and it cannot see records handled by other tasks, so it can never be correct, which is exactly why duplicates appeared after restarts.
For the migration, enrichment moves into Kafka Streams or Flink jobs that read the raw topic, join against a customer table built from a topic, and write an enriched topic that the sink reads. Dedup is replaced by idempotent writes in the sink, such as upserts on a business key.
Reshaping nested JSON can mostly move to built-in transforms like Flatten, and any custom transform left must have tests, versioning and a performance check and ship in the curated worker image. I would track all 30 per connector with owners and dates, and block new rule-breaking transforms through config review.
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 "Incidents include a connector stalling when the lookup service slowed down and...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-streams-connect/5e23377f8f/