Distributed crawl workers on Pub/Sub
- Problem
- Pub/Sub delivers each message at least once, crawls can run for hours, and many workers run at the same time. Done naively, that means duplicate batches, stuck messages and retry loops that never end.
- What I did
- Built the service. The backend takes a Postgres advisory lock per job and removes duplicate batches by content hash before anything is crawled. Workers pull up to 50 messages at a time and extend their leases for long scrapes. A batch gets 3 delivery attempts, then is marked Failed, and a harvest with zero rows counts as a failure, not a success.
- Result
- Collection on the projects moved onto it went from about 50M rows a year with the old scrapers to about 50M rows a week, roughly 52x. Every crawl is visible as a job with batches that are clearly Completed or Failed. I have written about 70% of its commits.
Python, GCP Pub/Sub, Cloud Storage, Kubernetes