For the complete documentation index, see llms.txt. This page is also available as Markdown.

Topic selection and data routing

Which topics to replicate and how records are routed.

A replication pipeline must answer two questions: which topics to read on the source Kafka cluster, and where each record lands on the target Kafka cluster. Kafka has no built-in concept of cross-cluster routing, so K2K expresses this through a source stage and a sink stage in the pipeline.

Each pipeline has exactly one source stage (topic selection) and one sink stage (topic and partition assignment). See Replication stage in the Glossary. For header replication, see Header replication. If you use offset mapping, set partition: source so partition N on the source Kafka cluster maps to partition N on the target Kafka cluster

Prerequisites

Example

name: "my_pipeline"
source:
  kafka:
    common:
      "bootstrap.servers": "source:9092"
    consumer:
      "group.id": "my-k2k-group"
target:
  kafka:
    common:
      "bootstrap.servers": "target:9092"
replication:
  - source:
      topic: "orders.*"
  - sink:
      topic:
        prefix: "dr-"
      partition: source

Configuration keys

Source stage

Key
Description
Required
Default
Used by

replication[].source.topic

Topics to replicate (regex string or list of topic names)

Yes

(none)

Replicator

Sink stage

Key
Description
Required
Default
Used by

replication[].sink.topic

Target topic assignment strategy

Yes

(none)

Replicator

replication[].sink.partition

Target partition assignment strategy

Yes

(none)

Replicator

Both keys must be set explicitly — there is no implied default. Use source for either to preserve the source value.

Source topic selection

Regex. Provide a string to match topic names on the source Kafka cluster:

Topic list. Provide a YAML list of explicit topic names:

Data routing

The sink stage controls how each record read from the source Kafka cluster is written to the target Kafka cluster.

By default (topic: source, partition: source), a record from topic orders on partition 3 of the source Kafka cluster is written to topic orders on partition 3 of the target Kafka cluster. The topic name and partition number are preserved.

Other strategies rename topics, consolidate multiple source topics into one target topic, or change how partitions are assigned.

Sink topic strategies

Same name as source (topic: source):

Records keep the same topic name on the target Kafka cluster.

Static topic (all records to one topic):

All replicated records are written to target-topic-name on the target Kafka cluster, regardless of their source topic.

Prefix and/or suffix (transform source topic name):

A record from topic orders on the source Kafka cluster is written to prod-orders-replica on the target Kafka cluster.

Static mapping (route by source topic pattern). This controls routing only; which topics are replicated is defined by the source stage:

Sink partition strategies

Value
Behaviour

source

Same partition number as on the source Kafka cluster

producer

Partition chosen by the Kafka producer strategy on the target Kafka cluster

Last updated

Was this helpful?