Evan's Blog

NextServiceStation.co.uk

An annoying easy problem to solve

Have you ever been on a motorway and wanted to stop at a services? Why is it such an annoyingly low information problem? Sure, you can squint at that that big green sign that tells you what’s at the next service station, but how do you know what’s at the service station after? It’s important information! Example: the nearest one might have a Starbucks, but I’d rather wait until the next one if it has a Costa.

This struck me as not only annoying, but incredibly easy to solve. So I did.

I built NextServiceStation.co.uk.

It does exactly what is says on the tin. It tells you the NextServiceStation™.

It works by taking two sets of GPS coordinates (technically GNSS, but no one knows the difference), and then working out which motorway you are on, which direction you are heading, and then which service stations are the next ones along. It then tells you what’s there: fuel, food, shops, etc.

Next Service Station user interface screenshot

How it’s made

NextServiceStation’s backend is written in Go, which is quickly becoming my favourite language for web services. The original prototype was a FastAPI Python app, but maintaining it became hell pretty quickly (mainly caused by the weak typing). The benefits of Go are:

The real star of the show is Postgres, in particular PostGIS, which provides native support for geographic objects. This makes it super easy to query things like “find the nearest service station to this point”. The prototype version used SQLite and pandas in this awful hacky way which was horrifically slow. Switching to Postgres sped up query times by up to 100x. Literally.

Most of the data needed for this is already available, but just scattered into a few different sources:

To gather this data and keep it all fresh I wrote standalone Python scripts that run on a cronjob. They download the data, process it, and then upload it to the Postgres database.

The frontend is written is a dead simple React app. I used tailwind and some other stuff, it’s not particularly interesting. Not a frontend engineer, me.

How it’s deployed

NextServiceStation is packaged into 3 containers: backend, frontend, and the Postgres database. These are all orchestrated by Docker Compose. The whole thing is deployed on a cheap Hetzner VPS.

This is not exactly the fanciest setup, but it’s cheap and it works. I’m not expecting NextServiceStation to get popular at all, so it’s probably fine.

Disclaimer

There is probably bugs, the scraped data sometimes comes out really weird in a way very slow tedious manual QA can fix. I’ll probably fix them at some point. Maybe. If you find a bug, you can tell me and I’ll fix it if it’s quick and easy

Source?

Soon to be open sourced. I just need to clean up the code a bit. It’s a bit of a mess right now. I don’t really think anyone will care about it, but I’ll do it anyway.