Search code examples
asp.netazuresynchronizationsoajobs

Scalable ASP.NET application jobs synchronization


My ASP.NET app can run on multiple virtual servers (e.g. in Azure I can scale on demand). I'm not sure where I will host my app, whether it will be Azure or some other hosting service, but I faced with the following problem:
I need to run jobs on some schedule: get exchange rates and they should be available for all server instances, check database and send emails, manage app cache or logs or do some other jobs in background.
What I don't understand well is how to build/architecture the system so that those jobs are executed only once (I don't want to pull exchange rates on every app instance or send emails more than once). So simple use cases of some Quartz.NET or QueueBackgroundWorkItem don't suit me.
I know that Azure WebJobs is capable of doing such things, but I do want the solution that doesn't not depend on hosting service like Azure, because maybe tomorrow I will want to move to another hosting service.

  • Is there any generic solution for this kind of problem?
  • Can I build this using service bus that is not related to any hosting service?
  • What are the advantages of using Azure specific solution (WebJobs, Azure ServiceBus) instead of generic solutions?
  • What are the best practices to build this part of application so I can replace it in a quick way using DI? Just abstract away the service bus using interfaces or something else should be done?

Thanks.


Solution

  • Have you taken a look at NServiceBus (and the Particular Service Platform)? It can be used as a deployment-agnostic API for asynchronous message processing and deployed both to Azure as well as on your own servers.

    When run on Azure, it leverages Azure Service Bus and when on your own server farm, you can choose MSMQ, RabbitMQ, and even SQL tables as your transport.

    NServiceBus leverages dependency injection quite heavily so testing your solution is very easy.

    Hope that helps.

    • Full disclosure: I'm the original author of NServiceBus and lead its' current development.