Project
Tube League Table
A pipeline that reads TfL's live feeds every minute, models them with dbt on Athena and Iceberg, tests every number against a quality gate, and publishes a weekly league for 20 London rail lines to a static site. About $1.80 a month.
- Collected
- every 60 s
- about 52 TfL calls a poll
- Coverage
- 20 lines
- arrival boards at 50 stations
- Modelled
- 32 dbt models
- 41 unit tests, 14 data tests
- Quality gate
- 87.1%
- of judged station-hours, bar 80%
- Runs for
- ~$1.80 / month
- projected, before VAT
TfL tells you what is happening on a line right now. Nobody publishes, week by week, how reliable each line actually was: what TfL’s status feed declared, next to what its arrival boards showed. That data doesn’t exist unless something records it every minute, because TfL’s live feeds can’t be fetched after the fact. The format is borrowed from football: a league table each week, with a top and a bottom people recognise.
Architecture
TfL Unified API on the left: line status and disruption, the arrival boards of about 50 stations (for the line scores) and, since M8, arrivals for every stop with one call per line (for station views), read every minute; timetables, route sequences and severity codes read weekly. In AWS eu-west-2: EventBridge Scheduler starts the poller Lambda every minute and a reference Lambda weekly; both read the TfL app key from SSM Parameter Store and write every response, failed calls included, to S3 raw as gzipped NDJSON. The Glue Data Catalog exposes raw to Athena through partition projection. Athena, in dev, prod and ops workgroups with scan caps, reads and writes Iceberg tables in S3 curated. CloudWatch alarms email through SNS, and an AWS Budget alerts at 50, 80 and 100% of 6.50 USD. In GitHub Actions, with short-lived OIDC credentials: infra plans Terraform on pull requests and applies on merge; ops-daily checks health; transform-daily runs the dbt build, tests and quality gate at 03:30; publish-weekly reads the marts on Mondays at 06:30, validates the JSON files, renders share cards and uploads to Cloudflare R2, then calls the Pages deploy hook. The Pages build validates the files again and publishes static pages at karshvashi.com/tube/. The weekly publish job is live and publishes to data.karshvashi.com; this site renders a snapshot vendored at build time.
- Line status feeds Poller Lambda
- Arrival boards feeds Poller Lambda
- Timetables feeds Reference Lambda
- EventBridge controls Poller Lambda
- EventBridge controls Reference Lambda
- Poller Lambda feeds S3 raw
- Reference Lambda feeds S3 raw
- S3 raw feeds Glue Catalog
- Glue Catalog feeds Athena v3
- Athena v3 feeds S3 curated
- transform-daily feeds Athena v3
- Athena v3 feeds publish-weekly
- publish-weekly feeds R2
- publish-weekly controls Pages build
- R2 feeds Pages build
- Pages build feeds karshvashi.com/tube/
- Collect. EventBridge Scheduler starts the poller Lambda every minute. It reads line status, disruption and the arrival boards of 50 stations, about 52 calls with bounded concurrency, and writes each feed’s responses unchanged, failed calls included, as one gzipped NDJSON object under
raw/{feed}/dt=…/hour=…. A second Lambda fetches timetables, route sequences and severity codes weekly. Both read TfL’s app key from SSM. - Keep everything. Raw is kept indefinitely and never edited. Every table downstream can be rebuilt from it.
- Catalogue. Glue tables with partition projection expose the raw prefixes to Athena. No crawlers: partitions resolve from the path.
- Model and test. At 03:30 London time a GitHub Actions workflow runs
dbt buildagainst Athena: staging, intermediate and mart models, the tests, and the quality gate. Dev and prod write to separate databases and prefixes, each with its own Athena workgroup and scan cap. - Export. On Mondays at 06:30 the publish workflow reads the marts, writes every file in the JSON contract, validates each one against its schema, and renders the share cards in headless Chromium.
- Publish. It uploads to Cloudflare R2, index files last, then calls the Pages deploy hook.
- Show. This site’s build reads the files, validates them again, and renders static pages. If anything fails, the previous week stays up.
CloudWatch alarms email on poller errors, throttles, a feed with no objects for 10 minutes, and TfL request failures. A daily health check reports completeness and freshness and keeps a GitHub issue open while anything misses its target. The weekly publish job is live and publishes to data.karshvashi.com.
Inside the transform
Raw line status, arrivals and timetables, plus 12 seed files of definitions, feed four staging models, which are Iceberg tables merged one whole day at a time: stg_line_status, stg_polls, stg_arrivals and stg_timetable. Declared path: stg_line_status and stg_polls feed int_line_minute_status, the status of every line in every minute; that feeds int_incidents and fct_line_daily; fct_line_daily feeds fct_line_weekly, which feeds nine report models (highlights, Monday Morning, engineering works, recovery time, division seeding, divisions, season, strikes excluded, status mix). Measured path: stg_arrivals and stg_polls feed int_inferred_arrivals; stg_arrivals feeds int_vehicle_passes, the trains seen on the boards by vehicle id; stg_timetable feeds int_scheduled_headways; int_inferred_arrivals feeds int_headways; int_headways, int_vehicle_passes and int_scheduled_headways feed int_measured_hours. The quality gate tests int_measured_hours: inferred trains must be 80 to 120% of the trains on the boards. Only then are fct_line_measured_daily and fct_line_weekly_measured built; fct_line_weekly_measured also reads fct_line_weekly. The export reads fct_line_weekly, the reports and fct_line_weekly_measured. Intermediate and mart models rebuild in full each run.
- line status feeds stg_line_status
- line status feeds stg_polls
- arrivals feeds stg_polls
- arrivals feeds stg_arrivals
- timetables feeds stg_timetable
- stg_line_status feeds int_line_minute_status
- stg_polls feeds int_line_minute_status
- stg_polls feeds int_inferred_arrivals
- stg_arrivals feeds int_inferred_arrivals
- stg_arrivals feeds int_vehicle_passes
- stg_timetable feeds int_scheduled_headways
- int_line_minute_status feeds int_incidents
- int_inferred_arrivals feeds int_headways
- int_headways feeds int_measured_hours
- int_vehicle_passes feeds int_measured_hours
- int_scheduled_headways feeds int_measured_hours
- int_incidents feeds fct_line_daily
- int_measured_hours feeds quality gate
- fct_line_daily feeds fct_line_weekly
- quality gate feeds fct_line_measured_daily
- fct_line_weekly feeds 9 report models
- fct_line_weekly feeds fct_line_weekly_measured
- fct_line_measured_daily feeds fct_line_weekly_measured
- 9 report models feeds export
- fct_line_weekly_measured feeds export
The dbt project has two paths over the same staging tables, and dependencies only run one way: the measured path may read declared tables, never the reverse. The declared path turns status polls into the status of every line in every minute, then incidents, daily and weekly scores, and the reports. The measured path infers arrivals from the boards, compares the gaps between trains with the timetable, and only builds its marts once the quality gate passes. A Python test reads the dbt graph and fails if anything on the declared side ever descends from the measured path, so a failed gate can hold back measured numbers but never the league.
Staging is incremental Iceberg, merged one whole day at a time. Everything after it rebuilds in full from the seed files on every run, so a changed weight or threshold applies to all of history at once.
Delivery and access
| Workflow | Runs | Role | Can do |
|---|---|---|---|
infra |
pull request; merge to main |
mtd-ci-plan, mtd-ci-apply |
read-only Terraform plan; deploy infra/envs/prod |
transform-daily |
03:30 London, daily | mtd-ci-transform |
Athena, Glue and S3 for the prod dbt target; no writes to raw |
publish-weekly |
Mondays 06:30 London | mtd-ci-publish |
read the prod marts, write only Athena query results |
ops-daily, ops-daytime |
daily; weekday middays | mtd-ci-observer |
read-only queries in the ops workgroup |
No workflow holds AWS keys. Each gets short-lived credentials through GitHub’s OIDC provider, and each role’s trust policy checks the repository by its immutable id and the exact workflow file, so a rename or a new workflow can’t borrow a role. The roles and a permissions boundary are applied by hand, outside CI, so nothing that runs unattended can widen its own access. A pull request only plans; merging applies it, and deletes need an explicit opt-in. The R2 token and the deploy hook URL reach only the upload step.
Design decisions
A minute missed is lost for good
TfL’s boards can’t be fetched after the fact. EventBridge Scheduler starts a Lambda once a minute, and each poll makes about 52 calls with bounded concurrency. Polling every 30 seconds would have meant an always-on container costing a few pounds a month more, while the arrival time comes from TfL’s own expected-arrival field either way, so one minute is enough. Polls can’t pile up: the code has a 45-second budget, neither the scheduler nor Lambda retries a failed poll (the next minute is the retry), and the function has a reserved concurrency of 1. That last setting had to wait: with the account’s concurrency quota at 10, reserving even one fails, so the poller shipped unreserved and switched once the quota rose.
Each poll writes TfL’s responses unchanged as gzipped JSON, failed requests included, so a gap is visible and never reads as Good Service. Pydantic models check the payloads only after the write, so a change in TfL’s format can’t lose data, and they reject a timestamp with no time zone rather than guess one.
Re-running a day must not count it twice
Raw keeps arriving until midnight, so the same day gets loaded more than once. Staging tables are Iceberg, merged on a row key one whole day at a time; dbt-athena has no insert-overwrite for Iceberg, and delete-then-insert would leave readers an empty day. The models downstream rebuild in full from seed files each run, so a changed definition applies to all of history at once rather than only to new days. A Sunday job compacts and vacuums the staging tables.
Tests that know the answer
The dbt project has 41 unit tests, each with expected rows computed by hand. One covers the clock changes: 00:30 and 01:30 UTC on 25 October 2026 are both 01:30 in London, and a separate test checks that the London days around the changes last 25 and 23 hours.
dbt unit tests run only against Athena, which CI can’t reach. On 15 November one fixture’s rows had different columns. Athena builds a fixture as a UNION, so the production run failed and skipped the divisions model. The fix was an offline check, run before merge, that every fixture’s rows share one set of columns.
Access the pipeline can’t widen
Everything the pipeline runs on is Terraform, in 8 modules, one per concern: raw bucket, data bucket, catalogue, Athena, Lambda functions, schedules, alarms and CI roles. Every Athena workgroup has a scan cap per query that clients can’t lift. Lambdas run outside a VPC, so there’s no NAT gateway to pay for.
From tables to this page
The weekly export writes JSON against a versioned JSON Schema contract and validates each file before upload. When the Disruption Index moved to its 0 to 800 scale, the minor version moved too, even though no field was removed, and every past week is rewritten on the next run so the site never mixes scales. Playwright renders each week’s share card from an HTML template, and fails rather than writing a card whose text overflows.
The files go to Cloudflare R2, index files last so they never list a file that isn’t there yet, and then a deploy hook rebuilds this site. The site validates the files again as it builds; if anything doesn’t match, the build fails and the previous week stays up. The weekly publish job is live and publishes to data.karshvashi.com. This site doesn’t fetch those files at runtime: it renders a snapshot vendored at build time, and the table shows the latest one vendored.
What it found
TfL sayswhat TfL's status feed declaredBoards showwhat TfL's arrival boards showed at the measured stations
| Line | Trains on the boards · excess wait | |
|---|---|---|
| District | 74.1% · 1.34 min | |
| Metropolitan | 76.7% · 3.17 min | |
| Jubilee | 84.8% · 0.85 min | |
| Central | 85.8% · 0.82 min | |
| Victoria | 85.9% · 0.76 min | |
| Piccadilly | 87.0% · 0.78 min | |
| Bakerloo | 91.6% · 0.54 min |
The 7 lines ranked on waiting time, sorted by share on the boards, lowest first. A lower bound: the boards can miss trains that ran. Excess wait comes from the same boards.
The figures here are all from week 46 (9 to 15 November).
- Boards show About three in four District and Metropolitan trains on the boards. The boards showed 74.1% of the District’s timetabled trains and 76.7% of the Metropolitan’s, against 91.6% of the Bakerloo’s. A train missing from the boards isn’t proof it didn’t run, and that question is still open.
- Boards show Extra waiting ranged from 0.54 to 3.17 minutes. Excess wait is how much longer the average passenger waited than the timetable implies, assuming people turn up at random. It was 0.54 minutes on the Bakerloo, 0.76 on the Victoria, 1.34 on the District and 3.17 on the Metropolitan. It is worked out from the same boards, so a train the boards miss makes the wait look longer.
- TfL says What TfL declared. On the Disruption Index, which runs from 0 (Good Service throughout) to 800 (suspended throughout), Liberty was top at 0. The District was 18th at 152, with Good Service for 26% of scored time.
- Lines that can’t be judged fairly are marked or left out. The Suffragette line was bottom at 259, but marked provisional: it was closed for engineering works for 34% of its scheduled minutes and scored on the rest. A line open for under half its scheduled hours isn’t ranked at all, as the Suffragette wasn’t from 4 to 10 November, when it was closed for 96%. The Circle and Hammersmith & City are left out of the measured view because the boards misfile trains on their shared track.
This is one week, so nothing here is a trend yet.
Every line, on a map you can query week by week, with each number traced back to the feed it came from: the network tool. The full league: the table.

