A study of serverless solution for connected gyms

Azure is amazing!

I was amazed by the hundreds of products it offers to simplify the IT delivery processes. But at the same time I was also wondering how much I could actually deliver with just Azure. So I gave myself a task to address a real life problem using only Azure. Luckily (or unluckily ;-Q), as a solution architect, my life is full of problems waiting to be addressed….

A real life scenario

Nowadays, More and more gym operators are installing connected gym equipment. It’s great news for the gym lovers. The connected equipment gives them a fantastic digital gym journey, e.g. they can track their daily exercise routines or monitor their progresses. The gym operators are also happy not just because their members are happy. The vast amount of data generated by their members day in and day out give the gym operators a great insight into their members individually.

How the connected gym works

Although technically possible, it’s unlikely that the connected equipment will send data directly to the gym operators. Usually the connected gym equipment sends data to the equipment vendor’s data centre which sequentially push out data changed events using technologies like web hooks or AMQP.

DigiCap - Serverless Connected Gym - connected equipment

High Level Design

Data is a gold mine. We don’t want to lost any of them. The raw data is captured in its raw format in data lake. Stream Analytics and Data Lake Analytics are two powerful gold diggers. While Stream Analytics works with event hubs to generate real-time reports in PowerBI, Data Lake Analytics is responsible for the studies of long term trend. The outputs of Stream Analytics and Data Lake Analytics are also stored in a Cosmos DB to support further analysis.

Logical Workflow of the connected gym serverless solution

The HLD diagram is pretty self explanatory. It should just work unless

The gym equipment vendor says no…

The one major gym equipment vendor I’m working with has a weird way to manage the message security. Also they put a lot of common attributes of the message in the http header instead of in the payload body which make it very tricky for the event hubs. They not very good at handling random http headers.  We need to add an extra layer to the design in order to handle this kind of vendor specified ‘abnormalities’.

Version 2

I was looking for a product in Azure which allows me to create a restful endpoint easily. I was hoping I could build the api with a few mouse clicks in the Azure Portal because the business logics were so straightforward. The product caught my eyes was Logic Apps. It can be triggered by restful api requests. Business logic (workflow) is configurable. It has a standard Event Hubs connector. Basically it ticked all the boxes until I looked at the price. The Logic Apps service charge per action and the usage of the connectors. For example, to handle around 10k api calls a day the chargeable items include 10k+ actions and 10k usage of the event hubs connectors. The total cost per year will easily be over 20k. Shocking! Absolutely shocking! Clearly Logic Apps is not a good choice for such high volume usage. This leaves me with no other option than Azure Api apps. To be honest Api apps is not a bad idea at all. It is still inside the serverless framework. But the idea of no code is simply too good to be true.

Serverless connected gym solution with a thin api layer

Costs

To complete the study, I’ve tried to work out how much it costs to deliver the solution o Azure. The build cost and the license fees of PowerBI are not included in this study.

The estimation is based on a gym chain with around 100k members. Let’s say 15% of the members are using one more more connected gym equipment In a single day. Typically a connected equipment spits out two messages per use: exercise started and exercise completed. There might be other types of messages, e.g. workout completed and biometric measurement completed. If an average gym user uses no more than 3 different types of connected gym equipment in one visit (personally I use two), she / he can generate up to 8 messages a day. It means the total number of messages generated by the gym chain with 100k members a day is around 120k. The table below summaries the costs of the key building blocks:   

NameCosts per yearNote
Event Hubs£850Including 12k messages per day and 12 months capturing service cost at £54.41/month
Data Lake< £10< 100 GB per year
Data Lake Analytics£1100Data lake analytics job runs on 1 analytics unit 2 hours a day very day
Stream Analytics£1600Two stream units run 24 / 7
CosmoDB£280100 GB storage and 100 RU/s throughputs
App Service£13002 standard instances
Key Vaults£10012k secret transactions a day at £0.023 per 10k transactions

The total cost of £5k per year is probably acceptable to a gym chain with 100k members. Without having to worry about about the infrastructure and maintenance costs, they can focus their resources on their core business which is to provide excellent gym journey to their members.

I think the solution is beautiful.

Leave a comment