Backend & GCP Data Engineer Guide: Resilient Asyncio Extraction & BigQuery ETL Pipelines
Enterprise market intelligence, e-commerce price monitoring, and AI training pipelines break when built on fragile single-threaded scripts that crash on DOM changes, leak browser memory, or insert duplicate rows when a job retries. Production data ingestion requires bounded `asyncio` concurrency, strict Pydantic schema validation, dead-letter quarantine queues, and idempotent staging-to-target merges in BigQuery or PostgreSQL. As a Senior Backend Engineer and Google Certified Professional Data Engineer, here is how I architect fault-tolerant extraction and ETL pipelines.
1. Bounded Asyncio & Playwright Browser Context Pooling
Launching a fresh Chromium OS process per URL consumes 300MB+ of RAM and saturates CPU within seconds. Instead, a production worker maintains a single browser instance and recycles isolated, lightweight BrowserContext sessions governed by an `asyncio.Semaphore` and deterministic content hashing:
import asyncio
import hashlib
from pydantic import BaseModel, HttpUrl
from datetime import datetime, timezone
class ExtractedProductRecord(BaseModel):
source_url: HttpUrl
sku: str
price_cents: int
currency: str
content_sha256: str
extracted_at: datetime
async def extract_with_context_pool(browser, urls: list[str], max_concurrency: int = 8) -> list[ExtractedProductRecord]:
sem = asyncio.Semaphore(max_concurrency)
results: list[ExtractedProductRecord] = []
async def _worker(target_url: str) -> None:
async with sem:
context = await browser.new_context(java_script_enabled=True)
try:
page = await context.new_page()
await page.goto(target_url, wait_until="domcontentloaded", timeout=15_000)
sku = (await page.locator("[data-testid='product-sku']").inner_text()).strip()
raw_price = (await page.locator("[data-testid='product-price']").inner_text()).strip()
cents = int(float(raw_price.replace("$", "").replace(",", "")) * 100)
digest = hashlib.sha256(f"{sku}:{cents}".encode()).hexdigest()
results.append(
ExtractedProductRecord(
source_url=target_url,
sku=sku,
price_cents=cents,
currency="USD",
content_sha256=digest,
extracted_at=datetime.now(timezone.utc),
)
)
finally:
await context.close()
await asyncio.gather(*(_worker(u) for u in urls))
return results
2. Idempotent Partitioned `MERGE` into Google BigQuery
Extracted batches are streamed into a date-partitioned staging table on GCS/BigQuery and merged into the canonical analytical table keyed on `(sku, content_sha256)` so retries never duplicate historical price-change events.
3. Hire a Senior Backend & GCP Data Engineer
Building high-volume data ingestion, market intelligence, or BigQuery ETL pipelines? Explore my GCP Data Engineer Pillar Guide, review my Backend Engineer Pillar Guide, or book a 1-Day Data Pipeline Architecture Sprint.