Backend Server/Worker Mode
Medusa has a backend architecture that typically operates in two primary modes: Server mode and Worker mode.
The Server mode is where the main application logic runs. This mode is responsible for handling incoming HTTP requests (such as API calls) and managing overall business logic (e.g., user authentication, order processing, etc.).
The Worker mode is used for offloading long-running tasks or background jobs that are not ideal to run during an HTTP request. These tasks often include time-consuming operations such as sending emails, processing payments asynchronously, updating inventory, or generating reports.
We will use PM2: A process manager that can be used to run both server and worker instances and keep them running in the background.
Server Mode
Now to start server mode, edit the .env file in the medusa backend folder and change parameter MEDUSA_WORKER_MODE
Note if required we need to enable admin along with server mode
Also keep default server port 9000
- Your NGINX reverse proxy will redirect here
Start backend in server mode
Worker Mode
Now to start worker mode, edit the .env file in the medusa backend folder and change parameter MEDUSA_WORKER_MODE
Note for worker instance we dont need admin so disable the same. Also both server and worker instance cannot run on same port.
So here we changed the worker port to 5173
Start backend in worker mode
You can view and manage these processes using PM2 commands
Last updated