Several processes in one app
A website, a queue worker and migrations in one app via Procfile: how it works and when a separate resource is better.
One app can run several processes: for example, a website and a job queue worker. They are described in a Procfile in the repository root.
Procfile
Each line is name: command:
web: node server.js
worker: node worker.js
release: npx prisma migrate deploy
webis the process with the website or API. It listens on the port from thePORTvariable.- Any other names (
worker,scheduler,queueand so on) run next towebin the same container under a shared supervisor. They share the CPU and memory of the plan. - Up to 6 processes in total.
releaseis not a process but a pre-start command; see below.
Without a web line, all processes run as a background app with no web address — this is how bots and workers run.
The release command
The release: line runs before the processes start, on every container start: after a deploy, a restart and waking up from sleep. Usually it runs database migrations.
- The command must be idempotent: running it again with no new migrations changes nothing.
- If it exits with an error, the container does not start and the deploy is marked as failed.
If a process exits
When any process exits, the supervisor stops the others and the whole container restarts. This way the error is visible instead of being lost silently: the site does not keep running with a dead worker.
Log
Processes share one log; each line is tagged with the process name:
[web] listening on 3000
[worker] job 412 done
The “Log” tab has a filter by process.
Examples
Node.js:
web: node server.js
worker: node worker.js
release: node migrate.js
Python with Celery:
web: gunicorn mysite.wsgi --bind 0.0.0.0:$PORT
worker: celery -A mysite worker --loglevel=info
release: python manage.py migrate --noinput
Periodic Celery tasks can run as a beat: celery -A mysite beat process, but the “Schedule” tab (cron) is simpler: see Scheduled jobs. The same goes for schedulers like node-cron — a scheduled job does not keep a process running all the time.
Limitations
- The
Procfileis used only with automatic stack detection (Node.js, Python). With your ownDockerfile, start the processes yourself, for example with supervisord, or move the worker to a separate resource. - Sleep. During sleep all processes stop, workers included. If the app has workers, turn off “Sleep without visitors” in the “Settings” tab.
When a separate resource is better
A separate app for the worker is more convenient if:
- the worker needs more memory than the site, or the other way round;
- the worker must be restarted or scaled separately from the site;
- a worker crash must not restart the site.
A second app from the same repository runs the same Procfile with all its processes. So keep the worker where it has its own entry point: in a separate branch or a separate repository (folder) with a Procfile containing a single worker: line, or with its own Dockerfile. When creating it, choose “Background process” mode. Connect the same database to both apps in the “Connection” tab.