How to Reduce the Cost of Your Azure App Services

The software development teams building applications on Windows operating systems find it natural to host their web apps on Azure App Service with Windows as the underlying operating system and skip exploring a much cheaper option of Linux as the underlying operating system.

Let's compare.

Azure App Service on Windows

Azure App Service on Windows

Azure App Service on Linux

Azure App Service on Linux

Suppose you look at the Basic B1, the most frequently used tier for development and sometimes even for production for hosting lightweight applications. In that case, it is straightforward to see that having an App service on Linux is much cheaper. Windows costs $54.75, and Linux $13.14 per month. Linux has a 76% discount compared to Windows.

There must be a catch, and there are a few

One must ensure that the code works on Linux.

  1. Linux uses / instead of \ on Windows as a file path separator.

  2. Operating specific commands, if used, need to be replaced with equivalent or similar commands on Linux.

  3. Nuances often missed could generally get caught by someone with the know-how of the operating system's inner workings. For example, Windows uses CRLF for new lines, but Linux uses only LF. I have seen developers spend days figuring out the cause as compilers do not report the solution, and line endings don't appear different on most text editors.

The other major issue is that Microsoft does not make it as easy to work on Linux as on Windows, at least to start the web server and host files. The changes are reflected almost instantly on publishing a working code on the App Service using Windows for the first time. In the worst case, you might need to restart the App service. However, on publishing the code to the App service using Linux it does not, not even after restarting the App Service 100 times. What could be the issue?

The web server on Azure App Service

After trying to publish the code through the CI/CD pipeline provided by Azure Deployment Center, FTP, editing the files manually through Kudu, and not achieving any change reflected on the website. It is found that Azure App Service using Linux does not host the web files from the usual /home/site/wwwroot where the files are published. Yes, this is a user experience disappointment; the fundamental behaviour of App service varies on Windows and Linux.

The Solution

The solution is to specify the App Service to use /home/site/wwwroot to host web files. This can be achieved by specifying the command pm2 serve /home/site/wwwroot --no-daemon in the Startup Command section in Settings > Configuration > General Settings, and you are good to be productive.

Conclusion

A simple selection of a cheaper pricing tier that might have been agreed upon in a standup meeting could end up spending a day or two of an engineer with successive implications of not having a working website up and running, resulting in unproductive time.

I have faced and solved many such issues while hosting ASP.NET, Node.js servers, JavaScript frontend, and containerized applications on Windows and Linux. These are not something easily looked up on Google, Stack Overflow, or through AI. Though AI is assisting programming, setting up a project is something you can contact me for.

Enjoy solving business problems.