Offset Translation Challenges in Kafka Replication

Offset Translation Challenges in Kafka Replication

When Kafka data is copied between clusters, the position numbers called offsets stop matching. This guide explains why that happens, how tools translate offsets, where the translation breaks down, and how to design failovers that survive it.

Imagine you are reading a thick novel and you leave a bookmark at page 212. Now a friend photocopies the whole book for you, but the copier skips a few blank pages, adds a few cover sheets, and starts copying only after chapter one was already gone. Your bookmark still says page 212, yet page 212 in the photocopy holds completely different words. Kafka replication between clusters has exactly this problem, and the bookmark is called an offset.

Most engineers meet this problem on the worst possible day: a data center fails, the team switches applications to the backup cluster, and the consumers either replay hours of old data or silently skip messages. This tutorial walks through the whole story slowly, from the basics of offsets to the advanced trade-offs of active-active designs, so you can plan for that day before it arrives.

1Why Anyone Replicates Kafka Across Clusters

Before we talk about the problem, we need to understand why teams accept it in the first place.

Apache Kafka is a system that stores streams of events, such as orders, payments, sensor readings, or clicks. A group of Kafka servers working together is called a cluster. A single cluster is usually placed inside one data center or one cloud region. That is fast and simple, but it also means the cluster is only as safe as the place it lives in.

Cross-cluster replication means continuously copying events from one Kafka cluster to another, often in a different building, region, or even cloud provider. It exists because some needs cannot be met by one cluster alone. A region can lose power, a legal rule can demand that data stay in one country, or users on another continent can demand faster reads.

Simple Analogy

Think of a library that keeps its rare books in one building. If the building floods, the books are gone. So the library opens a second building in another city and keeps sending copies of every new book there. The second building is your replica cluster, and the delivery truck is the replication tool.

The Main Reasons Teams Replicate

Reason 1

Disaster Recovery

A standby cluster in another region takes over when the primary region fails, limiting how much data and time is lost.

Reason 2

Geo-Locality

Applications read from a nearby cluster, so users in different continents get low delay without crossing oceans.

Reason 3

Data Aggregation

Many small regional clusters feed one central analytics cluster that sees the combined picture.

Reason 4

Migration

Moving from an old cluster to a new one, or from on-premises to cloud, without stopping the business.

Reason 5

Compliance and Isolation

Some data must be filtered or kept in specific places, so only a chosen subset of topics is copied.

Each of these reasons ends with the same practical question: when an application moves from the source cluster to the target cluster, where should it continue reading? Answering that question is called offset translation, and it is the heart of this guide.

i
Why This Matters

Replication is easy to celebrate when data flows. Its real test is the moment consumers must change clusters. A replication design that ignores offsets is only half a disaster recovery plan.

2Offsets From First Principles

An offset is just a number, but almost everything about reliable Kafka reading depends on it.

A Kafka topic is a named stream of events, such as a topic called payments. To allow many servers to share the work, a topic is split into partitions. A partition is an ordered, append-only log. New events are always added at the end and are never inserted in the middle.

Every event inside a partition receives a sequence number, starting at zero and growing by one. That number is the offset. The offset is unique only within one partition of one topic, so the full address of an event is the topic, the partition, and the offset together.

Simple Analogy

A partition is like a roll of numbered raffle tickets. Every new ticket gets the next number, and no ticket is ever renumbered. The offset is the number printed on the ticket. Two different rolls can both have a ticket number 50, and they mean different things.

Consumers, Groups, and Committed Offsets

A consumer is an application that reads events. Consumers usually work in a consumer group, a team of consumer instances that share the partitions of a topic so that each partition is read by only one member at a time. This lets you scale reading by adding more members.

To avoid rereading everything after a restart, the group records how far it has read. This progress marker is the committed offset, and it means the next event to read. Kafka stores committed offsets in an internal topic named __consumer_offsets, keyed by group, topic, and partition.

Term 1

Log End Offset

The offset that the next new event will receive. It marks the end of the partition today.

Term 2

Committed Offset

The position a consumer group saved as its progress, so it can resume after a restart.

Term 3

Consumer Lag

The gap between the log end offset and the committed offset. It shows how far behind a group is.

Term 4

Auto Offset Reset

A rule that tells a consumer where to start when no valid committed offset exists, either at the beginning or at the end.

That last term is important for our story. If a consumer group arrives at a new cluster and finds no committed offset, or an offset that makes no sense, it falls back to the reset rule. Starting at the beginning replays everything, and starting at the end skips everything that arrived before the consumer connected. Both are painful in production.

!
Common Misconception

People often assume an offset is a universal event ID. It is not. It is only a position inside one specific copy of one specific partition, and a second copy of the same data can assign different positions.

3Two Kinds of Replication That Behave Very Differently

The word replication hides two separate mechanisms, and only one of them keeps offsets identical.

Inside a Cluster: Follower Replication

Inside one cluster, every partition has a leader and several followers. Followers fetch the leader’s log byte by byte, so their copy is identical, including offsets. The set of followers that are fully caught up is called the in-sync replicas. When a leader fails, a follower is promoted, and consumers continue with the same offsets because the log is the same.

Between Clusters: Mirroring