How do you measure a train that might not exist?
TfL doesn’t publish when trains actually arrived. Its arrival boards show predictions, and the poller reads them every minute at about 50 stations. When a train was last seen within 120 seconds of the platform and is gone from the next poll, that’s an arrival. The rules exist twice, as dbt models and as a Python reference implementation, and a parity test feeds both ten minutes of real boards plus synthetic edge cases.
That makes the boards the evidence, and the boards are not a train register. On most Tube lines they list about 85% of the timetable. Either the missing trains didn’t run, or they ran and never appeared. The data can’t yet say which, so every figure built on it is a lower bound.
The first published week 46 overstated how many trains were missing. At some end stations TfL lists departing trains with no direction, so they were never counted, and Uxbridge read almost zero. At others it lists one train on two platforms, so it was counted twice. Trains on the boards is now measured at stations along each line, as the quality gate already was. That moved the Metropolitan from 67.6% to 76.7% for week 46 (9 to 15 November). TfL’s status figures were unaffected.
Two more things can go wrong:
- Held trains. A train waiting just outside a platform can be counted more than once, which shortens the gaps between trains exactly when service is bad. So the measured view leans towards hiding delay, not inventing it. Linking sightings by vehicle id fixes this where ids are stable: the Victoria and eight more Tube lines. The District stays unlinked, because its ids follow only 78.5% of westbound trains from Victoria to Earl’s Court.
- Boards that misfile. At Baker Street, King’s Cross and Liverpool Street, every westbound train is listed as Hammersmith & City, Circle trains included. Both lines’ measured numbers would be wrong in opposite directions, so neither is published.
Some lines get no measured numbers at all: the DLR, tram, Waterloo & City and Suffragette aren’t measured, and a line whose own week fails the quality check is withheld with the reason shown. The Elizabeth line and the Overground have no TfL timetable to compare with, so they are measured against estimated frequencies, shown, and not ranked. In week 46 (9 to 15 November), 9 of 20 lines had measured numbers and 7 were ranked on them.
The quality gate
Every measured number rests on inferred arrivals, so the inference needs a check that can fail. The plan’s check judged each core-station hour: inferred trains had to be 80% to 120% of the timetable, and at least 80% of hours had to pass.
The first method passed 65.4%. The obvious fix was to link sightings by vehicle id on more lines. On 9 to 12 November that moved the score from 65.9% down to 63.9%. A better inference had scored worse.
Counting the vehicle ids that came within 120 seconds of each station showed why. The boards list only about 85% of timetabled trains, and the inference found almost exactly those: 14,714 inferred arrivals against 14,990 trains on the boards on the Victoria line. Measured against the timetable, the gate couldn’t tell a train the inference lost from a train the boards never showed.
So the gate changed what it compares with. It now checks inferred trains against the trains seen on the boards, with the same 80% to 120% band. At five trains an hour, ±20% is one train. Trains against the timetable became a measure of its own, the lower bound above. From 9 to 13 November, 87.1% of 5,620 judged core-station hours pass, against 65.4% on the same hours under the old test. This is a redefined test, not the old one passing: it checks the inference against the boards, and says nothing about whether the boards are right.
Two choices keep it honest:
- It decides per line-week. A line’s measured numbers publish only when its own week passes. For 9 to 13 November the Piccadilly (74.1%) and Metropolitan (75.5%) were under 80% on their own, mostly from held trains counted twice. After vehicle-id linking was extended from 15 November, the week 46 figures (9 to 15 November) are 97.5% and 83.6%, and both lines publish measured numbers.
- It can’t freeze the declared league. The gate test runs at
error, but a failure skips only the measured models. They moved into their own model, and a Python test reads the dbt graph and fails if anything on the declared side descends from the measured path. A red gate means a red run and no new measured numbers; the declared table still publishes.
What it costs
From 1 to 13 November the whole AWS account cost $1.30, including VAT and under a cent from another project. The project’s own tagged spend was $0.81, counted from 8 November. A steady day costs $0.057, which projects to about $1.80 a month before VAT. The budget alert is set at $6.50. These are a partial month; the full-month figure comes after 1 December.
Lambda, Glue, EventBridge and CloudWatch cost nothing at this size. Two thirds of the bill is S3 PUT requests, about $1.15 a month, from writing one object per feed per poll. That’s the price of keeping raw lossless and replayable. Storage is the only line that grows.
What’s still open
- Did the missing trains run? The boards list about 85% of timetabled trains. Until that is answered against an independent count, trains on the boards stays a lower bound. The Honesty Gap, hours when TfL declared Good Service while the boards showed a long gap, stays off the share card. An hour counts only when at least two core or branch stations (not termini) in the same direction each show a long gap in it, with Good Service declared across the whole of each gap; a line with fewer than two such stations, such as Lioness, Windrush or Liberty, cannot be checked and has no figure, which is not the same as 0. Long gaps are measured from TfL’s arrival boards, which list about 85% of timetabled trains; if the rest ran, some gaps exist only on the boards.
- Circle and Hammersmith & City. Separating their trains needs each train’s history across stations. Not built yet.
- The District can’t be linked by vehicle id, so its measured numbers rest on the less precise method.
- Every station. The line scores read arrival boards at about 50 stations. Station views for every station are now on the map, sitting beside the line scores and not feeding them.
- No outside check yet. Once three four-week periods exist, the ranking will be compared with TfL’s own share of scheduled trips operated.
- The weights are judgement. The severity and time weights are choices, so each week is also re-ranked under three alternative sets and the rank changes are published.
The football layer
The weekly table is the first layer. Next come divisions, with monthly promotion and relegation between them, and a season table from April to March. Divisions are seeded from the first two full weeks and marked provisional until four exist. They appear here as the data arrives.
The methodology has every weight and threshold.