A Procfile is a plain-text file in the root of an application repository that declares the application’s process types and the command used to start each one. In the field of services & processes on servers, it serves as a compact contract between the code and the platform: the developer states what must run, and the runtime decides where, how many times and under which supervision it runs.
The format originated on Heroku and was later adopted by Cloud Native Buildpacks, many platform-as-a-service offerings and local process managers such as Foreman and Honcho. It is closely tied to the Twelve-Factor App methodology, which treats an application as a set of stateless processes started by explicit commands.
How a Procfile is structured
A Procfile contains one process declaration per line in the form name: command. The name identifies a process type, and the command is the exact shell command that starts that type. The file has no extension, and the platform expects the capitalized name Procfile in the repository root.
Process type names are short alphanumeric identifiers chosen by the developer. Two names carry special meaning on many platforms: web, which is the only type that receives external HTTP traffic, and release, which runs once during deployment before new processes start.
The following table lists the most common process types and what the platform does with each.
| Process type | Typical command | Receives traffic | Platform behavior |
|---|---|---|---|
| web | gunicorn app:server --bind 0.0.0.0:$PORT | Yes, via the router | Must bind to the assigned port within a timeout |
| worker | celery -A app worker | No | Runs continuously and processes background jobs |
| clock | python scheduler.py | No | Usually limited to one instance to avoid duplicate runs |
| release | python manage.py migrate | No | Runs once per deploy; failure aborts the release |
Commands run through a shell, so environment variables are expanded at start time. The most important one is $PORT, which the platform assigns dynamically; hard-coding a port number is a frequent cause of failed web starts.
How the platform turns declarations into running processes
The platform reads the Procfile after the build stage and creates a process formation, the mapping of each type to a desired number of instances. Scaling commands then change those numbers without touching the code, for example three web instances and two workers.
Each instance runs as an isolated, disposable process, often in a container. The platform acts as the process supervisor: it restarts crashed instances, sends SIGTERM on shutdown and expects the process to exit within a grace window, commonly 30 seconds, before sending SIGKILL. A well-behaved process therefore implements graceful shutdown, finishing current requests or returning jobs to the queue.
Processes must log to standard output and standard error, not to local files. The platform collects these streams centrally, which keeps instances interchangeable and makes rolling restarts safe.
This table summarizes the lifecycle stages in which the Procfile plays a role.
| Stage | What happens | Procfile involvement |
|---|---|---|
| Build | Dependencies installed, artifact created | Read and validated, not executed |
| Release | Configuration attached to the build | The release command runs once |
| Run | Instances started per formation | Each type’s command starts its processes |
| Restart or deploy | Old instances replaced | Commands rerun for every new instance |
Procfile compared with other process definitions
A Procfile is the simplest widely used format for declaring processes, and it deliberately leaves out details that heavier tools expose. It says what to run, but not resource limits, health checks, dependencies between services or restart policies; the platform supplies those defaults.
| Format | Main purpose | Level of detail | Typical environment |
|---|---|---|---|
| Procfile | Declare process types and start commands | Minimal, one line per type | Platform as a service, buildpacks |
| systemd unit file | Define a host service | High, including restart policy and dependencies | Single Linux server |
| Supervisord configuration | Supervise several programs | Moderate, with restart and logging options | Virtual machines, containers |
| Docker Compose file | Define multi-container applications | High, including networks and volumes | Local development, small deployments |
| Kubernetes manifest | Describe desired cluster state | Very high, including probes and resources | Container orchestration |
Because of this minimalism, the same Procfile often works unchanged in development and production. Local runners such as Foreman start every declared type in one terminal with interleaved, color-coded output, which mirrors the production formation on a laptop.
Writing a reliable Procfile
A reliable Procfile starts long-running foreground processes and nothing else. The command must not daemonize, because the platform tracks the process it launched; a program that forks into the background makes the supervisor believe it has exited and triggers a crash loop.
- Bind web processes to `$PORT` on all interfaces, never to a fixed port or to localhost only.
- Use the exec form of a launcher or call the server directly, so signals reach the application rather than a wrapper shell.
- Keep one concern per type: separate web serving from background jobs so each scales independently.
- Run database migrations in `release`, not in the web command, to avoid several instances migrating at once.
- Avoid comments and blank-line tricks, because parsers differ in how tolerant they are.
The table below lists frequent mistakes, the symptom each one produces and the fix.
| Mistake | Symptom | Fix |
|---|---|---|
| Hard-coded port | Web boot timeout, process killed | Bind to $PORT |
File named procfile.txt | No processes start after deploy | Rename to Procfile without extension |
| Daemonized command | Repeated restarts in a crash loop | Run the program in the foreground |
| Migrations in the web command | Locking errors during scale-out | Move them to a release entry |
| Several clock instances | Scheduled tasks run more than once | Scale the clock type to exactly one |
Limitations of the Procfile model
The Procfile model assumes stateless, horizontally scalable processes. Applications that write to local disk, keep sessions in memory or rely on a single long-lived host fit poorly, because instances are replaced without warning during restarts and deploys.
The format also has no formal specification. Platforms agree on the basic name: command syntax but differ on special type names, support for comments and how commands are passed to the shell. Teams moving between providers should test the Procfile on the target platform rather than assume identical behavior.
The short version
A Procfile is like a short list of instructions taped to a machine. Each line says, in effect, “this part of the program is called web, and here is how to switch it on” or “this part is called worker, and here is its switch”.
The hosting service reads that list and does the rest: it switches each part on, keeps it running, restarts it if it stops and runs more copies when traffic grows. The developer only says what to run; the platform handles the running.
Where it makes a difference
A three-person team runs a booking application written in Python on a platform-as-a-service. Its Procfile has three process declarations: a web entry that starts Gunicorn on $PORT, a worker entry that starts a Celery worker for confirmation emails, and a release entry that applies database migrations.
Before a holiday campaign, the team scales the formation from two web instances and one worker to six web instances and four workers with a single command, without editing code. During each deploy the release step migrates the schema once, then new instances replace old ones in a rolling fashion. When a worker crashes on a malformed message, the platform restarts it within seconds. The campaign runs without downtime, and afterward the team scales back down to reduce cost.