My website (https://edi.wang) is an open-source blog system written in .NET Core and runs on Microsoft Azure. This article explains why and how the blog benefits from Azure's services.
History of this blog
The history of my blog dates to 2003, and the .NET version of the blog was originally built 10 years ago by the ASP.NET 2.0 WebForm VB and Access database and has been gradually maintained and upgraded to today, using ASP.NET Core MVC and Azure SQL Database.
The current system, codename "Moonglade", is a complete rewrite of the previous .NET Framework version of the blog, which was "Nordrassil". For single-user blogs, this version extremely streamlined, eliminating the previous version of over-designed multi-user rights management, multi-level categories, MetaWeblog interface, article review workflow, and other useless components, and targets cloud-native environment.
This blog is currently deployed in the East Asia region of Microsoft Azure. The average server response time is 6.5ms, while page load time is around 4s, due to the impact of China’s network, I still have plenty of visitors from mainland China, besides these users, the page load time is actually 1.5-2s in a good network connection. In fact, it's not just .NET and SQL code optimization that made this performance, Azure's services are also a key role in success.
Let’s check out how Azure empowered every piece of this blog system to achieve more.
App Service + Azure SQL Database
These two services are at the core services used by the blog and were the only two that the blog system adopted when it first went to the cloud. They can reduce a day or days of work to deploy a VM or on-premises server to ten minutes. And the price is much lower than using VM to deploy a website.
App Service is a PaaS service on Azure. Compared to traditional virtual machine deployment, App Service provides a fully managed platform where users don't have to worry about installing and configure virtual machines. As for the underlying system patches, website environment, web server configuration, have all been managed by Microsoft. As a result, we no longer need to work 996 and get into ICU just to prepare a web environment. We can now do it in minutes, where traditional methods can take hours or even days.
Disadvantages of VM deployments
- Manual patch every month
- Manual install runtime and web server (IIS, .NET, Python, etc..)
- Manual configure website runtime (environment variables, path, etc..)
- Manual connect CI/CD (setup WebDeploy, FTP, etc..)
- Manual configure IP addresses, network, staging/prod environments, load balancer
- If website went boom, manually RDP to the machine to check logs and crash dump
- Difficult to scale
Cloud-Native App Service
- Fully managed platform
- Rich global regions
- Quickly build and scale Apps
- Smart monitoring
- High performance and security
- Low cost
Azure portal provides a complete management interface on the web that can be used for dozens of operations, including deployments (different environments), diagnostics, settings, backups, scaling instances, binding domain names/SSL, and more.
While .NET should be the right choice, Microsoft doesn't just support .NET. You can choose Node.js, PHP, Python, or other languages, and you can use almost all the App Service experience, or even the Linux/Docker platform.
In addition to the basic features like domain name, SSL, that each site will configure, my blog uses some of the additional features of App Service.
The purpose of this feature is to create and switch between different environments. For example, my blog has only staging and production environments. The code is automatically published from the continuous integration of Azure DevOps to a staging environment that very close to production, and after testing, the deployment of the production environment is manually triggered.
Azure can seamlessly switch between two environments so that your application is almost zero downtime. Traditionally, if a deployment went wrong, it usually takes a rollback operation, during which time users will surely take screenshots of your website and tweets to celebrate your mistake. So, the reason why my blog has always seemed very stable, it’s not I write correct code every time, but thanks to the staging slot, users won’t know if something has blown up before going to production.
Doing backup on traditional VM either requires manual operation, or write a complex script, or with the system scheduled task, or purchase third-party products. Anyway, it’s complex. Programmers can easily 996 into ICU for setting up this kind of environment.
Azure App Service, on the other hand, can be configured with scheduled automatic backups just with a few mouse click on the web page, even includes a database that will be packaged together. When the website blows up, you can select the backup file and restore it instantly with one click. You can also download the backup package at any time to restore to your local environment.
Azure App Service makes it easy to configure scaling rules in just a few minutes. For example, when CPU usage reaches an average of more than 70% in 1 minute and lasts 10 minutes, an instance is automatically added.
Kudu is a Microsoft open-source tool written in ASP. NET (unfortunately not .NET Core), it's the hero behind App Service. Websites on IIS can be published, managed, and diagnosed using Kudu. Microsoft not only opened the tool for free, but it also integrated it into Azure Portal, where I was able to use advanced features to manage the blog server.
Kudu can view app settings, server environment variables, browse or edit website directory files, view live log streams, check IIS, node, dotnet, and other processes, and download dump files for local debugging. It's a Swiss Army knife for a website application.
Other features of App Service are also useful. For example, you can find Let's Encrypt in "Extensions", which can automatically configure and renew free SSL certificates. You can also run scheduled tasks in Web Jobs. Learn more at https://azure.microsoft.com/en-us/services/app-service/
Azure SQL Database
Like App Service, Azure SQL Database is a fully-managed database service that includes almost all of SQL Server's capabilities and supports My SQL. Using Azure SQL Database means you don't have to worry about installing and configuring your database server environment, like patching your machines or struggle with firewall configurations. All common operations can be done in minutes in the Azure portal.
Azure SQL Database can be managed with tools you're familiar with, such as SSMS and Azure Data Studio.
Azure allows internal services to access the database, while you can disable/enable this setting at any time. But excludes other public IPs. You can add IP whitelists on the web portal, or by SSMS and Azure Data Studio.
Azure also provides data security (including compliance, such as masking sensitive data), performance optimization services, like which SQL Query is the slowest, and give accurate tuning recommendations like where to add indexes. Unfortunately, I am not so familiar with database technology, so I can't give you an in-depth introduction.
Learn more about Azure SQL Database here: https://azure.microsoft.com/en-us/services/sql-database/
Azure DNS provides domain name resolving services with global ultra-high availability. It is hosted alongside your apps, supports all common DNS record types, and can quickly update DNS records. My blog switched to Azure DNS years ago.
Azure can now provide one-stop service from domain name registration to DNS resolution. However, you don’t have to register a domain name in Azure to use Azure DNS. Just change your NS records to match Azure DNS servers and you are ready to go.
Learn more about Azure DNS here: https://azure.microsoft.com/en-us/services/dns/
CDN is also one of the services usually used with websites. Thanks to Azure's global footprint, using Azure CDN is a better way to ensure global access to resources. In my blog system, the images of the articles are using CDN to speed up Azure Blob Storage, which helped a lot for users in mainland China.
Azure CDN supports custom domain names and gives away SSL certificates for free! What a conscience does Microsoft have!
In my blog system, the first time the user requests an image, the CDN would go to the corresponding Blob Storage to get the picture and cache it. Subsequent requests no longer need to go through Blob Storage, and you can return the results directly from the cache to increase responsiveness. With CDN, the response speed is significantly improved compared to the turtle speed in mainland China to direct access Blob Storage.
Learn more about Azure CDN: https://azure.microsoft.com/en-us/services/cdn/
My blog system contains unstructured data such as pictures and is not suitable for saving with SQL Server databases. Azure Blob Storage, on the other hand, is ideal for storing resources such as pictures, files, and more. Its benefits are geo-redundancy, multiple blob types, object mutability, and strong consistency.
Microsoft offers SDK support, including .NET Core, to make it easy for programs to use blobs. For information on how my blog system uploads an image to Azure Blob, see the source code:
Files stored on blobs can be managed on the Azure portal, or by Azure Storage Explorer, Microsoft's official client application.
Learn more about Blob Storage: https://azure.microsoft.com/en-us/services/storage/blobs/
Azure Active Directory
People familiar with Microsoft products may know about Active Directory, which helps companies manage employee accounts. Azure Active Directory is a cloud-based domain service that not only manages accounts within your organization but also invites partners or temporary visitors.
Microsoft's Office 365 also adopts the service. The most useful feature of Azure AD is that it can be easily integrated with your own applications for an SSO (single sign-on) experience. My blog also supports Azure AD single sign-on.
For information on how my blog code integrates Azure AD, see:
Learn more about Azure Active Directory: https://azure.microsoft.com/en-us/services/active-directory/
Azure DevOps is not a new thing, but a masterpiece of Microsoft's renaming division. Formerly known as VSTS, or a more familiar name: TFS.
It is a complete set of DevOps tools that cover all functions such as requirements management, code hosting, compilation and deployment, testing, and more. Using Azure DevOps means you no longer need to buy individual products for individual features and then integrate them at the cost of working 996 and get into ICU. And Azure DevOps is free for teams of up to 5 people and open source projects!
The staging and production environments mentioned earlier in this article are configured by Azure DevOps.
Because of the open-source nature, my blog doesn't use all the features of Azure DevOps, but only Pipelines. It provides CI/CD generation, testing, and deployment. You can connect to GitHub or any other Git provider (including, of course, Microsoft's own TFVC).
Learn more about Azure DevOps: https://azure.microsoft.com/en-us/services/devops/
Azure Application Insights
After a website is developed and deployed. Monitoring is important to find problems, optimize performance, and so on. There are no systems without any bugs. Those can quickly find and solve the problem can dominate the market. Azure Application Insights is a powerful APM tool that integrates from front end to backend of your entire web application to provide real-time data.
I can pin the metrics that I care most to the dashboard. Such as server response time, failed requests, page views, page load time. And I can view more information by clicking into each metric.
For failed requests, I can clearly see what environments and services have gone through all way till the database. What’s the exception, and what SQL query was run, and how much time they took.
Built-in performance analysis tools that support both client and server can help you quickly locate performance bottlenecks, such as which is the slowest requests, where the slowest SQL queries are, and so on.
By the way, Azure Application Insights also comes with an Application Map that can see very intuitively the relationship of the web application.
Azure Application Insights can also be to integrate deeper into your app by using custom events to help get more useful data that more specific to your own application.
Building a cloud-based blog system with Azure has achieved great performance and developer efficiency compared to traditional approaches. I only used 8 out of hundreds of Azure products so far. My blog may take advantage of other Azure services in the future. For example:
- Content moderating with Azure AI
- Integrate Bing Search
- Use Azure Key Vault to manage secret keys
- Use Cosmos DB to store data
- Use Web Jobs to run scheduled tasks
I sill have a lot to learn, and I hope you can also achieve more with Microsoft Azure!