Search code examples
.netazurewindows-servicesazure-worker-roles

Where to run .NET service code within Azure?


When I need a program constantly running in the background and processing queues/database data/schedule tasks/etc, I create a Windows Service application and run it on an Azure VM. Is this still the optimal approach right now? It seems to me Azure Worker roles (as an alternative) are a bit forgotten/overlooked/depreciated. Should I attempt making more Service-Fabric-oriented services?

Partially what I'm looking for is a relatively simple way of deploying, running and maintaining of code which an old-timer would put in a windows service (with as little maintenance as possible).


Solution

  • Service Fabric seems a bit over-complicated (and expensive: see the minimum number of VMs required) to me for providing what you describe, unless this is enterprise-scale code which is mission critical.

    Your reference to a windows service makes me presume that these are long-running processes. Depending on how much processing time you require, you have a few options:

    • Azure Functions: for small, task-oriented functions with excellent integration to other azure services: storage, event hubs etc. (but has a 5 minute timeout)
    • Azure Batch Service: for long-running batch processes, manages job distribution over a cluster of VMs, you define the cluster size and lifetime. Can run any type of workload, including pre-existing executables etc. and can be scheduled - so this is probably your most likely candidate.

    For the Batch Service option, you just get billed for your normal compute usage (i.e. for the VMs which you deploy to service your batch jobs)

    For Azure Functions, you get per 100ms billing relative to the amount of memory which your function(s) consume at runtime. This platform is "Serverless" [Lol, great name] in that you don't have to worry about scaling out, it will detect when you have a lot of traffic and scale out for you.

    There are, as you point out, older options: Azure Cloud Service and WebJobs... Azure Functions is in fact an extension of WebJobs.

    So, lots of options - but hard to make a real recommendation without understanding the requirements of your code further. I hope this helps point you in a direction which is helpful.