Start, backfill and replay
This guide starts a hook with history already in its stores, backfills it, and reads a topic again after a bug fix.
Before you start, have:
- the hook and its sinks defined ( Hooks , Sinks and reading back );
- your broker's tools, such as
kafka-consumer-groups, with rights on the hook's consumer group; - the topic's retention: a replay reads only what Kafka still holds, and what it deleted is not rebuilt.
A hook's consumer group is its name, behind kafka_group_prefix when it is set ( Consumer groups ). The examples use the prefix prod. and the hook FM.SHOP.ON_PAYMENT.
Start a new hook
A hook created with START = 'latest', the default, indexes only the records read from then on. Running for a window's length proves nothing about the window: a 10-minute window read at T is complete only once every partition was read from before T - 10 minutes and has caught up to T. A producer that sends late, or a partition read late, leaves gaps.
To start with history, create the hook with START = 'earliest', or an interval back such as INTERVAL '7 DAY' ( WITH ). It reads the topic's history first, as fast as the stores take it. When a scheduled hook or a decision hook reads what it writes, follow the next section first.
Check: SHOW SERVING STATUS LIKE 'FM.SHOP.ON_PAYMENT' shows each partition's lag near zero ( A hook's details ).
Backfill a hook that feeds scheduled hooks
EXPIRE and RETENTION follow the clock, not the events' times. A backfill replays records days old: it queues bucket entries already older than a production EXPIRE, and the drain drops them. It writes index members older than a production RETENTION, which are trimmed as they are written.
A worked example: a minute rollup with EXPIRE = INTERVAL '2 MINUTE', and an event hook started a week back. Every minute of that week queues an entry due a week ago. Each drain drops them unrun, entries_expired counts every one, and no bucket of the week is written.
Step 1. Raise EXPIRE and RETENTION above the age of the oldest record replayed: CREATE OR REPLACE the scheduled hooks and the index sink. Changing EXPIRE, EVERY or POLICY keeps the entries already queued:
CREATE OR REPLACE FEATURES IN FM.TUTORIALS.HOOK_REF AS
PERSIST
pay_index := SINK(
'redis://redis:6379'
KEY 'pay:{' || merchant_id::VARCHAR || '}'
INDEXED ON event_time UNIQUE ON payment_id
WITH (
FORMAT = 'msgpack',
MODE = 'append',
SHAPE = 'sorted_set',
RETENTION = INTERVAL '31 DAY'
)
),
rollup_minute := HOOK(
RUN minute_ps
ON pay_ps
AT minute_close
USING (minute_ref)
TO per_minute
QUEUE minute_queue
WITH (
POLICY = 'earliest',
EVERY = INTERVAL '10 SECOND',
EXPIRE = INTERVAL '30 DAY'
)
)
;| feature_name VARCHAR | status VARCHAR | message VARCHAR |
|---|---|---|
| FM.TUTORIALS.HOOK_REF.PAY_INDEX | REPLACED | Feature was replaced |
| FM.TUTORIALS.HOOK_REF.ROLLUP_MINUTE | REPLACED | Feature was replaced |
Then:
- Load them:
RECOMPILE SERVING. - Create the event hook to read the history ( Start a new hook ). For a hook that already runs, drop it, reset its group and create it again ( Replay a topic ).
- Wait for both:
lagzero on every partition, then the queue'sdueat zero at alast_drainlater than that ( A hook's details ). - Set
EXPIREandRETENTIONback to their production values, andRECOMPILE SERVING.
Check: the queue's entries_expired did not move during the backfill.
Start a long horizon full
On the day a hook is created, a 7-day total covers only what it has indexed, and stays short for the length of the window. Until the index holds the whole window, the partial first hour, read from the index, misses what came before the hook ( Long horizons ). Two ways to start it full:
- Within the topic's retention, backfill as above, with the index's
RETENTIONand the rollup'sEXPIREraised over the replay's horizon. - Beyond it, republish the history to a topic the hook reads, or insert the hour buckets yourself ( Seed rows yourself ).
Replay a topic
A hook resumes from its group's offsets. There is no RECOMPUTE and no seek for hooks. To read a topic again, after a bug fix for instance:
Decide where the replayed values go. A replay rewrites a
latestkey only from records at least as new as its stored value (an equalrequest_timereplaces). A key keeps its old value, or tombstone, when the record that last wrote it is outside the replay, or when the new definition no longer writes it (another key, aWHEREthat drops the record). After a bug fix, either clear the sink first, or point the hook at a new sink (a new table or key prefix) and move the readers once it is filled.Raise
RETENTIONandEXPIREfirst when another hook reads the index the replay writes, a decision hook or a scheduled hook ( Backfill a hook that feeds scheduled hooks ). Otherwise the index is trimmed as it is written, and the decisions recomputed from it count too few events and replace good ones.Drop the hook so that no consumer is in its group:
DROP FEATURES FM.SHOP.ON_PAYMENT;, thenRECOMPILE SERVING;.Reset the group's offsets with your broker's tools:
bash kafka-consumer-groups --bootstrap-server broker:9092 --group prod.FM.SHOP.ON_PAYMENT
--topic payments --reset-offsets --to-datetime 2026-11-24T00:00:00.000 --executeCreate the hook again under the same name, with its
CREATE OR REPLACE FEATURES, thenRECOMPILE SERVING;. It resumes from the reset offsets.
A reset to a time before the oldest record Kafka keeps starts at that record. A replay reads the sources as they are now: it restores raw events in an index, within its RETENTION, not the values computed back then.
Check: lag back to zero on every partition, and the replayed keys' request_time in the sink matching their last record.
Replay under a new name instead
A hook under a new name has a new group, so it starts from its own START without a reset. It cannot write the old hook's sinks while that one exists (UE/SINK-SHARED): give it new sinks and a new queue, move the readers once it has caught up, then drop the old hook.
Seed rows yourself
A hook's table or index is an ordinary table or key: you may insert rows in its layout ( The write layout ), to seed a history the topic no longer holds.
- A
latestrow takes arequest_timeolder than any record the hook will process, so that the hook's own writes land over it. Leavedatakey,partition,offsetanddrainNULL, and setcompute_time: a row without one reads as a tombstone. - An
appendrow needs itsUNIQUE ONidentity. A record of the same identity replaces it.
Common failures
- The backfill wrote no buckets:
EXPIREwas not raised, andentries_expiredrose by the number of buckets. Raise it and replay again. - Decisions recomputed short after a replay: the index's
RETENTIONwas not raised, and the replayed events were trimmed as they were written. - A recreated hook skipped records: its group's offsets were deleted while it was dropped, after the broker's
offsets.retention.minutes, so it appliedSTARTagain ( Consumer groups ). Reset the offsets to the time it was dropped. - The reset is refused: a consumer is still in the group. Drop the hook on every replica, and
RECOMPILE SERVINGon each, or wait for their next sync.
Related
- Size
RETENTION,EXPIREand memory : the production values to set back. - Change and replay : changes that move a queue.
- A rolling window : a replay shown on a test server.