Between two independent clusters, there is no built-in follower relationship. The replication tool acts as an ordinary consumer of the source cluster and an ordinary producer to the target cluster. It reads an event, then writes it as a brand-new event. The target cluster does not know the event has any history, so it hands out its own next offset.

Simple Analogy

Follower replication is a mirror in your bathroom: whatever is in front of it is reflected exactly. Cross-cluster mirroring is a scribe copying a diary by hand into a new notebook. The words are the same, but the page numbers depend on the handwriting, the blank pages, and when the scribe started.

AspectFollower ReplicationCross-Cluster Mirroring
How it worksFollowers fetch raw log segments from the leaderA consumer reads events and a producer writes them again
OffsetsIdentical on every replicaAssigned independently by the target cluster
ScopeOne cluster, usually one regionTwo or more clusters, often far apart
Failover effect on consumersTransparent, same offsetsNeeds offset translation
Transactions and markersPreserved inside the logNot preserved as they were
Typical delayMillisecondsTens of milliseconds to seconds or more

Because mirroring is a fresh write, three things can differ between the copies: the offset of each event, the presence of some events, and the layout of partitions. Offset translation exists to bridge the first difference, and it must survive the other two.

“A mirrored event is not a copy of a position. It is a new event that happens to carry the same content.”

4Why Offsets Diverge Between Clusters

Offsets rarely match, and the reasons are ordinary, not exotic.

It is tempting to believe that if you start replication on day one and nothing breaks, the offsets will match forever. In practice, several forces act on every real system, and any one of them is enough to break the match. Understanding each cause helps you predict how large the gap will be for your workload.

Cause 1

Late Start

If mirroring begins after the source topic already holds millions of events, the target starts numbering at zero while the source is far ahead.

Cause 2

Retention Trimming

The source deletes old events after its retention time. The first available offset moves forward, and the target may have trimmed at a different moment.

Cause 3

Log Compaction

Compacted topics keep only the latest value per key, leaving holes in the offset sequence that differ from one cluster to the other.

Cause 4

Transaction Markers

Commit and abort markers use up offsets on the source but are not copied as ordinary events.

Cause 5

Duplicates and Retries

A retried write without protection can create duplicate events on the target, making its offsets run ahead.

Cause 6

Filtering and Reconfiguration

Dropping events, changing partition counts, or recreating topics gives the target a different shape.

flowchart LR
  A["Source partition: offsets 0 to 9"] --> B["Mirror tool: consume then produce"]
  B --> C["Target partition: offsets 0 to 6"]
  A -. "aborted transaction, markers, compacted keys" .-> D["Events never copied one to one"]
  D -.-> C
        
FIG 1 — The same content ends up at different positions

The result is a mapping between two number lines. Source offset 500 might correspond to target offset 430 today and target offset 470 an hour later, because the gap between the two lines changes over time as markers appear or old data is deleted. The mapping is not a fixed formula, which is why tools must keep records of it while replication runs.

!
Common Mistake

Some teams copy the committed offset number straight from the source into the target group. This works only by luck and often lands on the wrong event, causing either duplicate processing or skipped data.

5The Anatomy of MirrorMaker 2

The open-source Kafka mirroring tool solves translation by keeping a running diary of how the two clusters line up.

MirrorMaker 2 is the mirroring framework shipped with Apache Kafka. It runs on Kafka Connect, which is a framework for moving data in and out of Kafka using pluggable workers called connectors. MirrorMaker 2 is made of three cooperating connectors, each with a narrow job.

Connector 1

Source Connector

Copies events from source topics into the target and also emits records that describe how source and target offsets line up.

Connector 2

Checkpoint Connector

Reads consumer group progress on the source and uses the alignment records to compute equivalent target positions.

Connector 3

Heartbeat Connector

Emits small periodic events so you can confirm that data really flows end to end and measure delay.

The Three Bookkeeping Topics

The tool keeps its notes in ordinary Kafka topics. The first is the offset-syncs topic, which stores pairs saying that source offset X was written as target offset Y. The second is the checkpoints topic, which stores, for each consumer group and partition, the last source position the group committed and the target position considered equivalent. The third is the heartbeats topic, which proves the pipeline is alive.

Remote topics also follow a naming convention. By default, a topic called orders on the cluster with alias primary appears on the target as primary.orders. The prefix records where the data came from and prevents infinite loops in two-way setups. Some deployments use an identity policy that keeps the original name instead, which is convenient for applications but removes that loop protection and requires extra care.

flowchart TD
  S["Source cluster topics and consumer groups"] --> M["Source connector"]
  M --> T["Remote topic on target cluster"]
  M --> O["Offset-syncs topic"]
  O --> C["Checkpoint connector"]
  S --> C
  C --> K["Checkpoints topic on target"]
  K --> F["Failover tools and group sync"]
        
FIG 2 — How alignment records flow through MirrorMaker 2
i
Good to Know

Where the offset-syncs topic lives is configurable, and newer releases allow placing it on the target side. Placement affects what happens when the source cluster is completely unreachable, so choose it deliberately.

6How Translation Actually Works, Step by Step

The translation is an estimate built from sparse sample points, and that design choice explains most of its limits.

