r/DuckDB • u/mgkDante • 9h ago
Replaced Postgres with daily Parquet on Cloudflare R2 + read-only DuckDB for a public transit reliability dashboard (~US$10/mo)
I run a free public transit dashboard (transit.yesid.dev) tracking live buses and historical schedule reliability across Montréal (STM), Ottawa (OC Transpo), and Gatineau (STO) (over 1,700 live vehicles on a busy evening, ~2.6M stop arrivals/week on STM alone).
Originally I backed the historical queries with Postgres, and as the GTFS-RT archive grew, storage and hosting costs kept climbing for a mostly append-only, read-heavy analytical workload. I recently rebuilt the entire engine around daily clean Parquet files on Cloudflare R2 queried by a read-only DuckDB service (apps/engine).
How the pipeline works (~US$10/month total):
- Ingestion (Python): Polls each agency's GTFS-RT vehicle positions & trip updates, matches readings against scheduled trips, and writes clean daily star-schema Parquet files (bronze -> silver -> gold) to Cloudflare R2.
- Analytical engine (DuckDB): A thin read-only DuckDB query engine reads the daily Parquet partitions directly for arbitrary date ranges, day-of-week / time-of-day slices, line/stop rankings, and 3D corridor delay rollups.
- Edge + Frontend: A Cloudflare Worker data proxy caches hot queries in front of a SvelteKit (Svelte 5) + MapLibre + self-hosted PMTiles frontend. Users can also download the underlying daily Parquet or CSV files straight from the app.
A few analytical guardrails built into the SQL:
- Never average averages: Every multi-day rollup re-aggregates raw numerators and denominators across daily partitions rather than averaging daily percentages.
- Missing != zero (and != on-time): Roughly 35% of scheduled stop arrivals have no live GPS/prediction reading. They are explicitly left out and reported as observed coverage instead of silently treated as on-time.
- 30-observation floor: Lines and corridors require at least 30 recorded observations before entering rankings so noisy 2-trip outliers don't dominate the leaderboard.
- Live app: https://transit.yesid.dev/?ref=r_duckdb
- Architecture & data pipeline write-up: https://yesid.dev/projects/transit-data-pipeline?ref=r_duckdb
- MIT open-source repo (
apps/engine+ ingestion): https://github.com/yesid-dev/transit
Happy to answer questions on the DuckDB / R2 Parquet layout, partition sizing, or query caching trade-offs.