Web scraping
What does a solid scraping pipeline look like?
It is a chain of small stages, from finding URLs to delivering clean records, with stored output between them, so a failure in one stage can be fixed and replayed without redoing the others.
The short answer
A solid pipeline separates what to fetch, fetching, extracting, checking and delivering. Each stage reads from a queue or a store and writes to the next one. Raw responses are kept, so parsing can be rerun. Records are validated before anyone sees them. And every stage is idempotent: running it twice on the same input gives the same result, which makes retries safe.
The stages
Discovery
Produces the list of URLs or API calls to make: sitemaps, category crawls, search queries, or a fixed list from a client. Output goes to a request queue with metadata such as priority, the reason for the fetch, and the last time this URL was fetched. Deduplicate here, using a normalized URL as the key.
Fetching
Takes a job, applies per-site rate limits, picks a proxy and headers, and makes the request or renders the page. If a check page appears, this is where the solving step lives: detect the widget, create a task, apply the token or cookie, and retry. The fetcher writes the raw response (body, status, headers, timestamp) to storage and passes a pointer onward. It does not parse.
Parsing
Reads raw responses and turns them into records. Keep parsers pure: HTML in, data out, no network calls. That makes them testable with saved pages and lets you rerun them over historical data after a fix. A data extraction stage that also discovers new links can push those back to the discovery queue.
Validation
Checks each record against rules: required fields present, prices numeric and in range, dates parseable, currency known. Records that fail go to a quarantine table with the reason, not into the main dataset. Batch checks compare today's run with yesterday's: a sudden drop in record count or field coverage stops delivery and raises an alert.
Storage and delivery
Valid records are upserted into the main store keyed by a stable id, so repeated runs update instead of duplicating. Delivery then exports to whatever consumers need: a database view, CSV files, an API or a message stream.
A sketch of the flow
discover -> queue:fetch (url, priority, reason)
fetch -> store:raw (url, status, headers, body_ref, fetched_at)
-> queue:parse (raw_id)
parse -> store:staged (record, raw_id, parser_version)
validate -> store:final (upsert by natural key)
-> store:quarantine (record, failed_rule)
deliver -> exports, API, alerts on anomalies
Recording the parser_version with each record tells you which code produced it, so you can find and reprocess records made by a buggy release.
Design rules that pay off
- Idempotency everywhere. Use natural keys and upserts. A retried job must not create a second copy. See idempotency.
- Retries with backoff. Transient errors (timeouts, 429, 503) go back to the queue with a delay that grows, as described under exponential backoff. Permanent errors (404, parse failures) do not loop forever.
- Dead letter queue. After a set number of attempts, park the job with its last error for a human to review.
- Configuration per site. Rate limits, headers, proxy pools and parser versions live in config, not scattered through code.
- Cost tracking. Log proxy bandwidth, browser minutes and CAPTCHA solves per site. With GateSolver, only solved tasks are charged, and the
costfield in each result makes per-site accounting straightforward.
Start small
None of this requires heavy infrastructure on day one. A single database can hold the queue, raw pointers and records in separate tables, and a cron job can run each stage. What matters is the separation: once fetching and parsing are apart and raw data is kept, growing to many workers is a deployment change, not a rewrite. The question on scaling a scraping setup covers that growth, and monitoring a scraper covers keeping it healthy.
Where pipelines usually break
The weak points are rarely the code paths you tested. They are a site redesign that returns valid HTML with no data, a block that returns status 200 with a challenge page, and a slow drift in field coverage that nobody notices for weeks. Validation and run-over-run comparisons are what catch these, which is why they deserve as much care as the fetcher.
Common questions
Why separate fetching and parsing?
So you can fix a parser and rerun it on stored pages without fetching again, and test parsers offline.
Where should CAPTCHA solving happen?
In the fetch stage. It is part of getting a valid response, and parsers should only ever see real content.
How do I avoid duplicate records?
Key each record by a natural id such as SKU plus site, and upsert instead of inserting.
What belongs in a quarantine table?
Records that fail validation, stored with the rule they broke and a link to the raw response.
Do I need a message broker?
Not at first. A database table can serve as a queue until volume or latency demands a broker.
Keep reading
- Request queueThe list of URLs a crawler still has to visit, with retries, priorities and deduplication built into how it is stored.
- IdempotencyThe property that repeating an operation has the same effect as doing it once, and why it decides which retries are safe.
- Solving CAPTCHAs in web scraping pipelinesAn architecture for scrapers that meet CAPTCHAs: detect challenges as their own outcome, solve in a separate stage, retry with clear limits.
- How do I scale a scraping setup?Split the scraper into a queue, stateless workers and separate storage, then add capacity where measurements show the bottleneck.