Skip to content
dheeraj@webidentity 
AutomationLive2026

Companies House Lead Engine

The UK’s entire public company register, turned into pre-qualified leads at zero cost per lead.
Role
Sole developer, end to end — at Mirasphere Digital, for an agency client
Client
Swann Bookkeeping & Accountancy
Year
2026

Stack

Each choice with the reason for it.

  • Python

    language

    The core job is a 2.9GB CSV of roughly five million rows. That is pandas territory, and choosing the right tool mattered more here than keeping one language across the portfolio.

  • pandas

    tooling

    Chunked ingest at 25,000 rows at a time is what lets a modest VPS process the whole register without a single API call, or a memory ceiling.

  • FastAPI

    framework

    The dashboard needed to start jobs, watch progress and export leads. FastAPI keeps that surface thin and typed, next to the Python that does the actual work.

  • PostgreSQL

    database

    Nine tables holding jobs, resumable cursors, a 30-day verdict cache and a suppression list. Every one of those is a correctness requirement — a lead sent to a suppressed contact is a compliance failure, not a bug.

  • React

    framework

    Long jobs need live progress. A dashboard that shows a batch advancing is the difference between trusting a six-minute scan and refreshing a log file.

  • Docker

    infrastructure

    Jobs die on deploys and restarts, so the deploy path had to be boring and repeatable before the resumability work meant anything.

  • Caddy

    infrastructure

    TLS and reverse proxying with no configuration to forget, on a single-box deployment where the ops budget is one person’s attention.

01 · Context

Accountants win clients whose filing deadlines are close. Companies House publishes every company’s accounts due date and offers no way to query for it, and the paid lead platforms that fill that gap charge per lead for data that is already public.

02 · Problem

Turn the UK’s public company register into a pipeline of pre-qualified, contactable leads — at zero marginal cost per lead.

03 · Constraints

What was fixed before the work started, and what each constraint ruled out.

  • Companies House rate limits at 600 requests per five minutes — stay a good citizen at half the ceiling
  • The full register is a 2.9GB monthly CSV of roughly five million rows
  • Bulk data goes stale, so a "due" flag must be verified before anyone calls
  • GDPR and PECR: lawful basis and suppression built into the schema, not bolted on

04 · Approach

Hybrid by design. Source offline from the full bulk register with pandas in 25,000-row chunks, verify online through the rate-limited REST API, and make every long job restart-survivable: resumable batches with an auto-advancing cursor, and an orphan-job sweep on boot. The bulk file answers "who might be due" for free; the API answers "who actually is" for the few hundred that matter.

05 · Architecture

Each component, why it beat the alternative, and where it gives way first.

  1. 01Bulk ingest

    pandas, chunked CSV
    Purpose
    Reads the full monthly company register into Postgres.
    Why this, not the obvious alternative
    The whole register, without a single API call. 25,000-row chunks keep memory flat regardless of file size.
    What breaks first

    The snapshot lies, and it lies confidently. It is monthly, so a company that filed yesterday still reads as due — live verification on a cohort of 162 flagged companies confirmed only 83 were actually overdue. Nothing downstream may treat the bulk flag as truth.

    Connects to
    • Filter engine · Rows
  2. 02Filter engine

    Python rules
    Purpose
    Narrows five million rows to candidates by due-date window, sector and geography.
    Why this, not the obvious alternative
    Deterministic rules over a local table cost nothing to run and can be re-run the moment the definition of a good lead changes.
    Connects to
    • Verifier · Candidates
  3. 03Verifier

    Companies House REST + sliding-window limiter
    Purpose
    Checks the live company profile before a lead ships; caches verdicts for 30 days.
    Why this, not the obvious alternative
    A live check is the only thing that turns a stale flag into a fact, and the 30-day cache keeps the API budget spent on companies nobody has looked at yet.
    What breaks first

    The rate limiter is the bottleneck and the point of failure by design. It runs at half the published 600-per-five-minute ceiling to leave headroom for retries, so verification is deliberately the slow stage — and an eight-step backoff honouring Retry-After exists because 429, 404, 5xx and TLS failures need different answers.

    Connects to
    • Enrichment · Confirmed due
  4. 04Enrichment

    3-tier matching + Hunter
    Purpose
    Finds the company’s website and a contactable address.
    Why this, not the obvious alternative
    Matching is scored on evidence rather than guessed: a registered number in a site footer scores 95, a postcode match 80. A wrong match is worse than no match.
    Connects to
    • Store · Leads
  5. 05Store

    PostgreSQL, 9 tables
    Purpose
    Jobs, resumable cursors, verdict cache, suppression list.
    Why this, not the obvious alternative
    The cursor is what makes a long job survivable, and the suppression list is a schema-level obligation rather than a checkbox in an interface.
    Connects to
    • Dashboard · Jobs + exports
  6. 06Dashboard

    React + FastAPI
    Purpose
    Run jobs, watch progress, export leads.
    Why this, not the obvious alternative
    The jobs take minutes and can resume mid-batch. Progress has to be visible or nobody trusts the output.

