backend
Technical notes on web development, DevOps, and AI integration.
157 articles
- 17:58backend
An Honest Contract for Batch Ingest Endpoints
One success number for a whole batch hides partial failure. Per-item created/updated/unchanged/rejected status makes it visible.
TL;DR: The new POST endpoint replaces a single batch status with per-item outcomes plus a summary so partial failures are visible. Guards cap payload size and item count, rate-limit per source, and fail closed with proper status codes including constant-time auth. Each item is marked created, updated, unchanged or rejected via a content hash, with an audit row for every request.
#fastapi#api#rest-api - 17:47backend
Defining Ingestion Identity Beyond Raw Strings
The same company landed twice because the name was spelled two ways. A content hash over a canonical tuple closes that duplication gap.
TL;DR: Duplicate company rows appeared because the pipeline relied on raw text and sender references instead of semantic identity. The fix normalizes company names and builds a SHA-256 hash from core values, enforced by a database unique constraint with upsert logic. This stops same-source duplicates reliably but does not handle cross-source entity merging, which needs separate resolution.
#postgresql#python#sqlalchemy - 15:19backend
Recovery-Only Rebuild: Lessons from a Corrupted Ledger
A rebuild turned 20 healthy ledger rows into 77 UNKNOWN. The fix: a recovery-only contract that fills gaps and never rewrites healthy rows.
TL;DR: A rebuild tool corrupted a court-rulings ledger, inflating twenty healthy rows to seventy-seven, mostly tagged UNKNOWN. The cause was structural: per-tab raw files re-parsed as new records, proving raw-is-truth doesn't make re-parses safe. The redesign makes rebuild recovery-only: healthy rows stay verbatim, only missing cases are appended, sub-tab files are skipped, and any UNKNOWN aborts all writes.
#python#data-engineering#sqlite - 15:19backend
Tracing Harvested Data with Agent Guardrails and SQLite Logs
Two local guards for scraping pipelines: an AGENTS.md rulebook for coding agents and a per-target SQLite audit log made idempotent with UPSERT.
TL;DR: When a harvest run died, git couldn't trace which commit produced the data—it records file changes, not execution context. The fix was two guards: an AGENTS.md rulebook forbidding writes to harvested data and secrets in commits, plus a per-target SQLite audit log. UPSERT on a unique commit-case-tab key keeps re-runs idempotent, turning provenance recovery into a single query.
#sqlite#scraping#audit-trail - 12:19backend
When Deep Links Rotate, the Search Box Is the Address
Pagination URLs carry rotating session tokens that die within the hour. Drive the app's own search form instead, then flatten parsed values before comparing.
TL;DR: Apps that mint session-bound URLs make deep links unreliable, so drive the search form instead: type the exact document number, verify the detail page, and log the query rather than the link. Normalize parser output by flattening lists and lowercasing strings before status comparisons. Flag mismatches for human review instead of stopping the run.
#scraping#python#data-engineering - 11:14backend
Through One Door: A Retry-Safe Harvest Ingest Contract
A scraping workspace kept apart from the app, and a replayable single-door API delivery: resumable queue, stable dedupe key, ship log.
TL;DR: A mid-run interruption exposed the risk of writing scrape results straight into the app database, so this commit isolates all scraping tools and stores per-page, per-subtab queue rows with status and attempt logs on disk. Resuming is then deterministic. Shipping happens separately through one ingest endpoint, using stable deduplication keys and exponential backoff so idempotent retries make replays safe.
#scraping#idempotency#data-engineering - 10:30backend
The Raw-First Pattern for Gated Data Harvests
Why gated data harvests save verbatim raw text before parsing: an idempotent ledger, a resumable cursor, and retroactive rebuilds.
TL;DR: When scraping captcha-gated, session-locked court portals, save the verbatim rendered text first and parse later from local files. Resumable cursors and idempotent upserts keep crashes from corrupting data. This bronze-layer approach means parser fixes apply retroactively without ever hitting the fragile site again.
#scraping#idempotency#audit-trail - 05:13backend
Scraping via the Preview Panel: The Session Is the Credential
The preview panel session is the scraping credential: rotating URL tokens, cosmetic click failures, CDP left dead.
TL;DR: When scraping Jakarta's court portal, external fetches only hit captcha walls because the browser session inside the panel carries the real credentials. Rotating tokens force click-driven navigation, and automation success flags lie, so verify via URL and DOM instead of auto-retrying. This approach harvested 4,828 bankruptcy cases across 242 pages, keeping sessions in-panel with checkpoints instead of URL replays.
#scraping#browser-automation#captcha - 04:26backend
GraphQL from the Site's Own Bundle: 7 Requests over 533 Pages
Finding a site's own GraphQL endpoint in its public JS bundle: 5330 rows in 7 requests, not 533 HTML pages.
TL;DR: Expecting a tedious HTML scraping job for Indonesia's procurement blacklist, the author found an unauthenticated GraphQL endpoint exposed by the site's XLSX export. A perPage of 800 meant the full 5,330-row dataset downloaded in just seven requests and about ten seconds. The daily snapshot plan was retired in favor of a simple full-dataset sync.
#scraping#graphql#nextjs