> For the complete documentation index, see [llms.txt](https://docs.lenses.io/latest/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lenses.io/latest/k2k/configuration-reference/exactly-once-delivery.md).

# Exactly once delivery

Guarantee each record appears once on the target cluster.

{% hint style="info" %}
This feature is **disabled by default**. Set the corresponding `features` toggle to `enabled` in your pipeline file for the behavior described on this page to take effect.
{% endhint %}

Kafka's consumer protocol delivers each message at least once—a crash between writing a record and recording progress creates duplicates. If the target Kafka cluster must be a faithful copy of the source Kafka cluster, replication needs stronger guarantees than fire-and-forget produce and consume.

Enable `features.exactlyOnce` so K2K tracks progress in control topics on the target Kafka cluster rather than committing offsets on the source Kafka cluster; see [Consumer group](https://docs.lenses.io/latest/k2k/configuration-reference/consumer-group.md). The target producer must use idempotent writes (`enable.idempotence` and `acks: all`). For multiple instances, see [Horizontal scaling](https://docs.lenses.io/latest/k2k/configuration-reference/horizontal-scaling.md). For commit batching, see [Commit tuning](https://docs.lenses.io/latest/k2k/configuration-reference/commit-tuning.md). For assignment and fencing, see the [Advanced](#advanced) section below.

## Prerequisites

* [License accepted](https://docs.lenses.io/latest/k2k/configuration-reference/licenses.md)
* [Kafka connectivity and authentication](https://docs.lenses.io/latest/k2k/configuration-reference/kafka-connectivity-authentication.md)
* [Consumer group](https://docs.lenses.io/latest/k2k/configuration-reference/consumer-group.md) configured
* [Topic selection and data routing](https://docs.lenses.io/latest/k2k/configuration-reference/topic-selection-and-data-routing.md) configured

## Example

Use the following pipeline configuration:

```yaml
name: "my_pipeline"
features:
  exactlyOnce: enabled
source:
  kafka:
    common:
      "bootstrap.servers": "source:9092"
    consumer:
      "group.id": "my-k2k-group"
target:
  kafka:
    common:
      "bootstrap.servers": "target:9092"
    producer:
      "enable.idempotence": "true"
      "acks": "all"
replication:
  - source:
      topic: "orders.*"
  - sink:
      topic: source
      partition: source
```

## Configuration keys

### Feature toggle

| Key                    | Description                     | Required | Default    | Used by    |
| ---------------------- | ------------------------------- | -------- | ---------- | ---------- |
| `features.exactlyOnce` | Exactly once delivery guarantee | No       | `disabled` | Replicator |

### Target producer settings

Exactly once requires an idempotent producer on the target Kafka cluster. K2K sets these by default; override them under `target.kafka.producer` if needed.

| Key                                          | Required value | Used by    |
| -------------------------------------------- | -------------- | ---------- |
| `target.kafka.producer."enable.idempotence"` | `true`         | Replicator |
| `target.kafka.producer."acks"`               | `all`          | Replicator |

## Advanced

### Control topics and assignment

Assignment keys enforce [exclusive assignment](https://docs.lenses.io/latest/k2k/glossary.md#coordination) so only one replicator instance actively processes a given source partition at a time.

The commit control topic is configured under [Consumer group](https://docs.lenses.io/latest/k2k/configuration-reference/consumer-group.md#control-topics). Control topic names can also be configured under `topicCreation.control` when [auto creating topics](https://docs.lenses.io/latest/k2k/configuration-reference/topic-creation.md).

| Key                                             | Description                                                         | Required | Default            | Used by    |
| ----------------------------------------------- | ------------------------------------------------------------------- | -------- | ------------------ | ---------- |
| `coordination.assignment.topic`                 | Control topic for exclusive assignment on the target Kafka cluster  | No       | `__k2k_assignment` | Replicator |
| `coordination.assignment.graceWindow`           | Wait time before fencing other instances                            | No       | `15 seconds`       | Replicator |
| `coordination.assignment.fencingMaxParallelism` | Max parallelism when fencing producers                              | No       | `5`                | Replicator |
| `coordination.commit.syncTimeout`               | Max wait when catching up on the commit control topic               | No       | `90 seconds`       | Replicator |
| `features.optimizeOffsetCommitPartition`        | Publish all control commit messages to a single partition per group | No       | `enabled`          | Replicator |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.lenses.io/latest/k2k/configuration-reference/exactly-once-delivery.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