Writing a mapping record for every single event would double the write volume and add heavy load, so MirrorMaker 2 does not do that. It records a sample point only occasionally. A sample point is a fact such as: source offset 1,000 became target offset 940. Between two sample points, the tool knows nothing exact.

Simple Analogy

Think of highway kilometer markers. If you know you passed marker 40 and marker 50 but not the exact moment between them, you can say you are somewhere between the two. If you must be safe, you assume you are at marker 40. Offset translation makes the same safe assumption.

1

The mirror writes an event and sometimes records a sample point

At the beginning and then whenever the source position has moved far enough since the last sample, the tool stores a source-to-target pair in the offset-syncs topic. A tunable lag threshold controls how far apart samples may be, with a default in the order of a hundred events.

2

The checkpoint connector reads the group’s committed position

On a regular timer, commonly around every minute, it looks at what each monitored consumer group has committed on the source cluster.

3

It finds the closest sample point at or before that position

The tool picks the newest sample whose source offset does not pass the group’s committed offset. Choosing an earlier point is intentional, because choosing a later one could skip unread events.

4

It publishes a checkpoint with the equivalent target offset

The result is stored in the checkpoints topic on the target, ready to be read by a failover procedure or applied to the target’s consumer group automatically.

5

The consumer group resumes on the target from the translated position

Because the estimate rounds backward, the group typically rereads a small window of events it already processed.

This produces an important property: translation is conservative and favors at-least-once delivery. You will usually see some duplicates after failover, but you should not see silent loss, provided the assumptions behind the sample points still hold. The rest of this guide is largely about the situations where that promise gets weaker.

Sparse
Sample points, not one record per event
Backward
Rounding direction to avoid data loss
At-least-once
Delivery guarantee after a failover

A Worked Example With Real Numbers

Numbers make the idea stick, so let us walk through a small, invented example. A topic partition on the source cluster holds events from offset 0 upward. The mirroring tool started late, when the source already had 5,000 events. It began copying from the oldest event it could still read, and the target started numbering from zero. For simplicity, imagine the source had trimmed everything below offset 5,000, so the first mirrored event is source offset 5,000 and target offset 0.

Sample PointSource OffsetTarget OffsetWhy It Was Recorded
Sample A5,0000First event ever copied
Sample B5,120118Two markers were skipped along the way
Sample C5,260256Several compacted or aborted events were absent
Sample D5,400392The gap widened again

Now suppose a consumer group has committed source offset 5,300. The checkpoint connector searches for the newest sample whose source offset does not exceed 5,300. That is Sample C, at source offset 5,260, which maps to target offset 256. The checkpoint therefore says: for this group, resume the target partition at about offset 256. The real equivalent of source offset 5,300 might be target offset 294, but the tool cannot know that exactly. The group will process roughly forty events twice, and nothing is skipped.

Notice how the difference between the two number lines changed across the samples: it was 5,000 at the start, then 5,002, then 5,004, then 5,008. A growing difference signals that the source contains offsets the target does not. If you copied the raw number 5,300 into the target, you would land far beyond the end of the partition, since the target might only have a few hundred events. Depending on the reset rule, the group would either fail or jump to the end.

i
Reading the Example

The difference between source and target offsets is a useful health signal. If it jumps suddenly, something changed, such as a topic recreation, a large abort, or a mirror restart from a different position.

7Challenge One: Sample Granularity and the Duplicate Window

The sparser the samples, the larger the replay after failover.

Suppose sample points exist at source offsets 1,000 and 1,100. A group has processed up to offset 1,099 when the disaster hits. Translation can only use the sample at 1,000, so the group restarts on the target at the equivalent of 1,000. It will process about a hundred events a second time. With a small threshold, the duplicate window is small, but the extra bookkeeping traffic grows.

The duplicate window has a second cause that is easy to forget: timing. Checkpoints are calculated on a timer. If the checkpoint was written a minute ago and the group has advanced since, the translated position reflects the old state. In a busy topic processing thousands of events per second, one minute of staleness can mean tens of thousands of extra replayed events.

Source of ReplayWhat Controls ItTypical Effect
Sample spacingOffset lag thresholdUp to one spacing of events replayed
Checkpoint stalenessCheckpoint emit intervalEvents processed since the last checkpoint
Group commit delayHow often the consumer commitsEvents processed but not yet committed
Replication lagMirror throughput and networkEvents not yet on the target at all

Idempotent Consumers Turn Replay Into a Non-Event

If the consuming application can detect an event it has already handled, using a business key or a unique event identifier, then a replay of a few thousand events causes no harm. This is the most robust defense against every kind of translation inaccuracy.

i
Design Tip

Measure your acceptable replay window in seconds of business time, not in offsets. Then tune the sampling threshold and checkpoint interval to fit it, and confirm with a drill.

The Tuning Trade-off

Every tuning knob in this area moves cost from one place to another. Shrinking the sample spacing gives finer translation but produces more bookkeeping records. Shortening the checkpoint interval keeps checkpoints fresh but makes the checkpoint connector read consumer group state more often, which adds load on the source cluster, especially when hundreds of groups are monitored. Frequent automatic group syncing adds write traffic to the target cluster’s internal offsets topic.

