Skip to content
Advertisement

What’s the difference between FastAPI background tasks and Celery tasks?

Recently I read something about this and the point was that celery is more productive.

Now, I can’t find detailed information about the difference between these two and what should be the best way to use them.

Advertisement

Answer

Straight from the documentation:

If you need to perform heavy background computation and you don’t necessarily need it to be run by the same process (for example, you don’t need to share memory, variables, etc), you might benefit from using other bigger tools like Celery.

They tend to require more complex configurations, a message/job queue manager, like RabbitMQ or Redis, but they allow you to run background tasks in multiple processes, and especially, in multiple servers.

To see an example, check the Project Generators, they all include Celery already configured.

But if you need to access variables and objects from the same FastAPI app, or you need to perform small background tasks (like sending an email notification), you can simply just use BackgroundTasks.

Have a look at this answer as well.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement