Scrivio Interview library
CodingFoundations5 min read · updated 13 November 2026

A source connector writes customer rows to topics named prod-db.public.customers.

Write the transforms section of the connector configuration so that tombstone records are dropped, records go to a topic named customers, the email field is masked, and an ingested_at field holding the record timestamp is added. In which order do the transforms run?

Chain four built-in transforms in the order transforms=dropTombstones,route,mask,stamp: a Filter guarded by the RecordIsTombstone predicate, a RegexRouter that rewrites prod-db.public.customers to customers, MaskField$Value on email, and InsertField$Value with timestamp.field=ingested_at. Transforms run one record at a time in exactly the order listed, so dropping tombstones first protects the later transforms from null values.

Why this question is asked

Single message transforms, or SMTs, are the small per-record functions Kafka Connect applies between a connector and Kafka. They are how we rename topics, hide personal data and add metadata without writing code, and the configuration syntax trips people up because the names, dollar signs and order all matter. Interviewers ask a coding question like this to see whether we can write a working chain and explain what each step does to a record. In this answer, we will recap how transforms and predicates are configured, write the full transforms section, follow one record through it, and look at why the order matters.

1A Quick Recap of Transforms and Predicates

A connector's transforms setting lists aliases, names we choose, separated by commas. For each alias we set transforms.<alias>.type to a transform class and add that class's own settings under the same prefix. Many built-in transforms come in two variants, $Key and $Value, depending on which part of the record they change.

A predicate is a condition attached to a transform. We list predicate aliases in predicates, give each a type, and then set transforms.<alias>.predicate=<predicate alias> so the transform applies only to records that match. Adding transforms.<alias>.negate=true applies it only to records that do not match. Kafka ships predicates such as RecordIsTombstone, TopicNameMatches and HasHeaderKey.

2Writing the Transforms Section

Here is the part of the connector configuration that does all four jobs. It sits alongside the connector's own settings in the same JSON body.

YAML
"transforms": "dropTombstones,route,mask,stamp",
"transforms.dropTombstones.type": "org.apache.kafka.connect.transforms.Filter",
"transforms.dropTombstones.predicate": "isTombstone",
"predicates": "isTombstone",
"predicates.isTombstone.type": "org.apache.kafka.connect.transforms.predicates.RecordIsTombstone",
"transforms.route.type": "org.apache.kafka.connect.transforms.RegexRouter",
"transforms.route.regex": "prod-db[.]public[.](.*)",
"transforms.route.replacement": "$1",
"transforms.mask.type": "org.apache.kafka.connect.transforms.MaskField$Value",
"transforms.mask.fields": "email",
"transforms.stamp.type": "org.apache.kafka.connect.transforms.InsertField$Value",
"transforms.stamp.timestamp.field": "ingested_at"

Filter on its own drops every record, which is why it is always combined with a predicate: here it drops only records that are tombstones, meaning a record with a key and a null value, which signals a delete. RegexRouter matches the whole topic name against the regex and replaces it with the replacement. Writing the dots as [.] makes them literal dots rather than any character, and (.*) captures customers, which $1 inserts.

MaskField$Value replaces the email field's value with the empty value of its type, an empty string for a string field, unless we set transforms.mask.replacement to a value of our own, such as "***". InsertField$Value with timestamp.field adds a field named ingested_at holding the Kafka record's timestamp. For a source connector that timestamp is whatever the connector set on the record; if a connector leaves it unset, the field may be null, so check what yours provides.

3Following One Record Through the Chain

Transforms run one record at a time, in the order listed in transforms, each one receiving the output of the previous one. Here is a customer row going through, and a delete event that never makes it past the first step.

Java
topic=prod-db.public.customers key={id:7} value={id:7, name:"Asha", email:"asha@example.com"} ts=1731400000000
dropTombstones -> unchanged (value is not null)
route -> topic=customers
mask -> value={id:7, name:"Asha", email:""}
stamp -> value={id:7, name:"Asha", email:"", ingested_at:1731400000000}
topic=prod-db.public.customers key={id:8} value=null
dropTombstones -> dropped; route, mask and stamp never see it
The chain in order
OrderAliasEffect
1dropTombstonesdrops records whose value is null
2routeprod-db.public.customers -> customers
3maskemail -> empty string (or the configured replacement)
4stampadds ingested_at from the record timestamp

With a schema-based converter, ingested_at is added to the schema as a timestamp; with schemaless JSON it is added to the map. In both cases the downstream topic is named customers.

4Why the Order Matters

Order matters in two ways. First, built-in transforms differ in how they treat a null value: some pass a tombstone through unchanged, while others expect a struct or map and can fail on null, depending on the transform and the Kafka version. Putting the tombstone filter first means mask and stamp only ever see records with a value, so we do not depend on those details.

Second, predicates and later transforms see the state left by earlier ones. If we added a TopicNameMatches predicate to the mask step, it would have to match customers, not prod-db.public.customers, because route has already run. A useful habit is to read the chain top to bottom as a pipeline and ask what each step receives.

One more consideration: dropping tombstones is right here only because nothing downstream needs deletes. If a sink must delete rows, or the topic is compacted and should remove deleted customers, we would keep tombstones and use negate=true on a predicate to skip the value-changing steps for them instead.

5Follow-up questions

How would you apply the mask only to some topics?

Add a TopicNameMatches predicate, for example predicates.isCustomers.type set to the TopicNameMatches class with pattern set to customers, and set transforms.mask.predicate=isCustomers. Remember that the predicate sees the topic name after any earlier RegexRouter has changed it.

Does masking at the connector make the data safe?

It keeps the email out of Kafka for this pipeline, which is good minimisation. But the source table still holds it, and other connectors reading the same table would need the same rule, so it works best as part of a policy enforced through config review.

What does negate=true do?

It inverts the predicate, so the transform applies only to records that do not match. For example, a transform with predicate isTombstone and negate=true runs on every record except tombstones.

6Conclusion

In this answer, we configured four built-in transforms in the order dropTombstones, route, mask, stamp: a Filter with the RecordIsTombstone predicate, a RegexRouter from prod-db[.]public[.](.*) to $1, MaskField$Value on email, and InsertField$Value adding ingested_at from the record timestamp. Transforms run one record at a time in the listed order, each seeing the previous one's output, so filtering tombstones first protects the later steps, and any predicate on a later step must match the renamed topic.

What to say in the interviewAbout 70 seconds aloud

Open with

I would set transforms to dropTombstones, route, mask, stamp, because transforms run one record at a time in exactly the order listed. dropTombstones is the Filter transform with a predicate: I declare predicates=isTombstone with type RecordIsTombstone and set transforms.dropTombstones.predicate to isTombstone, so only records with a null value are dropped. route is RegexRouter with regex prod-db[.]public[.](.*) and replacement dollar one, so the topic becomes customers; the bracketed dots make them literal. mask is MaskField dollar Value with fields=email, which replaces the email with the empty value of its type, an empty string, unless I set a replacement. stamp is InsertField dollar Value with timestamp.field=ingested_at, which copies the Kafka record timestamp into the value.

Then, if they want more

I put the tombstone filter first because the built-in transforms differ in how they handle null values, so mask and stamp should only see records that have a value. Also, any predicate on a later step sees the renamed topic, not the original one.

If I needed a transform to apply to only some records, I would attach a predicate, and negate=true inverts it.

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 "Write the transforms section of the connector configuration so that tombstone records...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-streams-connect/82e752c3f7/