Tighter Settings Give

  • Smaller replay after failover
  • Fresher checkpoints for automation
  • More confidence in recovery time estimates
  • Earlier detection of a stuck connector

Tighter Settings Cost

  • More bookkeeping records and storage
  • More read load on the source’s group metadata
  • More write load on the target’s offsets topic
  • More sensitivity to brief network hiccups

A sensible approach is to start with defaults, measure real replay in a drill, and tighten only when the measured window is larger than the business accepts. Teams with thousands of consumer groups often restrict monitoring to the groups that truly matter, using include and exclude patterns, so the checkpoint work stays affordable.

8Challenge Two: Replication Lag and the Missing Tail

Translation can only point at data that actually reached the target.

Mirroring is asynchronous. The source acknowledges a write to its producer before the mirror has copied it. If the source cluster fails, the newest events that had not yet crossed the network are lost from the target’s point of view. This is a data-loss question, not a translation question, but it affects translation in a subtle way.

A consumer group on the source may have already read and processed events that never reached the target. After failover, the checkpoint for that group points to the last sample that exists on the target. The group will continue from there, but the events in the missing tail are gone. Downstream systems that already saw them, such as a database updated by the consumer, may now hold facts that the target cluster has never recorded.

Simple Analogy

A cashier rings up sales and a runner carries receipts to head office every few minutes. If the shop burns down, the receipts still in the cashier’s hand are lost, even though customers already walked away with their goods. Head office has a slightly old view of the world.

What This Means for Recovery

The gap between what the source had and what the target received is measured as replication lag. It equals the recovery point, the amount of business data you can lose in a disaster. Offset translation cannot shrink this gap. Only faster or more parallel replication, better network paths, or synchronous designs can. Therefore, a good failover plan states two different numbers: how much data may be missing, and how much data may be replayed.

Advantages of Asynchronous Mirroring

  • Producers on the source are not slowed by distant networks
  • A failing target never blocks the source
  • Works across regions, clouds, and unreliable links
  • Simple to reason about and operate

Trade-offs

  • A tail of recent events can be lost in a hard failure
  • Source and target states are never perfectly in step
  • Downstream side effects may exceed what the target recorded

9Challenge Three: Compaction, Retention, and Holes in the Line

A partition’s offset line is not always a solid line. Sometimes it has gaps.

Kafka topics use one of two cleanup styles. Delete-style topics remove whole old segments after a time or size limit. Compacted topics keep only the latest event for each key and remove older ones in the background. In both cases, offsets are never reused, so the surviving events keep their old numbers and the sequence develops holes.

Compaction Makes Alignment Harder

On a compacted topic, the source and the target run their cleanup independently, at different moments, with different amounts of data to compact. A given key might already be reduced to its latest value on the source while the target still holds several older versions, because the mirror copied them before compaction ran. The two logs therefore contain different numbers of events for the same time period, and the distance between equivalent offsets keeps shifting.

Sample points remain valid for the moments they were recorded. The trouble appears when a group’s committed offset points into a region that has since been compacted away, or when the group’s position falls between two sample points across a large hole. The estimate is still safe in the backward direction, but the replay could be much larger than the number of live events suggests.

ANTI-PATTERN-01 Avoid
Problem

A team treats a compacted topic as a stream of changes and expects the target’s event count to equal the source’s event count.

Why It’s Harmful

Compaction removes intermediate versions at different times in each cluster, so event counts, gaps, and offsets differ. Monitoring alerts based on equal counts fire constantly, or worse, hide real loss behind noise.

Correct Approach

Compare the final state per key rather than the number of events. Use consumer logic that only cares about the latest value, and monitor replication lag instead of count equality.

Retention Mismatch

If the target keeps data for a shorter time than the source, a group that was far behind on the source may translate to a position that the target has already deleted. The consumer then hits an out-of-range error and falls back to its reset rule, replaying everything or skipping to the end. Always make the target’s retention at least as long as the source’s for topics whose consumers might lag.

!
Watch Out

Topic configuration is not always copied automatically or kept in sync. Drift in retention, compaction, or timestamp settings between clusters is a quiet source of failover surprises.

10Challenge Four: Transactions and Control Records

Exactly-once on one cluster does not automatically survive a trip to another.

A Kafka transaction lets a producer write to several partitions and make all writes visible together or not at all. When the producer commits or aborts, the cluster writes a small control record, called a marker, into each partition involved. Markers take up offsets, but consumers never see them as data. That is one reason source offsets can jump by more than the number of visible events.

Simple Analogy

Picture a notebook where the teacher sometimes writes a stamp that says approved or cancelled on its own line. Students never copy the stamp lines into their own notebook, but the stamp lines still count as line numbers in the original.

What Changes During Mirroring

The mirroring tool reads events and writes them as ordinary events. It does not recreate the original transaction boundaries or markers on the target. Which records it reads also depends on how its consumer is configured. A consumer that only reads committed data skips events from aborted transactions entirely. A consumer that reads everything copies them as if they were normal, which could expose data that the source considered cancelled. Either choice moves target offsets away from source offsets.

Effect 1

Offset Shift

