App Service – Horizontal scaling
What’s the catch here? If you truly want to be dynamic in your horizontal scaling then you want to make sure your application is stateless. User sessions are cached outside of your solution and if you need to cache data never use memory or local storage but look into solutions such as Azure Redis Cache or Azure Service Bus.
Horizontal scaling also works well for micro services architectures and distributed systems. But if either of those is what you have been doing then it’s likely that you already looked into horizontal scaling or you have been doing it all along.
But, chances are you haven’t thought of this when you just started building your solution and depending on your application, going from stateful to stateless can be quite the project.
“Great, thanks for the information. Do I scale vertically or horizontally?”
When migrating your solution to Microsoft Azure then you have the option of both. If you have a pre-existing solution and the financial impact of going from stateful to stateless is too big for now, then vertical scaling is your quick win. But as stated, you need to plan your maintenance windows. Your next step would be to gradually evolve your solution into a stateless piece of art before you hit vertical scaling limits on Azure.
If you’re going with Infrastructure as a Service, then it might take you a while to hit these limits on Azure. But don’t forget, high performance virtual machines generally don’t come cheap. What you want to do is do a comparison where you focus on the costs of the Virtual Machine (over a period) and compare those to the estimated costs of refactoring your application to support horizontal scaling.
The same goes with Platform as a Service but you’re likely to hit the limit there a bit quicker. Long story short: Vertical scaling is your quick win when moving onto Azure but if you plan on growing rapidly then horizontal scaling (or combination of both) will be your goal as this provides a higher level of availability and more flexibility (financially).
Global scaling
One of the things Microsoft Azure excels at is global availability. You can literally deploy your application all over the world, with the touch of a button. But what does this mean for your software architecture and your technical infrastructure? What you want to achieve when scaling your solution globally is local presence in a specific region. The technology stack you are using will impact the way you scale globally (Are you using IaaS, PaaS or Serverless?). What’s your business case? Are you going to re-deploy a copy of your architecture to a specific region and doubling your costs (note that pricing can be different per region), are you doing this for just one customer and what about compliance and regulations?
Global scaling considerations
When scaling globally there are three subjects that are trivial for your global scaling strategy;
- Finance;
- Latency;
- Compliance, local laws and regulation.
Finance
Simply grabbing a copy of your environment and redeploying it to another region will at least double your costs. If you’re currently providing a service to a hundred customers and you are scaling to another region for just one customer, then the business case doesn’t look ideal. And let’s be honest: this is usually what it looks like at the beginning (how sure are you that you will be onboarding a lot more customers in that specific region the next few weeks?).
This is where your strategy for scaling vertical and horizontal comes in. If you implemented either one of those, chances are you can scale back to the minimum required for just a few customers while maintaining availability. This is why you need to understand why you scale and when you scale. You want to be in control of your capacity requirements vs. the usage of your platform.
Latency
By far, your single most important asset when scaling globally is data. You want to store your data close to your users. Let’s first look at databases. When it comes to Microsoft Azure you have a few options. If you’re using IaaS and are hosting a MSSQL database on a virtual machine, then you’re likely limited to redeploying that virtual machine in another region with customer specific databases for that region, hosted on that machine. If you want to scale globally you want to look at Platform as a Service or the Serverless technologies that Microsoft Azure provides.
When it comes to databases services, we generally see two solutions being used widely:
Platform as a Service with Azure SQL
Azure SQL supports database sharding. Long story short: this will help you split your data into smaller pieces, allowing you to store those pieces in different locations and increase performance.
Distributed database services
Distributed databases are built for horizontal scaling and global distribution. You can read and write your data to a specific location whilst still using the same technology and frontend (let’s say an Azure Web App). This sounds a lot like sharding but distributed databases services are much more than that in terms of replication, scaling and partitioning. Azure provides one of these services in the form of CosmosDB and is considered serverless. Note that this probably requires a different database model as that you’re used to. But if you’re scaling globally, CosmosDB is one of those services that you want to consider using.