06 · Implementation

Ingest reads the monthly register in 25,000-row chunks, so memory stays flat whatever the file does. Filtering happens locally against Postgres, which makes the definition of a good lead cheap to change. Verification is the expensive stage and is treated as such: a sliding-window limiter pinned at half the published ceiling, an eight-step backoff that honours Retry-After, and separate handling for 429, 404, 5xx and TLS failures, because retrying a 404 forever is how you get banned for a company that does not exist. Verdicts cache for 30 days. Enrichment scores matches on evidence rather than similarity — a registered company number in a site footer scores 95, a postcode match 80 — and Hunter fills the contact gap only after a match is trusted. Nine Postgres tables hold jobs, cursors, the verdict cache and the suppression list; the cursor auto-advances so a batch killed by a deploy resumes rather than restarts, and an orphan-job sweep on boot cleans up whatever the last restart left mid-flight.

07 · Challenges

What resisted, with the specific symptoms.

  1. Challenge 01Long jobs died mid-batch on deploys and restarts, losing hours of scanning
  2. Challenge 02The bulk snapshot flagged companies as due that were not: live verification found only 83 of 162 flagged companies were actually overdue
  3. Challenge 03Distinguishing 429, 404, 5xx and TLS failures so each got the correct retry behaviour rather than a generic one

08 · Solution

Resumability was solved with slice-and-continue batches and an auto-advancing cursor, plus an orphan-job sweep on boot — one 42,119-row batch was processed across five resumed runs without losing position. Staleness was solved by refusing to trust the snapshot: the bulk file produces candidates, and the live REST profile decides. Retry behaviour was solved by classifying failures properly and building an eight-step backoff that honours Retry-After, which is why 22 production scrape jobs have run without a single rate-limit incident.

09 · Results

The outcome in the client’s terms, then any measurement, with its source and date.

It fills the firm’s outreach pipeline at zero cost per lead, with every lead pre-qualified by a live-verified filing deadline rather than a stale flag — and it does it from data that was already public.

  • Register cohort scanned

    171,876 companies in ~6 minutes

    Source
    Self-measured
    Captured

    Self-measured: my own measurement under my own conditions, not independently verified. Treat it as an indication, not evidence.

  • Companies matched in one imported batch

    8,668 from 42,119 rows

    Source
    Self-measured
    Captured

    Self-measured: my own measurement under my own conditions, not independently verified. Treat it as an indication, not evidence.

  • Rate-limit incidents

    0 across 22 production jobs

    Source
    Self-measured
    Captured

    Self-measured: my own measurement under my own conditions, not independently verified. Treat it as an indication, not evidence.

10 · Reflection

What I would do differently now, and why.

Rejecting the Streaming API was right, and it was the decision the whole design rests on: streaming answers "what changed", and the business question is "who is due", which is a full-register scan. The next leap is not more coverage but better ranking — scoring leads by likelihood to switch accountants rather than by deadline alone, because a deadline tells you who is under pressure and not who is unhappy.