Your cart is currently empty!
Dead letter queues for records that fail parsing
The records nobody can find
A retailer changes the markup around its sale prices on a Tuesday. Only the sale template changes. Regular-price pages parse fine. Your collector’s price extractor returns nothing on sale pages, validation rejects those records for a missing required field, and the pipeline does what it was built to do with rejects: logs a warning and moves on.
On Friday an analyst asks why the discount report shows fewer discounted products than last week. Someone opens the logs, finds several thousand warnings, and fixes the selector in twenty minutes. Then comes the real question. Which products were affected, and can we get their prices back for Tuesday through Friday? The warnings contain URLs and error messages. They don’t contain the pages. Getting the data back means refetching thousands of pages, and the prices on those pages today aren’t the prices from Tuesday.
That’s the cost of dropping failures. The opposite mistake is retrying them: the same pages go back into the queue, get fetched and parsed again, fail again for the same reason, and cycle until someone notices the retry traffic.
A dead letter queue is the third option. Records that fail parsing are parked with everything needed to process them later: the raw input, the error, and the version of the code that failed. After the fix, they’re replayed from the stored input, and Tuesday’s prices come back as Tuesday’s prices.
The validation guide in this series covers deciding what counts as a bad record, and it recommends a dead-letter destination for rejects. This article picks up from there. It covers what belongs in a dead letter entry, how to group thousands of failures into the handful of bugs behind them, alerting, replaying after a fix without corrupting current state, and the retention rules that stop the queue turning into a second uncontrolled archive.
We run dead-letter handling on our own collection pipelines, and the design below is what we’d build again. It isn’t tied to one queue product, because the same shape works in a database table, a Kafka topic or a bucket prefix.
Drop, retry or park
When a record fails, a pipeline has three choices, and it’s worth being explicit about why two of them are wrong for parse failures.
Dropping is the default in most hand-rolled collectors, usually as a log line. It keeps the pipeline flowing and loses the evidence. Logs are written for humans scanning recent events, rotated on a schedule, and rarely carry the input. A dropped record can only be recovered by refetching, which costs proxy bandwidth and returns the page as it is now rather than as it was.
Retrying is the right answer for transient failures, like a timeout, a connection reset or a brief rate limit, where the same request might succeed a minute later. It’s the wrong answer for parse failures, for a simple reason: parsing is deterministic. The same bytes run through the same parser version produce the same result. Retrying a parse without changing either the input or the parser does the identical computation again and fails identically. If the retry refetches, it may get a different page, which hides the bug on some attempts and not others, and makes it much harder to diagnose.
Parking means writing the failure somewhere durable, with its input, and taking it out of the main flow. The pipeline keeps moving. Nothing is lost. The backlog is visible, queryable and replayable once the parser changes.
The mental model that helps is that a parse failure is a bug report filed by the pipeline. It should arrive with a reproduction attached, which is the raw input, and a version, which is the parser that failed. A dead letter queue is where those reports go. Dropping them is deleting bug reports. Retrying them is running the failing test again and hoping.
Which failures belong in the dead letter queue
Not every failure should go to the same place. Sorting them by cause keeps the dead letter queue useful and stops it filling with things that should have been retried.
Transient fetch failures, such as timeouts, connection errors and server errors that clear on their own, belong in a retry path with backoff and a cap on attempts, as the backpressure guide describes. They have no page to park. If they exhaust their retries, they become a fetch failure record, which is a separate concern from parsing.
Blocks and challenges, where the target answered with a 403, a 429 or a challenge page, belong in the error-handling path that slows the collector down and alerts. They’re a signal about access, and the right response is less traffic. Parking a challenge page as a parse failure and replaying it later just produces the same failure.
Parse failures are the core case: the page was fetched successfully, the bytes are real content, and the extractor couldn’t produce a record. A selector that no longer matches, a date in an unrecognised format, JSON embedded in the page with a changed structure.
Validation failures are the other core case: the extractor produced a record, but it failed a schema or semantic check. A price of zero, a missing required field, a currency code that isn’t one.
The tricky middle is a page that fetched with a 200 but isn’t the content you expected: a soft block, a login wall, an empty search result, a regional redirect. These often surface as parse failures because the selectors don’t match. They should be detected and routed to the error path, because replaying them after a parser fix won’t help. A simple classifier that checks for known block and interstitial signatures before parsing, as the silent-failures guide describes, keeps them out of the dead letter queue.
What reaches the queue, then, is failures where the input is genuine and the code is what needs to change.
What a dead letter entry needs
A dead letter entry is only as useful as what it carries. The test is whether someone can reproduce and fix the failure from the entry alone, weeks later, without refetching anything.
The input comes first. That means a pointer to the raw page in object storage, plus its content hash so you can confirm the bytes haven’t changed. If raw pages aren’t stored by default, the dead letter write is the moment to store this one. Without the input, the entry is a log line with extra columns.
Next come the version and stage. Record the parser version that failed, as a release tag or commit, and the stage where it failed: extraction, a specific field extractor, schema validation or semantic validation. When a failure is replayed, the version tells you whether it was already fixed.
Then the error itself. Record the error class, the message, and the field involved if there is one. For validation failures, the rule that failed and the value it saw. For extraction failures, the selector or strategy that returned nothing.
Context matters too. The source site, the canonical URL, the page type, the job and run IDs, when the page was fetched, and when the failure was recorded. The fetch time matters most, because it’s the time the recovered record will represent.
Any partial record belongs in there as well. If extraction produced some fields before failing, keep them. They help diagnose the failure and sometimes show that only one field is broken.
Last, state. A status, an attempt count, a fingerprint for grouping, and timestamps for each status change.
That’s a dozen or so fields, most of them small. The raw page stays in object storage and the entry holds a pointer, which keeps the queue cheap to store and fast to query.
Fingerprints: many failures, few bugs
A single selector break produces a failure on every page of the affected template, which can be thousands of entries in an afternoon. Nobody triages thousands of entries. They triage bugs, and there are usually only a handful behind a large backlog.
A fingerprint is what turns entries into bugs. It’s a stable identifier computed from the parts of a failure that stay the same across every instance of one cause: the source, the page type, the stage, the error class, the field, and a normalised form of the error message. Normalising means stripping the parts that vary per instance, such as URLs and IDs, plus numbers and quoted values, so “could not parse date ’14/09/2026′” and “could not parse date ’15/09/2026′” collapse into one fingerprint, “could not parse date”.
Include the parser version in the grouping view but not in the fingerprint itself. The same bug persisting across two releases should show as one fingerprint with entries from both versions, which tells you the fix hasn’t shipped or didn’t work.
With fingerprints, the dead letter queue becomes a short table: each row a distinct failure, with a count, first-seen and last-seen times, the sources affected, and a sample entry to open. A new fingerprint appearing is often the first sign that a target changed. A fingerprint whose count is still rising after a fix was deployed says the fix missed some cases.
The fingerprint is also the unit of replay. When a fix ships, you replay the entries for the fingerprints it addresses, and nothing else. That keeps replays targeted and makes their results easy to read: the fingerprint either clears or it doesn’t.
Keep the normalisation rules simple and visible. Over-aggressive normalisation merges unrelated bugs into one fingerprint. Too little leaves every instance unique. Start with a handful of patterns for numbers, dates, URLs and quoted strings, and adjust when a grouping looks wrong.
Where the dead letter queue should live
The name suggests a queue, and in message-broker pipelines it often starts as one: a dead-letter topic in Kafka or a dead-letter queue in a managed service. That’s a fine transport. It’s usually a poor place to keep entries you need to search.
Triage is query work. Which fingerprints appeared this week? Which sources have unresolved failures older than seven days? How many entries does this fix cover? Queues and topics are built to be consumed in order, and asking them questions like these means reading everything.
The shape that works best is a table in a relational database or your warehouse, with one row per entry, indexed on fingerprint and status, and on source and failure time. Pipelines built on a broker can keep their dead-letter topic as the transport and run a small consumer that writes each message into the table. Batch pipelines can write rows directly.
Keep the raw pages out of the table. Store pointers to object storage, as described above. The table then stays small enough to query quickly even with a large backlog.
A bucket prefix on its own, with one file per failure, is the minimum viable version. It preserves inputs, which is the most important property, but it makes triage slow. If that’s where you’re starting, add an index table early.
Whatever the storage, make writing to it part of the same unit of work as rejecting the record. A pipeline that rejects a record and then fails to write the dead letter entry has dropped it after all. If the dead letter write fails, the record should stay in the main flow as a failure that blocks or retries, rather than vanishing.
A lifecycle for each entry
Entries need states, so the queue reflects the work that’s been done on it instead of growing forever.
A simple lifecycle has five states. New means recorded and not yet looked at. Triaged means someone has looked at the fingerprint and linked it to a cause, usually a ticket or a known change on the target. Replayed means the entry was reprocessed after a fix, and the result is attached. Resolved means the replay produced a valid record that went through the normal write path. Discarded means a human decided the entry shouldn’t be recovered, with a reason.
Discard reasons are worth recording carefully, because they’re the one place the pipeline intentionally loses data. Typical reasons: the page was genuinely not a product page, the source was removed from scope, the entry expired past its useful life, or the page contained nothing recoverable. A dashboard that counts discards by reason will show you when someone is using discard as a way to make the queue look tidy.
Replay results can loop back. A replayed entry that fails again gets a new failure recorded against it, possibly with a new fingerprint if the fix changed the error. Keep the history on the entry, as a list of attempts with the parser version and outcome of each, rather than overwriting.
Cap attempts. An entry that has been replayed and failed several times under different parser versions probably needs a human decision, not another automated replay. After the cap, it stays in triaged until someone acts.
Track the age of the oldest unresolved entry per source. That number, more than the total count, tells you whether the queue is being worked or just accumulating.
Partial records and field-level failures
A record doesn’t have to fail as a whole. If the price extractor breaks but the title, SKU and availability extract fine, the pipeline has a choice: park the whole record, or publish what worked and park the rest.
The answer depends on what each field means to the consumer, and it should be decided per field in advance, not improvised when a failure happens.
Required fields are the ones the record is meaningless without. For a price monitoring job, the price is required. A product record without its price counts as a failure, and publishing it risks downstream logic treating the missing price as zero or as unchanged. These records go to the dead letter queue whole.
Optional fields are the ones consumers can live without for a while, such as a secondary image, a review count, or a long description. For these, publishing the record with the field null and a quality flag, while also writing a field-level dead letter entry, keeps the main dataset flowing and preserves the ability to backfill the field later.
The flag matters. A null that means “the page genuinely has no review count” and a null that means “our extractor failed” look identical downstream unless the record says which. A per-record list of fields that failed extraction solves it, and consumers who care can filter.
Field-level entries share the same structure as whole-record entries, with the field name filled in. They also replay the same way, and when replay recovers the field, it’s written as an update to the existing record rather than as a new one.
This is also where the data contract with downstream consumers comes in. Which fields are required, and what a failed optional field looks like in the output, are things consumers should know in writing, as the data-contracts guide in this series describes.
Alerting on the dead letter queue
A dead letter queue nobody watches is just a slower way of dropping records. Alerting is what makes it part of operations.
Alert on rate, not count. A source that produces a large volume will naturally produce more dead letter entries than a small one. What matters is the share of each source’s records that fail, compared with its usual level. A jump in that share for one source almost always means that source changed.
Alert on new fingerprints. A fingerprint that has never been seen before, crossing a small count threshold, is the most useful single alert a collection pipeline can have. It’s specific, it names the source and field, and it usually fires within the first run after a target changes its markup.
Alert on age. The oldest unresolved entry per source crossing a threshold, such as a few days, catches queues that are quietly accumulating because nobody owns them. It’s a process alert rather than a technical one, and it’s the one that stops the Friday surprise.
Alert on replay failures. A replay batch where most entries fail again means the fix didn’t work or addressed the wrong fingerprint.
Keep alerts per source and per fingerprint rather than one global number. A global dead letter rate that looks stable can hide one source failing completely while others improve.
Send the fingerprint, the count, the source and a link to a sample entry in every alert. An alert that says “dead letter queue elevated” gets ignored. One that says “new failure on the sale template, price field, several hundred entries in the last hour” gets fixed.
Replaying after a parser fix
Replay is where the dead letter queue pays for itself, and it’s also where a careless implementation does damage.
The basic flow is straightforward. Select the entries for the fingerprints the fix addresses. For each, load the raw page from storage, check its hash against the entry, and run it through the new parser version. Run the result through exactly the same validation the main pipeline uses. If it passes, write it through the normal write path, and mark the entry resolved with the new parser version. If it fails, record the attempt and leave the entry for another look.
Two rules keep this safe. Replay through the same code as the main pipeline, never a special replay parser or a relaxed validation, because a replay path that differs from the live one produces records the live one wouldn’t have. And write through the same idempotent path, so replaying an entry twice doesn’t create two records. The reparsing guide makes the same point for bulk reparses, and dead letter replay is a targeted version of that.
Before replaying the whole fingerprint, replay a sample. Ten or twenty entries, checked by eye against their raw pages, catch a fix that parses without errors but extracts the wrong value. A fix that turns a missing price into a wrong price is worse than the original failure, because it passes validation.
Rate-limit replays. A backlog replayed at full speed can flood downstream consumers with a burst of updates, trigger their alerts, or saturate the warehouse loader. Replay in batches at a pace the rest of the pipeline can absorb.
And tell the people downstream. A replay that recovers several days of prices changes historical numbers in reports. Analysts should hear about it from you, before they notice it themselves.
Replays and current state
The subtle risk in replay is time. A replayed record describes the page as it was when it was fetched, which might be days ago. Meanwhile, newer fetches of the same product may have succeeded after the fix, or before the failure started. Writing the recovered record as if it were current can overwrite fresher data with stale data.
The protection is to carry the fetch time through replay and make every write compare it. If your storage keeps history, as the guide on keeping history instead of overwriting rows recommends, the recovered record is inserted as a historical observation at its original fetch time, filling the gap, and the current state doesn’t change unless the recovered record is newer than what’s there.
If your storage keeps only current state, the write must check the fetch time against the stored record’s fetch time and skip the update if the stored one is newer. Without that check, replaying Tuesday’s backlog on Friday afternoon sets every affected product’s price back to Tuesday’s.
Event-driven pipelines face the same issue in a different form. A replayed record published to a topic arrives after newer records for the same entity. Consumers that maintain state from the topic must compare the event’s own occurrence time, not its arrival order, before applying it. The Kafka topic design guide in this series covers carrying that timestamp in every event’s envelope for exactly this reason.
Change detection needs care too. If a downstream system alerts on price changes, a replayed record from Tuesday followed by the existing record from Friday can look like a price change that happened today. Mark replayed records as such, and let change-detection logic treat them as backfill.
Turning dead letters into regression tests
Every resolved fingerprint leaves behind something valuable: a real page that broke a real parser, and a known-good record that the fixed parser extracts from it. That pair is a regression test, and it’s the best kind, because it came from production instead of from someone’s imagination about what might go wrong.
When a fingerprint is resolved, copy one or two of its sample pages into the saved-page test suite for that source, with the expected record from the successful replay. The testing guides in this series describe that suite: a set of stored pages per target with the records each should produce, run on every parser change. Adding dead letter samples to it means the same break can’t quietly come back in a later release. If someone refactors the date parser and reintroduces the format that failed in September, the test fails in CI instead of in production.
Pick samples that represent the failure, not just the first entry. If a fingerprint covered sale pages across three categories, one sample per category is worth more than three from the same one. If the fix handled a new date format, include a page with the old format too, so the test checks the fix didn’t break what used to work.
The suite grows with the pipeline’s actual history of failures. Over months it becomes a record of how each target has changed, which is also useful when someone new takes over a source and wants to know what tends to break.
There’s a triage benefit too. When a new failure appears, running its sample against the test suite’s previous fixes sometimes shows it’s an old fingerprint returning under a slightly different message. That points straight at the earlier fix and the code it touched.
Finally, give the queue an owner. A named person or rotation that looks at new fingerprints every working day keeps the backlog small. Without an owner, every alert is somebody else’s problem, and the oldest-entry age keeps climbing.
Retention, privacy and keeping it bounded
A dead letter queue holds raw pages, and raw pages can contain more than you meant to collect. Reviews with names, seller contact details, account information on pages that loaded while logged in. The queue can quietly become a second archive of raw content, with weaker controls than the main one.
Give it an explicit retention period. Entries older than the period are expired, meaning discarded with the reason “expired,” and their raw pages are deleted if nothing else references them. The period should be long enough to fix and replay typical failures, and short enough that the queue doesn’t become long-term storage. A few weeks to a couple of months covers most pipelines.
Apply the same access controls as the raw archive, or stricter. Triage needs the error, the fingerprint and a sample page, and not everyone who looks at fingerprint counts needs to open raw pages.
If you’re collecting under a policy that limits personal data, the dead letter queue is in scope. Pages that were supposed to be filtered before storage but failed parsing before the filter ran are exactly the ones that end up here unfiltered. Run the same redaction on dead letter inputs that the main pipeline applies, or make sure the stored raw pages already have it.
Size also needs a bound. A target that changes its markup across every template at once can produce a backlog of every page it has. Cap entries per fingerprint, keeping a representative sample plus a count of everything else, when a fingerprint grows past a threshold. You lose the ability to replay the full set, but in that situation a fresh crawl after the fix is usually the better recovery anyway.
What to do on Monday
If your collector currently logs parse failures and moves on, here’s the order we’d make the change in.
First, stop losing inputs. Make sure every page that fails parsing has its raw bytes in object storage, and that the failure record includes a pointer and hash. Even if nothing else changes this week, you can now recover from the next selector break without refetching.
Second, create the table. One row per failure, with the fields described above: input pointer, parser version, stage, error, field, source, URL, fetch time, status, attempts. Write to it in the same unit of work as the rejection.
Third, add fingerprints and a grouped view. A daily look at new and rising fingerprints per source is enough to start.
Fourth, add three alerts: new fingerprint, rate jump per source, and age of oldest unresolved entry.
Fifth, build replay as a small job that takes a fingerprint and a parser version, samples first, then processes the rest through the live pipeline’s own code, idempotently, respecting fetch time.
Sixth, set retention and access rules, and apply your redaction to the queue’s inputs.
Then, the next time a target changes its sale template on a Tuesday, you’ll know on Tuesday, fix it the same day, and have Tuesday’s prices back by the evening.
For the rest of the pipeline around a dead letter queue, from validation to storage to the contracts with your consumers, the full set of guides is at Data Research Tools.
Get new guides and videos first — join the Telegram channel.
Leave a Reply