> 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/runbooks/disaster-recovery.md).

# Disaster recovery

Failover procedure for disaster recovery with K2K.

This runbook covers failover from a source Kafka cluster to a standby target cluster when K2K has been replicating data continuously. For the business context, see [Use cases](https://docs.lenses.io/latest/k2k/use-cases.md#disaster-recovery).

## Prerequisites

Before a failover event:

* Pipeline with both source and sink replication stages — see [Topic selection and data routing](https://docs.lenses.io/latest/k2k/configuration-reference/topic-selection-and-data-routing.md)
* K2K replicator running and replicating selected topics to the standby cluster
* [Offset mapping](https://docs.lenses.io/latest/k2k/configuration-reference/offset-mapping.md) enabled with both `k2k` and `k2k-offset-mapping` deployed if applications must resume without reprocessing
* [Schema migration](https://docs.lenses.io/latest/k2k/configuration-reference/schema-migration.md) enabled if applications use Schema Registry
* [Observability](https://docs.lenses.io/latest/k2k/configuration-reference/observability.md) metrics and alerting configured for replication lag
* Failover drill completed using the [Validation checklist](https://docs.lenses.io/latest/k2k/runbooks/validation-checklist.md)

## Metrics to monitor

| Metric                  | What it tells you                                    |
| ----------------------- | ---------------------------------------------------- |
| Replication lag         | How far behind the standby is relative to production |
| Offset mapping progress | Whether target consumer groups are being translated  |
| Error rates             | Connection, produce, or commit failures              |

Alert on sustained lag growth or mapping stalls before a failover event occurs.

## Failover procedure

### 1. Confirm standby readiness

1. Check replication lag is within acceptable bounds for your RPO.
2. Verify replicated topics exist on the target with expected partition counts.
3. If using offset mapping, confirm target consumer group offsets are current:

```shell
k2k-tool describe -f my_pipeline.yml
```

### 2. Stop writes to the source cluster

Stop producers on the source Kafka cluster (or block traffic at the network layer). Allow K2K to drain remaining records.

### 3. Wait for lag to reach zero

Monitor until replication lag is zero and the offset mapper has translated the latest committed offsets.

### 4. Switch consumers to the target cluster

Update application configuration to point bootstrap servers at the target Kafka cluster. Consumer groups that were offset-mapped should resume from equivalent positions.

### 5. Validate applications

Confirm applications consume correctly from the target cluster. Check for schema compatibility issues if Schema Registry was replicated.

### 6. Keep K2K running (optional)

Leave K2K running if you plan to fail back once the source cluster is restored. For a permanent switch, proceed to decommission below.

## Rollback

If the target cluster has issues:

1. Stop consumers on the target cluster.
2. Redirect consumers back to the source cluster (offsets on the source are unchanged — K2K does not commit there).
3. Investigate using [Troubleshooting](https://docs.lenses.io/latest/k2k/configuration-reference/troubleshooting.md).

## When to use k2k-tool

Use [k2k-tool](https://docs.lenses.io/latest/k2k/k2k-standalone-tool.md) during failover preparation or investigation:

* `describe` — inspect committed offsets before cutover
* `set` — manually adjust offsets if a group was not offset-mapped
* `reset` — reset to earliest (use with caution)

{% hint style="danger" %}
Warning: Setting offsets should only be used when the K2K application has been stopped.

If the K2K application is running, the offset reset might not be applied as the application will continue to commit offsets, potentially overwriting the reset operation.
{% endhint %}

## Decommission source cluster

After a permanent failover:

1. Stop all K2K processes.
2. Confirm all applications run on the target cluster.
3. Decommission the source Kafka cluster per your infrastructure procedures.


---

# 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/runbooks/disaster-recovery.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.