Markers and skipped aborted events create a steadily growing difference between source and target numbers.

Effect 2

Lost Atomicity

A group of events that were visible together on the source may appear on the target in separate moments.

Effect 3

Weaker Exactly-Once

End-to-end exactly-once processing is guaranteed only inside a single cluster’s protocol, not across mirrored copies.

The practical lesson is to treat cross-cluster failover as an at-least-once world even if your applications use transactions locally. Design consumers to tolerate replays and, when strict correctness matters, keep a durable record of processed identifiers outside Kafka. Also consider the isolation level of the mirror’s own consumer as a deliberate design decision, not a default you never looked at.

i
Design Tip

Write down, per topic, whether it carries transactional data. Topics with transactions need a documented decision about aborted events, and a drill that proves the target behaves as expected.

11Challenge Five: Consumer Group State and Timing Traps

Even a correct translation is useless if it lands at the wrong moment.

Checkpoints only tell you where a group could resume. Something still has to apply that position to the group on the target cluster. There are two common ways. In the first, an operator or script reads the checkpoints during failover and sets the group’s position before the applications start. In the second, the mirroring tool can automatically write the translated positions into the target’s committed offsets on a schedule, if that feature is enabled. It is not enabled by default in many versions, so check your release.

The Active Group Rule

Automatic synchronization generally refuses to overwrite a group that is actively running on the target. This protects a live group from having its position yanked backward. The consequence is a trap: if some instance of your application already started on the target for testing, or was started too early during the incident, the automatic sync may stop updating that group. Later the group begins from whatever position it created for itself, not from the translated one.

1

Stop all consumers on the target that share the group name

Confirm the group is empty so that offsets can be safely written.

2

Read the newest checkpoint for each partition

Check its age. A stale checkpoint means a larger replay window than you planned for.

3

Apply the translated positions to the target group

Do this for every partition and verify the result before restarting anything.

4

Start the applications and watch lag and error rates

Expect a short burst of replay, then a normal drain to zero lag.

Group Names and Topic Names

Translation is keyed by group name and topic name. If the target’s topic carries a source prefix, consumers must subscribe to the prefixed name after failover, and the translated positions apply to that name. If applications hard-code the original topic name, they will connect to an empty or different topic. Many teams solve this with subscription patterns that match both the local and the prefixed topics, so the same application works in both places.

!
Common Mistake

Teams sometimes rename the consumer group on the target to avoid confusion. That discards the translated checkpoints, because they were recorded under the old group name.

12Challenge Six: Partitions, Keys, and Ordering

Offsets belong to partitions, so anything that changes partitions changes the whole translation problem.

Offsets are per partition, and translation maps a source partition to a target partition with the same number. This assumes the target topic has the same partition count as the source. If the counts differ, one source partition would have to feed several target partitions, and there is no single target offset that corresponds to a source position.

Simple Analogy

Imagine a supermarket with five checkout lanes and a customer standing at position seven in lane three. If the new store has eight lanes and reassigns customers by a different rule, position seven in lane three no longer means anything.

Partitioners and Key Ordering

Events with the same key normally go to the same partition, which is how Kafka preserves order per key. The mirroring tool by default keeps events in their original partition numbers. If a team changes it to re-partition using keys on the target, the per-key order may still hold, but the partition-to-partition mapping that translation depends on is lost. Any design that repartitions during mirroring must give up the standard offset translation and rely on timestamps or business keys instead.

Growing Partitions Later

Adding partitions to a topic on one cluster but not the other changes where new keys land and breaks the one-to-one mapping. Any partition count change should be planned as a coordinated operation on both clusters, followed by a fresh alignment check.

Recreating a Topic

If a topic is deleted and recreated on the source, its offsets restart from zero. Old sample points now describe a topic that no longer exists. The mirror must be reset and old checkpoints must be treated as invalid.

i
Design Tip

Treat partition count as part of the replication contract. Put it into your topic provisioning process so that both clusters are always created with the same number.

13Challenge Seven: Active-Active, Failback, and Reverse Translation

Failing over is only half the journey. Getting back is where most plans fall apart.

In an active-passive design, one cluster serves traffic and the other waits. After a failover, the old primary is behind, because it missed everything written during the outage. Returning to it is called failback. It requires replication in the opposite direction and translation from the new primary’s offsets back into the old primary’s offsets. Every difficulty we have discussed now applies a second time, in reverse.

In an active-both design, applications on both sides produce to their local clusters and each cluster mirrors to the other. Each mirrored topic appears with a source prefix on the far side, and consumers that need the global view read both the local topic and the prefixed remote topic. This layout avoids replication loops, since a prefixed topic is never mirrored back to where it came from.

sequenceDiagram
  participant App as Consumer application
  participant A as Cluster A primary
  participant B as Cluster B standby
  App->>A: Reads and commits offsets
  A->>B: Mirror events and alignment records
  Note over A: Region failure
  App->>B: Failover using translated offsets
  B->>B: New events written locally
  Note over A: Cluster A recovers
  B->>A: Reverse mirror from failover point
  App->>A: Failback using reverse translation
        
FIG 3 — Failover and failback need translation in both directions

The Split Brain of Offsets

