tl;dr - if you only want to get started quickly, just jump ahead to “Setting up a Development Environment” section
I have been experimenting with container orchestrators to help me deploy a microservices-style hobby project I have been working on (more on this in a separate blog post) to the cloud. If there’s one thing I learnt from this project, there are a lot of moving parts to it and might not be easy to manage a distributed cluster with hundreds of services that are fast, reliable and scaling.
While I was on the journey in finding a platform/framework with a good balance of container orchestration, managing and monitoring infrastructure, I came across Azure Service Fabric which looked promising.
The following definition is the one that caught my eye,
The aim of Service Fabric is to solve the hard problems of building and running a service and to use infrastructure resources efficiently, so teams can solve business problems by using a microservices approach. Service Fabric is agnostic about how you build your service, and you can use any technology. But it does provide built-in programming APIs that make it easier to build microservices.
For starters, you can have a quick look at Microsoft’s official page to learn more about Azure Service Fabric.
Options in Azure for Microservices
Here’s a quick summary of different options you can use to build microservices type applications in Azure,
- AKS: Microsoft’s Managed Kubernetes service with Docker as runtime
- Service Fabric: Another step forward from AKS. All about microservices and,
- Service communication
- Service discovery
- Monitoring and Telemetry
- Provision and upgrade
- Testing locally
- Manage downtimes
- Focus on business objectives and infrastructure. In AKS you need to build your infrastructure. Build and deploy from day1, but still be able to customize.
- Proven tech - Many azure services run on ASF. Cosmos DB, Azure SQL, Power BI, Skype, IoT Hub, Cortana, ACR, Azure DevOps
- Azure Functions - Mini version of microservices. Event-driven (triggers, scheduled). Easier to get started than Azure Service Fabric and Azure Kubernetes Service
Service Fabric is designed to run on any cloud platform other than Azure, such as AWS, GCP etc. However, as you might have already guessed, Azure has first-class support.
If you want to manage your own premise cluster, ASF supports Windows Server 2012 R2, 2016 or higher, Linux Ubuntu 16.04 and 18.04. However, when it comes to Macs, you are kind of on your own since you will have to rely on an emulator for that.
Service Fabric does not have a dependency on Visual Studio since it’s designed to be modular. This is great because you can have a similar setup to your production environment in your development machine. It also brings you much good stuff such as simulating real-life disasters and fixing issues before they go into production!
Azure service fabric provides us with different ways to wrap our services in. Here’s a summary of programming models used in Service Fabric.
- Reliable Service: Used to address single or multiple business concerns.
- Stateless - Acts like a console application
- Stateful - With its own transactional replicated storage
- Reliable Actors: Service Fabric uses virtual actors to handle communication between servers. Here’s an excellent article on Actor Model
- Guest Executables: run any executable without any code changes
- Containers: Separate blog post will be published on this (I promise!)
Setting up a Development Environment
To set up your local environment, we need to first install the necessary tooling. You can also have a look at Service Fabric’s official documentation on getting started.
Make sure you follow these steps,
Install Visual Studio 2019 - Community edition is fine. In fact, you can use an editor such as Visual Studio Code. But it would be easier to use VS to get something up and running.
Install Service Fabric tooling
Install Service Fabric SDK - If you run Visual Studio and try to create a new Service Fabric project it will ask you whether you want to install the Service Fabric. However, you can also install the SDK with the Microsoft Web Platform Installer (don’t forget to scroll down to Download Web PI section)
Verifying your local setup
Once you have installed the prerequisites, you can open up Visual Studio and select Create a new project
In the Create a new project dialog, filter by typing “fabric” and select Service Fabric Application
Enter a project name. You don’t need to worry about Framework version unless you are working on a classic ASP application.
You will get another popup to select a project type. For this demo, we will select Stateless Service and enter a name for our project.
In your solution explorer you will find 2 projects like so, you can also double check with my repo if you managed to get this far.
The first project is just a wrapper around the Verification Project. If you open up
Verification.cs you will see that in
RunAsync method is the main entry point of our stateless console app. Hit F5 and see whether your local cluster is working fine. It may take about 2 - 3 mins initially.
Once everything is up and running, you will see the following output in Visual Studio. Put a breakpoint in your code and have a play around it.
Now open up a browser and navigate to
You will be able to see that your application is running in a healthy state in your local cluster.
Congratulations for making it this far 🙌! Stay tuned for my next post on deploying a multi-container application to Azure with Service Fabric.