<?xml version="1.0" encoding="UTF-8"?>
<response><data><post><id>95</id><slug>retry-and-backoff-patterns-part-5-95</slug><title>Retry and backoff patterns, part 5</title><excerpt>This is part 5 of our series, and this time we focus on edge cases readers asked about. Networks fail, servers restart and rate limits kick in. A scraper that gives up at the first error is fragile;…</excerpt><seriesName>Retry and backoff patterns</seriesName><seriesPart>5</seriesPart><sections><item><heading>Introduction</heading><paragraphs><item>This is part 5 of our series, and this time we focus on edge cases readers asked about. Networks fail, servers restart and rate limits kick in. A scraper that gives up at the first error is fragile; one that retries instantly and forever is a nuisance.</item></paragraphs></item><item><heading>A practical approach</heading><paragraphs><item>Read the site's terms of service before you start. Many sites welcome automated access within limits and say so explicitly; others ask you to use an API instead.</item><item>Pagination comes in several shapes: numbered pages, next links, offsets and opaque cursors. Each has trade-offs, and a robust scraper should detect the end of the result set rather than assuming a fixed number of pages.</item><item>Character encodings still cause trouble. Decode responses using the charset the server declares, and normalise text before comparing or storing it.</item></paragraphs></item><item><heading>Step by step</heading><paragraphs><item>Dynamic pages render content after the initial HTML arrives. A browser automation tool can wait for a specific element to appear, which is far more reliable than sleeping for a fixed amount of time.</item><item>Always identify your client honestly with a descriptive User-Agent, and keep your request rate modest. A crawler that behaves like a considerate visitor is far less likely to cause problems for the site operator.</item></paragraphs></item><item><heading>Key takeaway</heading><paragraphs><item>Retry only on errors that can succeed later (timeouts, 429, 5xx), use exponential backoff with jitter, and cap the number of attempts.</item></paragraphs></item></sections><authorId>3</authorId><authorName>Priya Nakamura</authorName><authorSlug>priya-nakamura</authorSlug><category>Data Engineering</category><tags><item>scrapy</item><item>javascript</item></tags><publishedAt>2025-01-16T00:00:00.000Z</publishedAt><wordCount>222</wordCount><readingTimeMinutes>2</readingTimeMinutes></post></data></response>
