Hangfire storage best practices

Hi Hangfirers,

We are evaluating storage approaches for hangfire jobs, it looks either MSMQ or Database from documentation. MSMQ requires distributed transaction with Remote Q and Database(SQLServer). We have concern on the distributed transaction requied by REMOTE Q and also want to know more about table as Queue pattern in SQLServer side. Do we have any best practices or guidelines on the selection between MSMQ and Database to store Jobs?



Hi @Xianjing_Zhuo,

Please note that Hangfire keeps in its queues only job identifiers, and nothing else, jobs are always stored in the transactional storage. Hangfire.SqlServer.Msmq package does not require distributed transaction to be spanned across both SQL Server and MSMQ, it is here only to be able to fetch background jobs identifiers from remote queues. When queueing, internal MSMQ transactions are used.

The main drawback of table as queue implementation is polling for updates. Large polling interval increases the delay after which a newly created background job will be processed by a worker. Smaller polling interval increases the load on database. If you want to decrease the delay, or if you have thousands of workers that cause significant load on your SQL Server instance, you could try using Hangfire.SqlServer.Msmq integration.

Hi Sergey,

Got it, Thanks for the clarification.