Search code examples
asp.netarchitecturewindows-servicesrabbitmqlong-running-processes

Long-running background tasks with progress notifications


I have an ASP.NET website with a a number of long-running (5 mins to 2 hours) user-initiated tasks. I want each user to be able to see the progress of there own jobs, and be able to close their browser and return at a later time.

Current plan is to store each job in the database when it's started and publish a message to a RabbitMQ queue, which a windows service will receive and start processing the job.

However, I'm not sure of the best way to pass the progress information back to the webserver from the service? I see two options:

  • Store the progress information in the database, and have the web-app poll for it
  • Have a RabbitMQ consumer in the webserver and have the windows service post progress messages to that queue

I'm leaning towards the second option, as I don't really want to add more overhead to the database by regular polling / writing progress info. However, there are lots of warnings about using RabbitMQ (as a consumer) - as I am not sending vital messages (it doesn't matter if progress messages aren't processed), I'm wondering if this matters? It's not that (famous last words) difficult to restart the RabbitMQ consumer whenever the web app is restarted.

Does that option sound reasonable? Any better choices out there?


Solution

    • Store the progress information in the database, and have the web-app poll for it
    • Have a RabbitMQ consumer in the webserver and have the windows service post progress messages to that queue

    the correct answer is C) All Of The Above!

    A database is not an integration layer for applications.

    RabbitMQ is not meant for end-user consumption of messages.

    But when you combine RabbitMQ with a database, you get beautiful things...

    have your background service send progress updates through RabbitMQ. the web server will listen for these updates and write the new status to the database. use websockets (signalr) to push the progress update to the user immediately, but you still have the current status in the database in case the user does a full refresh of the page or comes back later.

    i wrote about this basic setup in a blog post on using rabbitmq to do user notifications