If both clusters accept writes for the same logical stream during a network split, they create two different histories. When the link returns, merging them is not an offset problem but a business problem. Events may conflict, and no offset translation can decide which is right. Active-active designs therefore work best when data ownership is clear, for example, each region owns its own customers, and the other region only reads.

ANTI-PATTERN-02 Avoid
Problem

The team plans failover carefully but has no rehearsed plan for failback, and simply keeps running on the backup cluster indefinitely.

Why It’s Harmful

The backup was sized and configured as a standby. Running production there for months without reverse replication leaves the original cluster stale and turns a temporary state into an unplanned permanent one.

Correct Approach

Treat failback as a first-class scenario. Configure reverse replication, test reverse translation, and schedule a rehearsed return during a low-traffic window.

14Older Behavior, Newer Improvements, and Version Awareness

Translation behavior has changed across releases, so the version you run matters.

Offset translation in MirrorMaker 2 has been improved several times since its introduction. Early versions could translate reliably only for consumer positions at or after the most recent sample point. A group that was lagging well behind the newest sample could fail to get a usable checkpoint. Later releases keep more history of sample points so lagging groups can be translated too. Other improvements added automated syncing of group positions, more flexible placement of the bookkeeping topics, and identity naming policies.

Because these details change, the safest approach is to read the release notes and configuration reference of the exact Kafka version you run, then test the behavior in a staging environment with a deliberately lagging consumer group. Never assume that a blog post, including this one, describes your version’s defaults.

!
Version Warning

Defaults for automated group syncing, sample spacing, and topic placement have differed between releases. Verify them rather than relying on memory, and write the verified values into your runbook.

15Strategies Beyond Standard Offset Translation

If translated offsets are too coarse for you, there are other ways to choose a safe restart point.

Option 1

Timestamp-Based Reset

Kafka can look up the earliest offset whose timestamp is at or after a given time. After failover, restart the group a few minutes before the failure time. It ignores offset differences entirely.

Option 2

Offset-Preserving Replication

Some commercial platforms offer linking features that copy the log so target offsets equal source offsets. This removes translation, but ties you to that product and its rules.

Option 3

Timestamp Interceptors

Certain replication products record consumption timestamps so the group can be translated by time, at the cost of specific client requirements.

Option 4

Application-Level Idempotency

Store processed event identifiers in your own database, so any replay is detected and skipped regardless of offsets.

ApproachPrecisionMain CostBest When
Standard translationApproximate, replays a windowBookkeeping topics and timersOpen-source stack, tolerant consumers
Timestamp resetDepends on clock qualityManual step and safety marginSimple recovery, fallback plan
Offset-preserving linkExact positionsVendor dependencyStrict recovery needs and budget
Idempotent consumersExact effects despite replayDesign and storage effortMoney, inventory, or audit data

Timestamp-based recovery deserves a special note. It relies on the timestamps stored inside each event. If the topic is configured to use the time the event was appended to the log instead of the time the producer created it, then the mirror’s write time replaces the original time, and the timestamps reflect the copy moment. Check the timestamp setting and ensure it is consistent on both clusters before relying on this method.

i
Practical Advice

Use the strategies in layers. Let standard translation get you close, keep timestamp reset as a manual backup, and make consumers idempotent so that neither one needs to be perfect.

16Monitoring, Logging, and Metrics for Offset Health

You cannot trust a failover plan that you cannot measure.

Translation quality is invisible until you need it, which is why monitoring must check it in advance. The goal is to answer three questions at any moment: is data flowing, how far behind is it, and are checkpoints fresh enough to be useful?

Signal 1

Replication Latency

The time between a write on the source and its arrival on the target. Heartbeat events make this easy to measure end to end.

Signal 2

Checkpoint Age

How long since each monitored group’s checkpoint was refreshed. Old checkpoints mean large replay after failover.

Signal 3

Record Age at Target

The difference between the newest event’s timestamp and the current time. It shows the real recovery point.

Signal 4

Connector Health

Task failures, restarts, and rebalances in the workers that run the mirroring connectors.

Signal 5

Bookkeeping Topic Health

Growth, retention, and availability of the offset-syncs and checkpoints topics themselves.

Signal 6

Configuration Drift

Differences in partitions, retention, compaction, and timestamp type between paired topics.

Logging That Helps During an Incident

Log every failover step with the group name, partition, source position, translated position, and the age of the checkpoint used. After the incident, these logs let you estimate how many events were replayed and confirm whether anything was missed. Also record who applied the positions and when, because manual steps are the most common place for human error.

Rehearsals as a Metric

Schedule regular failover drills and record how long each takes, how many events were replayed, and what surprised the team. The trend across drills is the best single indicator of whether your offset strategy is healthy. A plan that has never been rehearsed is only a hope.

Keeping the Bookkeeping Topics Healthy

The offset-syncs and checkpoints topics are easy to forget because they are internal. Yet they are the memory of the whole translation system. If the offset-syncs topic loses its recent data because of aggressive retention, the checkpoint connector may lose the samples it needs. If the checkpoints topic is deleted, every group loses its translated position until new checkpoints are produced, which can take a full interval or more.

