Live subscriber count using an LED LaMetric

Building an HTTPS endpoint in Rust to show our Mailchimp subscriber count on an LED LaMetric device.
Live subscriber count using an LED LaMetric

The Console newsletter launched in January with a goal of hitting 1,000 subscribers by the end of Feb. We beat that goal by more than 50% and are now aiming to x10 by the summer.

Right now we're focused on subscribers, but our KPIs will soon need to include things like engagement and retention. Tracking subscriber numbers helps us prove we can build an audience, but doesn't prove whether we have something people want to continue receiving.

Our privacy policy is clear that we only track what is important. That means we don't care about tracking whether / when you open the email, but we are interested in who signed up, where they have found us, and which links people are finding interesting each week.

We have a chatbot that posts subscriber stats to our Basecamp chat room every morning. This will be how we keep an eye on things in the long term i.e. not distracting, just once per day, only the key metrics we care about. We want to try to avoid becoming addicted to checking our stats, so having them update just once per day is quite helpful.

Our bot posting our daily Mailchimp stats into Basecamp.

However, after seeing Troy Hunt post about his experiment with using an LED internet connected LaMetric to show live Have I Been Pwned (HIBP) subscribers, I decided it would be fun to do the same for Console!

Creating a LaMetric app for Mailchimp

The LaMetric is a cool device because although it has many built-in apps, it also allows you to create your own. It will display any kind of arbitrary content, such as icons, numbers, text, and even charts.

In Troy's blog post he hooks his LaMetric up to Cloudflare Workers to push the latest subscriber count whenever it changes. This is an efficient way to keep the LaMetric showing the latest value, but because he is running entirely his own code, he can hook up his subscriber endpoint to save the current number in Cloudflare's KV store. We're using Mailchimp, which doesn't support anything like webhooks to update a subscriber count somewhere.

Instead, I decided to build an HTTP endpoint which, when polled by the LaMetric, would query the Mailchimp API for the number I wanted. The LaMetric spec simply requires an HTTP response that looks like this:

    "frames": [
            "icon": "i29438",

The icon is chosen from one of the supported icons. You can create your own but I used the rocket 🚀 emoji. "text" is the content to be displayed on screen.

Building an HTTPS endpoint

I decided to reuse the code I had just finished writing for the Basecamp chatbot mentioned above. This already queried the Mailchimp API for the subscriber count but instead of posting it to the chat room, it would return the above JSON object. Having used the Rocket framework, this was easy - JSON responses are built-in functionality.

I had also already done the work to figure out custom runtimes on Azure Functions, so I could also reuse the infrastructure code. I swapped the function type from a timer trigger to an HTTP trigger. This returns an HTTP response and is configured with HTTP forwarding so that Azure Functions just passes the JSON response directly, rather than its standard output.

Everything I learned building a custom runtime in Rust for Azure Functions applied here too, so I could reuse all the build and deploy scripts.

This is a perfect example of where a serverless function is the right choice. It is a simple HTTPS endpoint that is queried periodically, is stateless, and returns a HTTP JSON response. I write the code, and Azure deals with running all the infrastructure, hosting the endpoint, provisioning the SSL certificates, keeping everything secure, etc.

Azure Portal showing the HTTPS function.

Live subscriber stats on my desk

I now have an LED device that shows an almost-live view of our subscriber stats. It is set up to query the endpoint every 10 minutes, which was especially fun to watch when we launched on Product Hunt last month!

Having these metrics available at a glance has been fun, but it is definitely encouraging bad habits. I feel like I want to check the stats every time the number changes, and it is too easy to be distracted by the shiny display.

LaMetric supports scheduling so the display turns itself off after my working day ends. It's currently on my desk at home but the plan is to relocate it to our office when we return post-COVID. Unlike Twitter follows or Instagram likes, it is showing a metric that is very relevant to our business, but I'm still wary of keeping it around for the long run.

The source code for the endpoint is available on our GitHub.

The LaMetric on my desk showing our subscriber count.

Discover the best tools for developers

Console Newsletter - A free weekly email digest of the best tools and beta releases for developers. Every Thursday.
See the latest email.