---
title: "Keep events long enough to replay them · Agent Wranglers"
url: https://agentwranglers.se/playbook/events/consuming-events/event-replay
id: EVT-14
level: Recommended
updated: 2026-10-27
build: a2a6bdfed830
tokens: 991
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Keep events long enough to replay them

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Consuming events](https://agentwranglers.se/playbook/events/consuming-events.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: EVT-14
- Level: Recommended
- Chapter: [Consuming events](https://agentwranglers.se/playbook/events/consuming-events.md)
- Rule: Set a retention time on every topic or stream that is longer than the longest outage you plan to recover from. Write down how to replay a consumer from a past time.
- Check: Every topic's retention setting appears in the written list, each at least as long as the stated recovery window. On staging, reset a test consumer to 24 hours ago. It processes the events again and the target holds no duplicates.
- How: A consumer with a bug writes wrong data for a day. With the events still in the log, you fix the code and rewind its position to before the bug, and it processes them again. That needs retention longer than the time to notice and fix, such as 7 days. The consumer must also be safe to rerun, as [Process each message once](https://agentwranglers.se/playbook/events/consuming-events/idempotent-consumers.md) requires. Kafka can reset a group's offsets to a date. A compacted topic keeps only the last event per key, so it serves as current state, not as history. Events that hold personal data need a retention that matches [Keep one retention schedule](https://agentwranglers.se/playbook/compliance/records-and-data-map/retention-schedule.md), so keep IDs in events rather than personal fields.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### Shell example

```bash
# Rewind one consumer group to a point in time on staging
kafka-consumer-groups.sh --bootstrap-server kafka.staging.example.com:9092 \
  --group order-emails --topic shop.orders \
  --reset-offsets --to-datetime 2026-10-26T09:00:00.000 --execute
```

### Python example

```python
from confluent_kafka import Consumer, TopicPartition

def rewind_to(consumer: Consumer, topic: str, partitions: list[int], timestamp_ms: int) -> None:
    wanted = [TopicPartition(topic, p, timestamp_ms) for p in partitions]
    consumer.assign(consumer.offsets_for_times(wanted, timeout=10))
```

### JavaScript example

```js
export async function rewindTo(admin, groupId, topic, timestampMs) {
  const offsets = await admin.fetchTopicOffsetsByTimestamp(topic, timestampMs);
  await admin.setOffsets({ groupId, topic, partitions: offsets.map(({ partition, offset }) => ({ partition, offset })) });
}
```

## Sources

- [Apache Kafka design, consumers that rewind](https://kafka.apache.org/43/design/design/)

## Related rules

- EVT-11 [Process each message once](https://agentwranglers.se/playbook/events/consuming-events/idempotent-consumers.md) in Integration and events
- CMP-11 [Keep one retention schedule](https://agentwranglers.se/playbook/compliance/records-and-data-map/retention-schedule.md) in Compliance and governance

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/events/consuming-events/event-replay">Agent Wranglers integration and events playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Alert when a consumer falls behind](https://agentwranglers.se/playbook/events/consuming-events/consumer-lag.md)
- Next: [Undo failed multi-step work with compensating steps](https://agentwranglers.se/playbook/events/consuming-events/sagas.md)
- [Consuming events](https://agentwranglers.se/playbook/events/consuming-events.md)