Give these topics enough replicas, sensible retention, and proper alerts. Include them in backup and configuration management, and never let cleanup scripts delete them by accident. When the source cluster is the home of the offset-syncs topic, consider what happens if that cluster disappears entirely, because the samples you need at failover time would then be unreachable.

Lag
How much data could be missing
Age
How stale the translated offsets are
Drills
Proof the plan works in practice

Replication tools hold powerful keys to two clusters at once.

A mirroring deployment connects to both clusters with credentials that can read many topics on one side and write many topics on the other. If those credentials leak, an attacker gains wide access. Treat the replication identity as a high-value account with the smallest set of permissions that still works, and give it separate credentials from ordinary applications.

Control 1

Least Privilege Access Rules

Allow read only on the source topics that must be copied and write only on the target’s remote topics and bookkeeping topics.

Control 2

Encryption in Transit

Cross-region traffic crosses networks you do not own, so use encrypted connections with verified certificates.

Control 3

Checkpoint Topic Protection

Whoever can write to the checkpoints topic can influence where consumers restart. Restrict write access tightly.

Control 4

Data Residency Review

Before copying a topic to another country or provider, confirm that the data may legally leave its home region.

The checkpoints topic deserves extra attention. It looks harmless, but a tampered checkpoint could push a group far backward, causing a large replay of sensitive events, or far forward, causing loss. Treat it as control data, monitor unexpected changes, and audit who applies translated positions.

18Design Patterns That Work

Teams that survive failovers tend to share a handful of habits.

Pattern: Assume Replay, Design for It

Accept at-least-once as the cross-cluster reality. Make every consumer side effect safe to repeat, and treat translated offsets as a starting point rather than a promise of exactness.

Pattern: Uniform Topic Contracts

Create topics on both clusters from the same definition, with identical partition counts, timestamp type, and compatible retention, so drift cannot creep in.

Pattern: Dual Subscription

Let applications subscribe to both the local topic name and the prefixed remote name so the same build works on either cluster.

Pattern: Failover Runbook With Verification

Write every step, including how to check that groups are empty, how to inspect checkpoint age, and how to verify applied positions before restarting applications.

Pattern: Time-Based Safety Margin

When restarting by timestamp, subtract a deliberate margin, such as several minutes, and rely on idempotent processing to absorb the extra replay.

ANTI-PATTERN-03 Avoid
Problem

Consumers are configured to reset to the latest position whenever their committed offset is missing, and this is left unchanged in the disaster recovery cluster.

Why It’s Harmful

If translation fails or the group name mismatches, consumers silently jump to the end and skip everything that arrived before they connected. Nobody sees an error, only missing business data.

Correct Approach

For critical consumers, prefer a reset rule that fails loudly or starts early, together with idempotent processing. A visible replay is easier to fix than an invisible gap.

ANTI-PATTERN-04 Avoid
Problem

Checkpoints are trusted without checking their age, and the team assumes the translated offset reflects the group’s latest progress.

Why It’s Harmful

If the checkpoint connector was stuck or the source was unreachable for a while, the checkpoint may be very old, and the replay window could be hours, not seconds.

Correct Approach

Alert on checkpoint age and include an age check in the failover runbook. If the checkpoint is too old, choose the timestamp-based fallback.

19Best Practices and Common Mistakes

A short checklist can prevent most painful surprises.

Best Practices

  • Match partition counts and timestamp settings on both clusters
  • Keep target retention at least as long as the source’s
  • Decide the mirror consumer’s isolation level on purpose
  • Alert on replication latency and checkpoint age
  • Keep consumer group names identical across clusters
  • Rehearse failover and failback on a regular schedule

Common Mistakes

  • Copying raw offset numbers between clusters
  • Renaming groups during failover
  • Starting applications on the target before syncing positions
  • Ignoring compacted topics when comparing counts
  • Planning failover but never failback
  • Assuming defaults are the same across versions
i
A Simple Rule of Thumb

If a step in your failover plan starts with the word assume, turn it into a test. Every assumption about offsets that has not been checked by a drill is a possible outage.

20Real-World and Industry Context

The same pressures appear across very different industries.

Cross-cluster mirroring has been a core need almost since Kafka became popular. The original MirrorMaker tool was a simple consumer-producer pair with no offset translation. It worked for moving data but left consumers with no help at failover. Large companies built their own replicators to cope, and the open-source community later designed MirrorMaker 2 to add topic and configuration syncing, offset translation, and heartbeats. Commercial vendors also offer their own replication and linking products with different trade-offs.

Payments and Banking

Recovery point and duplicate handling are both strict. Teams pair mirroring with idempotent processing and a documented cap on acceptable data loss, and they rehearse failover regularly because auditors ask for evidence.

Online Retail

Order and inventory events flow between regions. A small replay is tolerable if stock updates are idempotent, but a silent gap could oversell products, so checkpoint age is closely watched.

Telemetry and IoT

Device readings are voluminous and often tolerate replay or small loss. Many teams choose timestamp-based recovery because it is simple and the data is naturally time ordered.

Platform Migrations

When moving from an old cluster to a new one, teams mirror topics, translate consumer positions, then move consumers group by group, keeping the option to move back until confidence is high.

A Typical Migration Walkthrough

