# Ops Playbook: Offsets & Replays

Page title: Ops: Offsets & Replays

> Operate CDC pipelines with confidence by hardening offset storage, planning safe rewinds, and scripting replay drills.

Canonical page: <https://sandgraal.github.io/letstalkcdc/ops-offsets/>

> **Known errata for this page (1)**
>
> - **Corrected: Kafka Connect offset topic** (updated 2026-08-24)
>
>   The storage table previously named `__consumer_offsets` as Kafka Connect's primary offset store. That topic holds *consumer-group* offsets. A source connector's own progress (the LSN/binlog position Debezium checkpoints) lives in `connect-offsets`, set via `offset.storage.topic`. The table now reads `connect-offsets`, matching the backup commands lower on the same page.
>
> [See all corrections and caveats](https://sandgraal.github.io/letstalkcdc/errata/)

Keep change streams healthy by protecting offset stores, practicing safe rewinds, and rehearsing replay drills.

View Ops Checklist Automate Replays

## Offset operations readiness tracker

Watch overall rewind preparedness climb as you complete each operational checklist.

0 of 0 readiness checks complete (0%)

## Guardrail checklist

- Offsets persist to durable storage separate from the connector host.
- Backups exist for the last seven days of offset snapshots.
- Runbooks document how to pause, rewind, and resume each connector.
- DLQ triage flow is rehearsed quarterly.
- Access to offset stores is restricted to on-call engineers (MFA enforced).

## Offset storage patterns

Treat offsets as crown jewels. They decide whether a replay is a clean rewind or a week-long [dedupe](https://sandgraal.github.io/letstalkcdc/glossary/#deduplication) exercise.

| Pipeline | Primary store | Secondary copy | Notes |
| --- | --- | --- | --- |
| Kafka Connect | `connect-offsets` (internal topic) | MirrorMaker stream to DR cluster | Source-connector progress lives in `connect-offsets` (set via `offset.storage.topic`), *not* `__consumer_offsets` (that holds consumer-group offsets). Enable `offset.flush.interval.ms` < 5000 for tighter RPO. |
| Debezium Server | File-based or JDBC offset storage | Nightly object storage snapshot | Encrypt backups; restore drill should be documented. |
| Custom sink | Table in target warehouse | Application DB with strict RBAC | Persist the last processed offset per partition with checksum. That is consumer progress, not a row version: the sink still [guards on the source log position](https://sandgraal.github.io/letstalkcdc/partitioning/#recon). |

Store offsets in a system that survives connector hosts. Local disk is a single point of failure.

## Safe rewind procedure

1. Pause ingestion and confirm downstream consumers are idle.
2. Restore the offset snapshot you want to resume from.
3. Validate that the target system can handle replays idempotently.
4. Resume the connector and watch [lag](https://sandgraal.github.io/letstalkcdc/glossary/#lag) + error metrics.
5. Document the incident: why rewind happened, what data was affected.

Never delete offsets ad hoc. Instead, copy them to a safe location and prove your recovery path in staging first.

If the rewind is really a reload of history, see [Backfill and Re-Snapshot Safely](https://sandgraal.github.io/letstalkcdc/backfill-resnapshot/) for the choices and the checks.

## Replay drills

**Offset backup commands**

Before attempting any offset manipulation, back up the current state. The offset storage topic name is configured via `OFFSET_STORAGE_TOPIC` in [Kafka Connect](https://sandgraal.github.io/letstalkcdc/glossary/#kafka-connect) (defaults to `connect-offsets` in the Debezium image).

```bash
# Discover your offset topic name from the Connect worker config
# Check the container environment variable
docker compose exec connect env | grep OFFSET_STORAGE_TOPIC

# Or list all Kafka Connect internal topics
kafka-topics --bootstrap-server localhost:9092 --list | grep connect

# Dump all offsets to a JSON file
# IMPORTANT: Replace 'connect-offsets' with your actual topic name if different
# IMPORTANT: Replace 'localhost:9092' with your Kafka broker address
kafka-console-consumer --bootstrap-server localhost:9092 \
  --topic connect-offsets \
  --from-beginning --timeout-ms 5000 \
  --property print.key=true \
  --property print.offset=true \
  --property print.timestamp=true \
  > offsets-backup-$(date +%Y%m%d-%H%M%S).json

# Verify backup contains data
wc -l offsets-backup-*.json
tail -5 offsets-backup-*.json
```

**Topic name matters:** The standard topic name is `connect-offsets`, which is used by both the main [compose.yaml](https://github.com/sandgraal/letstalkcdc/blob/main/compose.yaml) and the [lab tutorial](https://sandgraal.github.io/letstalkcdc/lab-kafka-debezium/). Always verify the topic name in your deployment's Connect configuration before dumping offsets to avoid an empty backup.

**Quarterly dry run**

- Pick a connector and simulate a failure that requires rewind.
- Time each step from detection to recovery.
- Capture deltas between the replayed data set and expected outcome.

**Game day metrics**

- Record lag peak, throughput dip, and recovery duration.
- Update runbooks with observed bottlenecks or manual fixes.

## Monitoring & alerting

- **Lag & throughput:** Alert when lag growth exceeds the agreed budget or throughput drops suddenly.
- **Offset staleness:** Detect connectors that have not committed offsets in the last five minutes.
- **DLQ spikes:** Track dead-letter events per partition to spot poison pills early.

## Automate the boring, dangerous steps

Codify replay drills so humans do not improvise under pressure.

```bash
#!/usr/bin/env bash
set -euo pipefail

CONNECTOR_NAME="$1"
TARGET_OFFSET_SNAPSHOT="$2"

echo "Pausing $CONNECTOR_NAME"
curl -X PUT "${CONNECT_URL}/connectors/${CONNECTOR_NAME}/pause"

aws s3 cp "s3://cdc-offsets/${CONNECTOR_NAME}/${TARGET_OFFSET_SNAPSHOT}" ./offsets.json

psql $OFFSET_STORE -c "\copy connect_offsets FROM './offsets.json' WITH (FORMAT json)"

curl -X POST "${CONNECT_URL}/connectors/${CONNECTOR_NAME}/resume"
```

Keep scripts idempotent—rerunning should yield the same offset state. Track revisions in version control.

## Quarterly offset audits

1. Verify snapshots exist for every critical connector and restore one into staging.
2. Reconcile stored offsets against the target system [watermark](https://sandgraal.github.io/letstalkcdc/glossary/#watermark) to catch drift.
3. Document gaps, update runbooks, and assign owners for remediation tasks.

Pair the audit with a tabletop exercise covering simultaneous connector failure and downstream replay to keep teams confident under stress.

## Offset operations readiness scorecard

Confirm the operations team can rewind confidently at 2 a.m. by checking each line item before you certify a connector as production-ready.

0 of 4 ready (0%)

| Area | Ready when… | If not, next step |
| --- | --- | --- |
| Offset durability | Primary and secondary offset stores are replicated and restore drills succeed within RTO. | Set up replication or snapshots, automate restore verification, and document expected recovery times. |
| Runbook quality | Pause/rewind/resume steps are scripted with parameterized inputs and owner contact info. | Convert manual docs into scripts, add sanity checks, and capture owner rotation details. |
| Access control | Least-privilege access exists for offset stores with MFA and break-glass procedures. | Implement RBAC, rotate credentials, and rehearse break-glass approval flow with security. |
| Replay rehearsal | Latest quarterly drill has a postmortem with metrics (lag delta, replay duration, data diffs) and closed actions. | Schedule a rehearsal, capture metrics template, and assign follow-up owners before certifying the pipeline. |

### Offsets & Replays Knowledge Check

Test your understanding of offset management and safe replay procedures.

Q1

#### What is a consumer offset in Kafka-based CDC?

A The size of the message in bytes

B A pointer indicating the last message a consumer successfully processed

C The number of partitions in a topic

D The time a message was produced

Q2

#### Why is it dangerous to reset offsets to an arbitrary position without proper safeguards?

A It's always safe to reset offsets

B Resetting offsets can cause reprocessing of old data, leading to duplicates, or skipping data, causing gaps

C Offsets cannot be reset once set

D Offset resets have no effect on consumers

Q3

#### What is the purpose of log retention in Kafka?

A To automatically delete all messages after one day

B To determine how long messages are kept before being eligible for deletion

C To store consumer offsets permanently

D Log retention doesn't affect CDC pipelines

Q4

#### When should you consider replaying CDC events?

A Replays are never necessary

B When recovering from data corruption, sink failures, or testing schema changes in a downstream system

C Every day as a routine operation

D Only when the database is offline

Q5

#### What is idempotency, and why is it critical for safe replays?

A Idempotency means messages are always processed in order

B Idempotency means reprocessing the same message multiple times produces the same result

C Idempotency prevents all message duplication

D Idempotency is not important for CDC

**0/5** correct

## Further resources

- [Reconciliation & Offset Surgery](https://sandgraal.github.io/letstalkcdc/reconciliation-surgery/) for advanced offset manipulation and sink repair techniques.
- [Event envelope](https://sandgraal.github.io/letstalkcdc/event-envelope/) for understanding replay impacts on payload contracts.
- [Observability basics](https://sandgraal.github.io/letstalkcdc/observability/) to plug audit metrics into dashboards.
- [Materialization 101](https://sandgraal.github.io/letstalkcdc/materialization/) for coordinating offset rewinds with downstream table recovery.

---

CDC: The Missing Manual by Christopher Ennis (Let's Talk CDC), licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Attribution is required.
