Replay CLI

Preview and replay one bounded Kafka slice at a time.

The current replay engine is intentionally narrow: one topic, one partition, one closed offset range or timestamp window, and one destination topic.

Command Contract

npm run replay:cli -- --source <topic> --destination <topic> --partition <id> --start <offset> --end <offset>
npm run replay:cli -- --source <topic> --destination <topic> --partition <id> --start-timestamp <timestamp> --end-timestamp <timestamp>
Flag Purpose
--sourceSource topic to read from
--destinationExisting topic to write replayed records into
--partitionSingle source partition for the run
--startInclusive starting offset
--endInclusive ending offset
--start-timestampInclusive ISO timestamp or epoch milliseconds
--end-timestampExclusive ISO timestamp or epoch milliseconds
--messages-per-secondOptional write cap for actual replay execution
--dry-runPreview the replay without producing
--job-idStable replay identifier for logs and headers
--brokersOverride the broker list instead of using KAFKA_BROKERS
--progress-everyLog every N replayed messages

Replay Examples

npm run replay:cli -- --source orders --destination orders-replay --partition 0 --start 10 --end 25 --job-id incident-2026-04-28
npm run replay:cli -- --source orders --destination orders-replay --partition 0 --start 10 --end 25 --dry-run --job-id incident-2026-04-28
npm run replay:cli -- --source orders --destination orders-replay --partition 0 --start 10 --end 25 --messages-per-second 10 --job-id incident-throttled-2026-04-28
npm run replay:cli -- --source orders --destination orders-replay --partition 0 --start-timestamp 2026-04-28T14:03:00.000Z --end-timestamp 2026-04-28T14:08:00.000Z --job-id incident-window-2026-04-28

Dry-Run Preview

Dry-run validates the replay request, reads the exact range, and prints a per-message preview including the headers that would be written. It does not connect a producer or advance the destination topic offsets.

Timestamp Windows

Timestamp replay resolves the requested window to concrete offsets before consuming records. The start timestamp is inclusive and the end timestamp is exclusive. If the window resolves to no retained messages, the command fails before replay begins.

Replay Throttling

--messages-per-second caps writes to the destination topic during actual replay execution. Preview stays fast because it does not produce records.

Replay Headers

Header Meaning
x-replayedMarks the record as replayed
x-replay-job-idStable run identifier
x-original-topicOriginal topic name
x-original-partitionOriginal partition number
x-original-offsetOriginal source offset

Safety Checks

The replay engine preserves the source key, value, timestamp, and any pre-existing headers. Lighthouse adds the replay headers on top.