Migration is the friendliest setting for offset translation, because nothing is on fire and you can pause at each step. Teams that do it well move one consumer group at a time and check the result before touching the next.

1

Create matching topics and let mirroring catch up

Confirm partition counts and settings match, then wait until replication lag is close to zero and checkpoints are fresh.

2

Move producers or leave them, according to the plan

Some teams move consumers first and producers later, while others move producers first. The order changes which cluster holds the newest data at each moment.

3

Stop one consumer group and apply its translated positions

Wait for the group to be fully idle, read its newest checkpoint, and apply it on the new cluster.

4

Start the group on the new cluster and compare outputs

Watch lag, error rates, and business results. Keep the old group’s position preserved so a rollback is possible.

5

Repeat for each remaining group, then retire the old cluster

Only decommission mirroring after every group and producer has moved and a quiet period has passed without incidents.

21Frequently Asked Questions

Q1Why can’t Kafka just copy offsets one to one between clusters?

Each cluster assigns offsets when it stores an event. A mirroring tool writes new events, so the target chooses its own numbers. Only follower replication inside one cluster copies the log exactly.

Q2Does offset translation ever lose data?

Translation itself rounds backward to avoid skipping events. Data loss usually comes from asynchronous replication lag, where the newest events never reached the target, or from mismatched retention and reset rules.

Q3Why do I see duplicates after failover?

Because translated positions come from sample points and timed checkpoints. The group restarts slightly earlier than its true position, so a window of events is processed again.

Q4Can I get exactly-once behavior across clusters?

Not through mirroring alone. Kafka’s transactional guarantees apply inside one cluster. Across clusters, design for at-least-once and add idempotent processing or a store of handled identifiers.

Q5What happens if the target group is already running when I sync offsets?

Automatic sync generally avoids overwriting an active group. You may need to stop all members, apply positions, and restart. Confirm the exact behavior in your version.

Q6How does compaction affect translation?

Compaction creates holes in the offset line that differ between clusters. Translation stays safe but may replay more than expected, and event counts will not match between source and target.

Q7Is timestamp-based recovery better than offset translation?

It is simpler and independent of offsets, but less precise and dependent on timestamp quality. Many teams keep it as a fallback rather than the main method.

Q8What if source and target have different partition counts?

Standard translation no longer applies, because partitions cannot be mapped one to one. Use identical counts, or rely on timestamps and idempotent consumers.

Q9Should I rename the consumer group on the target?

Generally no. Checkpoints are recorded under the original group name, and a new name starts without any translated position.

Q10How often should we rehearse failover?

Often enough that the runbook stays accurate and staff stay familiar with it, commonly a few times a year, and after any major change to topology, versions, or partitioning.

Q11Why is the translated offset usually a little behind the true position?

The tool only has sample points and chooses the newest one that does not pass the group’s committed position. Being slightly behind is the safe direction, because it can only cause replay, never skipped events.

Q12What does a sudden jump in the gap between source and target offsets mean?

It usually means the target lost or gained events relative to the source, for example after a topic recreation, a large aborted transaction, a mirror restart from another position, or a heavy compaction run. Investigate before trusting old checkpoints.

Q13Do heartbeats help with offset translation?

Not directly. Heartbeats prove that data flows end to end and let you measure latency. That measurement tells you how large the missing tail could be, which is an important companion to translation quality.

Q14Can consumers on the target read both local and mirrored data at once?

Yes. With prefixed remote topics, a consumer can subscribe to the local topic and the remote topic together using a pattern. Ordering across the two topics is not guaranteed, so downstream logic must not depend on it.

Q15What is the single most valuable protection against offset problems?

Idempotent consumers. If reprocessing an event is harmless, then imprecise translation, stale checkpoints, and even manual timestamp resets stop being emergencies and become routine operations.

22Summary and Key Takeaways

Offsets are positions inside a single copy of a partition, so they cannot be treated as universal addresses. Mirroring between clusters creates new events and therefore new numbering, which then drifts further because of late starts, retention, compaction, transaction markers, retries, and configuration differences. Tools such as MirrorMaker 2 respond by keeping sparse sample points and computing checkpoints that map consumer positions from one cluster to the other. That mapping is deliberately conservative, favoring replay over loss.

The hard parts appear at the edges: stale checkpoints, active groups on the target, mismatched partitions, missing replication tails, and the return trip during failback. The most resilient organizations combine sensible translation with idempotent consumers, uniform topic contracts, strong monitoring, and rehearsed runbooks.

Key Takeaways

  • Offsets are local — they identify a position in one copy of one partition, and mirrored copies assign their own numbers.
  • Translation is an estimate — sparse sample points and timed checkpoints produce a safe, backward-rounded restart position.
  • Expect replay, not exactness — cross-cluster failover is at-least-once, so consumers must tolerate repeated events.
  • Configuration drift hurts — partition counts, retention, compaction, and timestamp settings must match across clusters.
  • Timing and state matter — check checkpoint age and make sure the target group is inactive before applying positions.
  • Plan the return trip — failback needs reverse replication and reverse translation, rehearsed in advance.
  • Layer your defenses — combine standard translation, a timestamp fallback, idempotent processing, and regular drills.