What is a worker and why do applications use background tasks?
Published on 2026-10-20 by frfrand
Workers explained with examples: queues, Celery, emails, PDFs, delayed jobs, retries and idempotency without blocking a web.

Short answer: A worker is a process that handles executing tasks outside the main flow of an application. In web development it is often used for jobs that take too long to keep a person waiting in front of a page: generating files, processing images, sending notifications, or importing thousands of records.
It does not mean the work disappears. It simply runs in another process, and often on another machine.
The restaurant example
Imagine a restaurant where the person who takes the order must also prepare every dish before attending to the next customer. It would be a disaster: everyone would end up queuing, even if they only wanted to ask about the menu.
Something similar happens in an application when an HTTP request must wait for a heavy operation to finish. The usual approach is to receive the request, record what needs to be done, and delegate the task.
Then the worker comes into play.
What is the difference between the web, a queue, and a worker?
The web application handles requests. The queue keeps information about pending jobs. The worker picks up jobs and executes the corresponding logic.
For example, a customer clicks "generate report". The web can create a task and return an identifier in a few seconds. The worker processes it and, when finished, the user receives a notification or can download the file.
Depending on the chosen technology, the queue and execution can be coordinated with Redis, RabbitMQ, or other systems. Each combination offers different guarantees.
A practical case: sending emails
If a new user registers, the application can confirm the registration and send a welcome email as a secondary task.
But be careful: if the email does not arrive, what should happen? Is it retried? How many times? And if the email provider received the message, but the worker lost the confirmation?
These questions matter because a task executed twice can cause duplicate effects. Sending two emails can be annoying; charging a purchase twice would be much worse.
What does idempotency mean?
An operation is idempotent when repeating it produces the same relevant effect as executing it once. For example, setting an order status to "processed" can be designed to tolerate repetitions.
On the contrary, "adding 10 € to the balance" is not idempotent if each execution adds another 10 €. When queues can repeat tasks, this detail ceases to be theory.
A common practice is to use unique identifiers to avoid reapplying the same effect if it has already been performed.
What happens if the worker shuts down?
It depends on how messages and confirmations are managed. Some configurations acknowledge a task before executing it; others can return it to the queue after an interruption.
There is no universal guarantee of "exactly once" execution just by installing Celery or Redis. You need to understand retries, acknowledgments, timeouts, and how to record results.
What is Celery?
Celery is a well-known tool in the Python ecosystem for defining and executing distributed tasks via workers and a messaging system. It is frequently used with Django, although it is not limited to that framework.
You can define a task that processes a report and send it to the queue from the backend. Workers execute that function when they have capacity.
To operate correctly, you need monitoring, error logging, and proper concurrency configuration.
Does more workers mean more speed?
Not always. If all tasks compete for the same database or consume all available memory, adding workers can make the situation worse.
Some jobs are CPU-bound, others network-bound, and others depend on external services. Before increasing processes, it is advisable to measure how long each task takes and where the bottleneck is.
It is also important to limit retries: if an external provider fails, it makes no sense to launch thousands of attempts per second and worsen the problem.
When do you not need a worker?
If an operation completes in milliseconds and is part of the immediate response, introducing a queue can add unnecessary complexity.
The goal is not to create a larger architecture, but to keep the application available when long-running or unpredictable tasks appear.
And in ArduMaker?
In an app deployed from GitHub on an ArduMaker VPS, the worker is declared in the deploy configuration as another process, alongside the web process: the platform writes its systemd service and restarts it on every deployment, so there is no need to create it manually. Periodic tasks are declared the same way, as timers. Redis, if you use it as a queue, is installed as an app on the VPS and is accessible only from inside by default.
For processes that do not belong to an app, such as a standalone script, there are VPS services and scheduled tasks. In any case, the above applies: separate the component that receives requests from the one that performs delayed jobs.
In summary: a worker executes tasks that should not block the main response. A queue helps coordinate them, but reliability depends on how you design retries, errors, and duplicate operations.
Frequently asked questions
How many workers should I run?
Start with a few and measure. In Celery, default concurrency is the number of CPU cores, which makes sense for compute tasks; for tasks that spend most of their time waiting for the network, more concurrency may be appropriate, always monitoring memory and database connections.
What happens to a task in progress when I deploy a new version?
When restarting the worker, a task that was running may be interrupted and, depending on the acknowledgment settings, return to the queue. That is why it is advisable for tasks to be idempotent and for the worker to have time to finish what it is doing before shutting down.
Sources: Celery task guide · Introduction to Celery workers.
