Multiple servers and priority

Is there a way in Hangfire where I can set Server priorities.

I want to setup server 1 on machine 1 which always take care of Jobs 1-10 . Server 2 on machine 2 which always takes care of Jobs 11-20. If machine 1 goes down I want server 2 to take care of Jobs 1-10 and vice-versa.

As far as I know, no, there is no such mechanism. A Hangfire ‘server’ is standalone, it knows nothing about other ‘servers’ that are consuming the same hangfire db. You would probably have to write your own load-balancing/work sharing mechanism to achieve what you want.

1 Like

I’m curious what your use case is here. The individuals servers, as with most scaling load balancing solutions, should be able to handle any request, and in fact what you describe means they would be able to do that very thing. Allowing hangfire to handle the balancing means you don’t have to go back and configure things when you add servers 3, 4, and 5. You also wouldn’t run into the case where server 1 is doing all the work while server 2 is idle just because all of the jobs currently queued are 1-10.

There are times when maybe you want a specific server to always be the one to get a certain request without backup in the case of something server specific like maybe you only have 1 box that has certain physical files on the machine and if you want to do that, you can accomplish that by creating a queue for that job that only the one server has defined in its options.

Thanks for your response.

What you said absolutely makes sense. I am trying to get more control of distribution of jobs on each server by setting priorities so its not always server 1 running all the jobs or server 2 running all the jobs.

The only solution here is to set your jobs in different queues and then only have the workers able to run jobs from those queues. We do this all the time.

1 Like