GridSignal.
Great Britain electricity intelligence
From fragmented electricity feeds to a system people can investigate. GridSignal combines reproducible ingestion, SQL analytics, geospatial comparisons and a deployed API in one connected analytical workspace.
One grid. Several different signals.
Electricity data arrives through separate providers, publication schedules and measurement definitions. Carbon intensity describes emissions per unit of electricity; generation shares describe composition; metered outturn and demand describe power. Connecting them requires preserving those distinctions throughout the data pipeline.
I built GridSignal to make that investigation practical: move from a national overview to a time period, fuel or region, inspect the source evidence, and export the observations behind the result.
The grid, in perspective
Six streams, explicit contracts
| Stream | Provider | Purpose |
|---|---|---|
| National carbon intensity | NESO Carbon Intensity API | Published forecast and estimated actual intensity |
| Regional intensity | NESO Carbon Intensity API | Regional forecasts and generation composition |
| National generation mix | NESO Carbon Intensity API | Fuel shares at half-hour intervals |
| Metered fuel outturn | Elexon Insights / FUELHH | MW by original fuel category and publication time |
| Electricity demand | NESO Data Portal | National and transmission demand by settlement period |
| Published carbon factors | NESO Carbon Intensity API | Reference values with acquisition lineage |
Source-specific clients handle request pacing, retries, pagination and historical resource discovery. Response-contract checks detect structural changes, while Pydantic models validate individual records. Original HTTP responses remain available alongside the normalised facts.
A reliable path from source to screen
- 01Official APIsNESO and Elexon source clients
- 02Acquire & validatePython · contracts · Pydantic
- 03PostgreSQL warehouseRaw evidence · facts · revisions · operations
- 04SQL analytical martsTime-series, regional and quality metrics
- 05Read-only APIFastAPI · validated filters · connection pool
Collection that can recover and explain itself
Each collection run records its extraction window and obtains a source-specific database lock. Raw responses are committed before the fact-processing transaction. Failed processing preserves the acquired evidence while rolling back incomplete fact changes.
- Batched, hash-sensitive upserts insert new facts, skip unchanged observations and preserve meaningful revisions.
- Elexon publication ordering prevents an older release from replacing a newer stored observation.
- Progress checkpoints and overlapping extraction windows support bounded recovery after missed runs.
- A continuous reporting calendar supplies expected intervals independently of received data.
- UTC storage and Europe/London settlement mapping handle 46-, 48- and 50-period reporting days.
Ask a question, then follow the evidence
Carbon intensity through time
PostgreSQL computes period comparisons, distributions, hourly and weekday profiles, volatility, rankings and paired forecast–estimate differences. The browser consumes these analytical results rather than maintaining a separate set of metric definitions.
Generation and demand, with units intact
Spatial context without losing the national picture
Regional intelligence
The map uses licensed NESO distribution-network boundaries, transformed from British National Grid to WGS84 and simplified for the browser. Documented region mapping connects the geometry to source identifiers; the national series remains separate from regional forecasts.
A workspace, not a collection of notebooks
- Seven connected screens: overview, carbon, generation and demand, regions, forecast performance, operations and methodology.
- URL-backed date, region, fuel, resolution and comparison filters make analytical views shareable.
- Chart selections and regional comparisons connect summary views to underlying observations.
- Accessible data tables, keyboard navigation, responsive layouts and reduced-motion support accompany the visualisations.
- CSV exports return the full filtered dataset, independently of visible table pagination.
Reliability belongs in the architecture
I separated scheduled collection from recovery orchestration. The hosted system collects every six hours and retains the original half-hour observation intervals. This bounds compute and storage use on free infrastructure without changing the analytical grain of the source data.
| Layer | Responsibility | Execution policy |
|---|---|---|
| Primary collection | GitHub Actions acquires and validates official observations | Every six hours |
| Catch-up checks | GitHub Actions inspects collection status before starting ingestion | Hourly; healthy collections are skipped |
| Independent scheduler | Cloudflare Workers checks public source status and requests the ingestion workflow | Hourly; overdue, failed or missing collections qualify |
| Concurrency controls | Workflow concurrency and source-specific database locks coordinate writes | An active workflow suppresses duplicate recovery dispatch |
The independent scheduler reduces reliance on a single cron service. It dispatches the same ingestion workflow in due-only mode, where freshness is checked again before dependencies are installed or observations collected. GitHub Actions remains the execution layer; the design provides a second scheduling path rather than a second database writer.
Machine authentication uses a GitHub App installed on this repository only, with Actions read/write and read-only metadata access. Its private key is encrypted in Cloudflare, and short-lived installation tokens are generated for each check. The Worker has no database credentials or public administration endpoint. Authentication is validated even when collection is healthy.
Freshness is a source contract
Observation time, publication time and collection time answer different questions. A successful collection confirms that the pipeline contacted and processed a source; it does not imply that the provider published a newer observation. GridSignal exposes observation age separately from collection status and preserves publication ordering where supplied.
NESO carbon and regional forecasts update every thirty minutes; Elexon FUELHH publishes half-hourly outturn. Demand follows a daily publication cycle with settlement-data latency. Carbon factors are reference values, so their acquisition timestamp is not evidence of a newly measured grid condition.
- A scheduled wait is distinct from a failed attempt or an overdue collection.
- Delayed upstream observations alone do not trigger repeated recovery pulls.
- Missing intervals remain visible and are included in calendar-based completeness calculations.
- Human-readable timestamps and consistent numerical precision make operational evidence usable alongside the charts.
- Heatmap tooltips identify the reporting date, hour, value and unit; missing observations remain distinct from measured zero.
Deployed from ingestion to interface
The public workspace runs on Vercel, with FastAPI on Render and PostgreSQL 18 on Neon. GitHub Actions provides collection and catch-up execution; Cloudflare Workers provides independent recovery scheduling. Docker Compose reproduces the complete database, migration, API, worker and frontend topology for development.
Collection status distinguishes a normal wait for the next scheduled update from failed or overdue work. Observation age remains visible separately, including cases where collection succeeds but an upstream provider has not published newer data.
Source timestamps, run counters, validation results and calendar completeness are part of the product. They help a user decide whether a pattern is ready to interpret, rather than asking them to trust a dashboard simply because it has rendered.
Correctness checked at each boundary
| Layer | Evidence |
|---|---|
| Python, API and database | 51 automated checks, including isolated PostgreSQL integration tests |
| Frontend utilities | 5 unit tests for reporting dates, missing values and request behaviour |
| Browser experience | 36 checks across desktop, tablet and mobile Chromium |
| Containers | Fresh Compose startup, migrations, all six adapters and a database-backed overview |
| Hosted application | Anonymous access, HTTPS, exact-origin CORS and 38 analytical routes verified |
Regression checks cover idempotency, revision ordering, interrupted collection, reader isolation, forecast-pair null handling, daylight-saving boundaries and completeness denominators. Collection-state tests include schedule grace, failed attempts, stalled work and delayed upstream observations.
Eight watchdog tests verify healthy-source skipping, recovery eligibility, active-run suppression, workflow scoping, visible authentication failures and cryptographically signed App tokens. A deployed scheduled-handler test also verified encrypted App authentication and a healthy-source response. These checks establish handler behaviour; scheduler delivery and upstream availability remain separate operational concerns.
Keep the interpretation as precise as the system
National actual intensity is an estimate; regional series are forecasts. Forecast comparisons describe published forecast–estimate differences, not retrospectively reconstructed issue-time skill. Metered outturn does not provide complete embedded-generation coverage, and interval-average fuel shares are not consumption-weighted energy shares.
The hosted edition collects every six hours, so half-hourly source resolution should not be confused with half-hourly dashboard freshness. Recovery uses independent scheduling but still depends on GitHub execution, provider availability and free-service quotas. The API can take about a minute to resume after inactivity.
The next engineering stage is source-specific collection cadence: publication-aware schedules, measured release buffers and separate reporting of the last check and the last newly received observation. Further priorities are controlled cold-start measurement and longer historical comparisons within an explicit retention policy.