Skip to content

Event contracts and changes

When a record cannot be processed

Decide when to retry, stop, or save a failed record for repair before resuming the stream.

Learn with an AI assistant

Copy the prompt and paste it into a chat with an AI assistant.

You are a tutor for the course "Stream Processing".
Topic: "When a record cannot be processed"
In short: Decide when to retry, stop, or save a failed record for repair before resuming the stream.
Topic text in Markdown: https://stream-processing-systems.github.io/contracts/when-a-record-cannot-be-processed.md
Base your explanations on the topic text. First ask how I want to study: a short summary, a step-by-step walkthrough, or a deep dive with questions that check my understanding. Use the text's example and terms. If you add anything the text does not say, point it out.

The charger map reads a log partition. Offset 39 holds the 09:24 reading from charger-7. Offset 40 holds the late reading from 09:16, which arrived at 09:25. At offset 41 the old reader fails to decode the new status paused. A later reading waits at offset 42. After a restart the reader returns to 41 and fails again.

The map team needs to choose what happens to that record and the ones behind it. Can the reader make progress while the team fixes the problem? What can the map tell drivers in the meantime?

A retry is useful if the conditions for processing may change between attempts. For example, the reader may need to fetch a writer schema from a service that is temporarily unavailable. A few attempts with a delay give the service time to recover. The team sets a limit so a long outage can be investigated.

At offset 41 the reader has the writer schema, but its own schema cannot resolve the new status. Another attempt with the same schemas gives the same error. The team needs to update the reader or handle the record separately. An input that repeatedly blocks progress for a reader is sometimes called a poison record.

The map team can pause the partition and leave the next saved offset at 41. An alert tells the team which partition is blocked and why. This fits a calculation that needs every record in order. A report that groups charging readings into sessions can split one period of use into two if it misses a reading that bridges a gap.

The readings behind 41 in that partition wait, including readings from other chargers. The team has until the log’s retention policy removes needed records to fix the problem and catch up.

The map can still show the latest successfully read observations if it exposes gaps in the input. For that view the team chooses to continue and keep failed records for investigation. A separate destination that holds failed records for later handling is often called a dead-letter queue (DLQ). Kafka Connect, for example, can send failed sink records to a separate topic and attach information about the error.1

The map’s failure entry keeps the original bytes, including the key and headers needed to read them, and records the source topic, partition, and offset. It also records the error, the reader version, and the schema identifier if available. Even if the reader cannot extract an event ID, the team can locate this particular record using its source position. The queue must keep the copy long enough for the team to investigate and reprocess it.

If the reader saves 42 as its next offset before storing the failure entry and then crashes, it restarts at 42. The failure queue has no copy of record 41 and the main path has passed it. The team can recover it from the original log only while it is still retained.

If the reader stores the failure entry and crashes before saving 42, it restarts at 41. The failure store can use the source topic, partition, and offset as the entry’s unique key for this processing path. A write that inserts only when the key is absent leaves the existing copy in place. Once the entry is durable, the reader can save 42 as its next offset. If it cannot confirm the entry was saved, the offset remains at 41. The same boundary between the write and saved progress applies whether the destination stores results or failed work.2

Save the failed record before moving on A crash after saving the failure entry leaves offset 41 committed. On restart, the reader reuses that entry and commits offset 42. CRASH AND RESTART Save the failure entry Committed offset stays at 41 Read record 41 again Reuse the saved failure entry Commit offset 42 Read the next record

The reader saves the failure entry with a pending status before committing the offset. The map uses pending entries to flag gaps. It can restore the list from the failure store after a restart, even when the reader resumes at 42. If the original key identifies the charger, the map can flag that charger. Otherwise, it flags data from the whole partition as incomplete.

With a reader that supports paused, the team can decode record 41 from the failure queue and apply it using its original event time and identity. Suppose record 41 was measured at 09:26 and the later reading at 42 reports that charger-7 was charging at 09:28. The repaired reading adds the charging pause at 09:26 to the charger’s history and shows that the charger was occupied at that time. The map still uses 09:28 as the latest observation. A report that used the incomplete history may need to recompute the affected interval.

The team marks the failure entry resolved after saving the correction. The history stores one reading per (source, event_id), so repeating a repair updates the same reading.

The map can now show the time of the latest usable reading and flag a gap while repair is pending. A reading can be recent even when a preceding observation is still missing from the result.

  • Retry when a later attempt may see different conditions. Pause if the calculation needs the failed record before it can proceed.
  • When continuing, save the failed input and its context durably before moving the saved position past it. Make the failure write safe to repeat.
  • Track gaps using saved failure entries. Apply repaired readings using their original time and identity before marking the failures resolved.
  1. Apache Kafka 4.4, Error Reporting in Connect.

  2. Apache Kafka 4.4, Message Delivery Semantics.

© 2026 Grig Alex · CC BY-NC-SA 4.0