Scrivio Interview library
DebuggingIntermediate7 min read · updated 13 November 2026

A JDBC sink connector writing orders to PostgreSQL shows task 2 FAILED with a trace containing BatchUpdateException and 'duplicate key value violates unique constraint'.

The connector has errors.tolerance=all and errors.deadletterqueue.topic.name=dlq-orders-sink, yet the task still failed and the DLQ is empty. Explain why, what you do now, and how you configure the connector to cope with such records.

Connect's errors.tolerance and dead letter queue cover failures in the converter and transform stages, plus records a sink task reports itself through ErrantRecordReporter; an exception thrown by the database inside SinkTask.put() still fails the task. To recover, we read the trace, fix the cause and restart the failed task, which resumes from the last committed offset of consumer group connect-<name>. To cope with such records, we make writes idempotent with upserts on the primary key, so redelivered rows no longer violate the unique constraint.

Why this question is asked

A failed sink task with an empty dead letter queue confuses many teams, because the configuration seems to say that bad records should be tolerated and parked. Interviewers ask this to see whether we know exactly which failures Connect's error handling covers, how to restart without losing or skipping data by accident, and how to design the sink so the problem does not come back. In this answer, we will look at the stages a sink record goes through, see why this error bypassed the DLQ, recover the task, skip a poison record if we must, configure the connector for idempotent writes, and set up the alert that should have fired.

1A Quick Recap of a Sink Record's Path

A sink connector's task receives records in stages. The worker's consumer fetches bytes from the orders topic. The converter turns those bytes into Connect data, a schema and a value. Single message transforms, small per-record functions, then run in order. Finally the worker calls the task's put() method with a batch, and the task writes it to PostgreSQL.

The errors.* settings attach to the first stages. errors.tolerance=all tells the worker to skip records that fail conversion or transformation instead of failing the task, errors.retry.timeout controls retries, and errors.deadletterqueue.topic.name sends those failed records to a topic with headers describing the error. The put() call is different: it is the connector's own code talking to an external system, and the framework cannot know whether an exception there means one bad record, a whole bad batch or a database outage.

Step throughWhich failures reach the DLQ
  1. Consumer fetches bytesfrom orders
  2. Converter fails?
    Yeserrors.tolerance applies: skip, DLQNocontinue
  3. Transform fails?
    Yeserrors.tolerance applies: skip, DLQNocontinue
  4. put() writes batch to PostgreSQLconnector code
  5. Exception in put()?
    Yestask FAILED unless the connector reports the recordNocommit offsets after flush

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

The duplicate key error happens in put(), outside the stages errors.tolerance controls.

2Why the Task Failed and the DLQ Stayed Empty

The BatchUpdateException with 'duplicate key value violates unique constraint' comes from the JDBC driver while the task executes an INSERT batch inside put(). Conversion and transformation succeeded, so the DLQ logic never saw a failure. The exception propagated out of put(), and the worker marked task 2 as FAILED.

Since Kafka 2.6, a sink task can call ErrantRecordReporter, which the framework provides, to report one specific record as bad; reported records go to the same DLQ and the task carries on. Whether a connector does this for database errors depends on the connector and its version, and for a batched INSERT it is not always possible to know which record in the batch failed. So we check the connector's documentation rather than assume. In this case it evidently did not report the record.

3Recovering the Task Now

First we read the full trace and find out why a key already exists. Common causes are a record redelivered after an earlier restart, two producers emitting the same order, or a table that already contained rows from a backfill.

Shell
curl http://connect:8083/connectors/orders-sink/status
# tasks[2]: state FAILED, trace: BatchUpdateException ... duplicate key value violates unique constraint "orders_pkey"
# after fixing the cause (here: switch to upserts, below)
curl -X POST 'http://connect:8083/connectors/orders-sink/restart?includeTasks=true&onlyFailed=true'
# task 2 resumes from the last committed offset of group connect-orders-sink
kafka-consumer-groups.sh --bootstrap-server b1:9092 --describe --group connect-orders-sink
# shows partition offsets and lag while it catches up

Notice that the task resumes from the last committed offset, not from the record that failed. Sink offsets are committed only after the connector has flushed, so the records between that commit and the failure are written again. With plain inserts, that redelivery can itself hit the same unique constraint, which is why restarting without a fix often fails again within seconds.

4Skipping a Poison Record if We Must

Sometimes one record is genuinely wrong and must be skipped. We stop the connector, move the consumer group's offset for that partition past the record, start again, and record what we skipped and why. With Kafka 3.6 or later we can do it through the Connect REST API.

