Skip to content
Work

Case study · data engineering · running now

A production pipeline, running on this site

Every minute, a pipeline I built pulls Dublin's live bus feed, checks it, loads it and records how the run went. The numbers on my homepage come from it, and so does the ops console in the playground. It costs nothing to run.

Live · Dublin buses, right now

last pipeline run 51s ago · ok

Buses on the road
1,017
150 routes running
Median delay
+3.3 min
1 in 10 is +13.8 min or worse
On time
57%
1 min early to 5 min late
Buses, last 24 h
building history…
Collected every minute by a pipeline I built and run. 100% of runs succeeded in the last 24 h.How it worksOps console

Why build it

My first Dublin bus project was a notebook-and-SQLite pipeline that I ran by hand. It proved the analysis, but nothing about operating data in production. Hiring managers ask about the second part: what happens when the feed is late, when a join quietly drops half the rows, when a retry double-counts. So I rebuilt it as a small system that runs by itself, and that I can be paged by.

Architecture

TFI GTFS-Realtimeprotobuf, 1 req/minCron Triggerevery minuteWorker: extractdecode in ~3 msvalidate + transform5–6 checks per runD1 (SQLite)runs · seriesread API (same Worker)JSON + CSV, cachedmycodingjourney.comhome strip · ops console · SQL
  • Source: Transport for Ireland's GTFS-Realtime API, two feeds: vehicle positions and trip updates (delays). The key allows about one request a minute, so the two feeds take turns: vehicles on even minutes, trip updates on odd minutes.
  • Compute: one Cloudflare Worker with a cron trigger. No servers, no containers.
  • Storage: D1 (SQLite at the edge): a runs table, fleet and delay time series, per-route delays every 15 minutes, and the latest snapshots.
  • Serving: the same Worker answers a small read-only API (JSON and CSV) that this site proxies.

Decisions worth explaining

A hand-written protobuf decoder

The trip-updates feed is 6.7 MB as JSON and 1.1 MB as protobuf. A Worker on the free plan gets about 10 ms of CPU per run, and parsing 6.7 MB of JSON blows through that. So I wrote a decoder that walks the protobuf wire format and reads only the dozen fields the pipeline needs, skipping the rest. It decodes about 3,500 trip updates in 3–5 ms and 1,300 vehicle positions in 1–2 ms. I checked its output against the JSON feed field by field.

Delays only for buses actually on Dublin roads

The trip-updates feed covers the whole country, including trips that haven't started. Averaging all of it gives a confident, wrong number. Each run joins trip updates to the latest vehicle snapshot inside a Greater Dublin bounding box, so the median delay describes buses that are out there right now (as I write this, +3.3 min across 987 buses).

What the real feed taught me on day one

The first run flagged 92 “duplicate” trips. They weren't duplicates: they were extra services the operator had added that day, which the GTFS-Realtime spec allows to have no trip ID at all. The fix was to key trips on ID plus service date and count unkeyed added trips separately. Checks need testing against real data too. The same afternoon, the SQL Lab showed a route called “1 13 c a#1”: route 13's ID arrives with spaces where every other route has underscores. The parser now normalises both, and a route_id_format check counts IDs in unexpected shapes on every run.

Idempotent loads

Time-series rows are keyed by the feed's own timestamp and written with INSERT OR IGNORE. If a run is retried, or the feed hasn't moved since the last poll, nothing is double-counted.

Staying inside free-tier limits on purpose

D1's free plan allows 100,000 rows written a day. Storing every vehicle position every minute would be about 1.9 million. So raw positions live only in a snapshot that is overwritten, and history is kept as aggregates: about 26,000 rows a day, with retention jobs that trim old data nightly. Health numbers are computed every 10 minutes into a snapshot, so the homepage reads a handful of rows rather than a day of run history.

Data-quality checks on every run

A run is ok when every check passes, warn when data loaded but a check failed, fail when nothing loaded, and throttled when the feed said “slow down”.

feed_fresh
The feed header is less than 3 minutes old. A stale feed is the most common silent failure in real-time data.
row_count_in_range
Between 200 and 4,000 vehicles nationwide. Zero rows is an outage; ten times the usual is a bug.
coordinates_valid
Fewer than 2% of positions fall outside Ireland or are missing.
route_id_format
Route IDs in an unexpected shape are counted, then normalised. Upstream format drift should be visible, not silent.
unique_vehicle_ids / unique_trip_ids
Duplicates would double-count buses and skew every average.
delay_outliers
Delays beyond ±2 hours are excluded and counted, not silently averaged in.
join_to_vehicles
At least half of the buses on Dublin roads match a trip update. If the join collapses, the delay numbers are meaningless.

What I'd add with a team and a budget

  • Raw feed archived to object storage (R2 or S3) as Parquet, so history can be reprocessed when the logic changes.
  • Alerting on the checks: a page when freshness breaks for 5 minutes, not just a red row.
  • The static GTFS timetable joined in, for stop names and scheduled headways, and a proper dimensional model on top.
  • Contract tests on the feed schema, so a change upstream fails loudly in CI rather than quietly in production.