Spritpreise: Implementing a price alarm backend

#Spritpreise #Tech

Schematic view of the price alarm technical infrastructure, showing a server that communicates with ‘Firebase’ that communicates with the users device

Spritpreise has recently a Price Alarm feature, that sends push notifications based on a personal price threshold. In this blog post, I’ll explain some of the technical details and considerations that went into the implementation.

The API

The price alarm is handled by a new application and API that I have implemented based on the Spring Boot / Kotlin stack. It uses a database to store the configured price alarms, stations as well as the Firebase Cloud Messaging push token.

Whenever a gas station changes their price, Tankerkoenig sends an event on a messaging bus that the API consumes. The event passes some checks and is then compared against all configured price alarms. If it matches, a push notification is issued. Sounds simple, but there were actually a few details that required more thinking than I expected.
For example, let’s assume a user has configured the price alarm to 1,80 €. The price at a gas station drops from 1,85 € to 1,70 € - a notification will be sent. But what if the price increases to 1,75 € ? It’s still below the threshold, hence another notification could be sent. There are some gas stations out there that like to update their prices often, like more than 25 times per day or more. This could lead to excessive notifications being sent, which not only annoys the user, but also increases battery usage on the users device, as all notifications force the device to wake up from sleep. Let me know what you think about this.

For now, I have decided to only send notifications if the price is reduced below the threshold. If it increases but stays below the threshold, no notification will be sent.

Monitoring

Like usual in IT, there are rarely issues and everything is very stable. Nothing bad will ever happen, monitoring is therefore absolutely optional. 🙃

Well, that’s not how things like these work unfortunately, so I investigate quite some time and effort in a reliable monitor solution. I’ve set up a Prometheus Grafana stack to monitor the application as well as the servers themselves. By using alert rules, the system will automatically tell me if the application is down or experiences unexpected errors.

Grafana dashboard showing various telemetry metrics of the price alarm backend

This requires the application to provide a list of metrics to have insights into what it’s doing and what’s happening. As an example, there are metrics for the amount of price update events received by Tankerkoenig, as well as the count of push notifications being sent.

 


 

I hope you found this blog post interesting. If you would like to try out my Spritpreise app and the price alarm, you can download it here:

Download Spritpreise for Android now