Shell
curl -X PUT http://connect:8083/connectors/orders-sink/stop
curl -X PATCH -H 'Content-Type: application/json' http://connect:8083/connectors/orders-sink/offsets -d '{
"offsets": [{"partition": {"kafka_topic": "orders", "kafka_partition": 2},
"offset": {"kafka_offset": 48121}}]}' # resume after offset 48120
curl -X PUT http://connect:8083/connectors/orders-sink/resume
# older versions: with the connector stopped or deleted so the group is empty
kafka-consumer-groups.sh --bootstrap-server b1:9092 --group connect-orders-sink \
--reset-offsets --topic orders:2 --to-offset 48121 --execute

Skipping loses data in the target, so it needs a record of the order id and an owner who decides whether to reinsert it later.

5Configuring the Connector to Cope

The lasting fix is to make writes idempotent, meaning that writing the same record twice leaves the table the same as writing it once. With a JDBC sink that means upserts on the primary key instead of inserts.

Properties
# connector settings, shown as properties (the REST body holds the same keys as JSON)
connector.class=io.confluent.connect.jdbc.JdbcSinkConnector
topics=orders
insert.mode=upsert # INSERT ... ON CONFLICT (order_id) DO UPDATE on PostgreSQL
pk.mode=record_key # primary key taken from the Kafka record key
pk.fields=order_id
errors.tolerance=all # still useful for conversion failures
errors.deadletterqueue.topic.name=dlq-orders-sink
errors.deadletterqueue.context.headers.enable=true

Now a redelivered order updates its row to the same values instead of failing. The record key must hold the order id, so the producer must key by it. Field names differ between JDBC sink implementations, so check the documentation of the one you run.

6Alerting on Task State

The task probably sat failed for a while because monitoring checked only that the worker process was alive, and the worker was. A failed task does not restart by itself. We alert on task state from GET /connectors/{name}/status, or on the worker metric connector-failed-task-count, and on sink consumer lag for connect-orders-sink. Both would have paged within minutes.

7Follow-up questions

Why do sink connectors see duplicates even when nothing failed?

Sink offsets are committed periodically after a flush, not after every record. When tasks rebalance because a worker joins, leaves or is redeployed, or when a connector restarts, records after the last committed offset are delivered again. So a sink is at-least-once by design, and the target must tolerate repeats, which is why upserts or idempotent writes are the normal choice.

Would errors.tolerance=all hide database errors if the connector supported reporting?

If the connector reports failing records through ErrantRecordReporter, they would go to the DLQ and the task would continue. That keeps the pipeline moving, but a systematic problem could fill the DLQ quietly, so we alert on the DLQ's growth too.

Is restarting the whole worker a good way to recover a failed task?

No. It causes a rebalance of every connector on that worker and still does not fix the cause. Restarting only the failed tasks through the REST API is targeted and leaves healthy tasks running.

8Conclusion

In this answer, we saw that errors.tolerance and the dead letter queue apply to conversion and transformation failures and to records a connector reports through ErrantRecordReporter, while a database exception from put() fails the task. We recovered by reading the trace, fixing the cause and restarting only the failed task, which resumes from the last committed offset and rewrites some records. We skipped a poison record by moving the group's offset with the connector stopped, made writes idempotent with upserts on the record key, and alerted on task state rather than worker liveness.

What to say in the interviewAbout 80 seconds aloud

Open with

Connect's error handling covers the converter and transform stages, plus any record a sink task reports through ErrantRecordReporter. The duplicate key error came from the JDBC driver inside SinkTask.put(), after conversion and transforms succeeded, so errors.tolerance and the DLQ never saw it; the exception escaped put() and the task failed.

Then, if they want more

Whether a connector reports database errors per record depends on the connector and version, so I would check its docs. Right now I would read the full trace from the status endpoint, find why the key already exists, fix the cause, and then restart only the failed task with the restart endpoint using includeTasks and onlyFailed.

It resumes from the last committed offset of the consumer group connect- plus the connector name, so some records are written again, which is why the real fix is idempotent writes: insert.mode=upsert with pk.mode=record_key, so a redelivered order just updates its row.

If one poison record has to be skipped, I would stop the connector and move the group's offset past it, with the Connect offsets API on 3.6 or later or kafka-consumer-groups, and record what we skipped. Finally I would alert on task state or connector-failed-task-count, not just worker liveness, because a failed task never restarts by itself.

About this answer

Last updated
13 November 2026
Versions it names
Kafka 2.6, Kafka 3.6
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 "The connector has errors.tolerance=all and...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-streams-connect/47db6fe6b8/