trains.fyi

Web Projects

A live, real-time map of passenger train locations in North America.

Blog Posts

trains.fyi
How my site trains.fyi hit the front-page of Hacker News

Hitting the front-page of Hacker News with trains.fyi


Tracking Passenger Trains

While sitting on a delayed Via Rail train stuck behind others, I started to wonder about train traffic, and I started looking for a map of trains in North America. Those that I found were a bit complicated or difficult to understand as a layperson - so I decided to build my own - trains.fyi.

How It Works

The site has two main components; the front-end and the back-end.

Front-End

The front-end is really simple. It's just a single static HTML page hosted on GitHub pages. The page has a map, served with the leaflet.js framework, with an overlay of the OpenRailMap to highlight rail lines. Train data is fetched from the backend and plotted on the map, updating every minute to show the latest. The front-end also uses bootstrap to keep everything responsive and mobile-friendly.

Back-End

The back-end is a bit more complicated. It pulls data from multiple sources, and does a bit of data processing so that it's ready to be consumed by the front-end. It makes use of a bunch of transit APIs, public data, and some GTFS-RT feeds (which are a new concept for me).

{
    "name": "1 (11-26)",
    "company": "Via Rail",
    "latitude": 46.5832,
    "longitude": -80.9412,
    "origin": "Toronto",
    "destination": "Vancouver",
    "speed": 65,
    "direction": 323
}

Data is fetched every minute by a Google Cloud Function, processed with a data pipeline, and stored in a Google Cloud Storage bucket, where the front-end static page can access it directly.

What Is Tracked

Currently, the site tracks the locations of passenger trains in Canada and the USA. I've tried to include various commuter rails as well, but have left out anything that I wouldn't consider a "train", like the NYC subway or TTC street cars.

What's the purpose?

This is more of an art-project than it is an actual useful application. For me, it doesn't really solve a problem, but instead is a neat way to pass the time and check out where trains are at a glance.

Building This Project

The total build of this project, from start to finish, took about a weekend. I had two things in mind when I built this:

  • Automatic Updates
  • Cheap To Run

With that, I chose a static front-end and Google Cloud Functions / GCS buckets for a backend. This ensures that the project remains pretty cheap for me, and runs continuously without much upkeep.

Questions

Any questions, comments, concerns, suggestions? Send me an email!

Interested?

Check out the project for yourself!

Let's build something big together

I build creative marketing experiences and projects with technology.