Sahan Serasinghe

Senior Software Engineer | Master of Data Science

Getting Started with Azure Service Fabric

2020-03-23azure 5 min read

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.

./1-service-fabric-intro.png

Source: https://docs.microsoft.com/en-au/azure/service-fabric/service-fabric-overview

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 - Scalability - 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

Supported Environments

  • Public Clouds

    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.

  • On Premise

    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.

  • Developer Workstation

    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!

Programming Models

Azure service fabric provides us with different ways to wrap our services in. Here’s a summary of programming models used in Service Fabric.

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,

  1. 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.

  2. Install Service Fabric tooling

    ./2-installing-tools.png

  3. 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)

    ./3-installing-sdk.png

Verifying your local setup

Once you have installed the prerequisites, you can open up Visual Studio and select Create a new project

./4-new-project.png

In the Create a new project dialog, filter by typing “fabric” and select Service Fabric Application

./5-new-project-2.png

Enter a project name. You don’t need to worry about Framework version unless you are working on a classic ASP application.

./6-new-project-3.png

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.

./7-new-project-4.png

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.

./8-solution-explorer.png

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.

./9-solution-diagnostics.png

Now open up a browser and navigate to http://localhost:19080/

You will be able to see that your application is running in a healthy state in your local cluster.

./10-sf-explorer.png

Congratulations for making it this far 🙌! Stay tuned for my next post on deploying a multi-container application to Azure with Service Fabric.

References

  1. https://docs.microsoft.com/en-au/azure/service-fabric/service-fabric-overview
  2. https://docs.microsoft.com/en-au/azure/service-fabric/service-fabric-architecture
  3. https://docs.microsoft.com/en-us/azure/architecture/reference-architectures/microservices/service-fabric
Loading...
Sahan Serasinghe - Engineering Blog

Sahan Serasinghe Senior Software Engineer at Canva | Azure Solutions Architect Expert | Master of Data Science at UIUC | CKAD