Procfile

On this page 7

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 typeTypical commandReceives trafficPlatform behavior
webgunicorn app:server --bind 0.0.0.0:$PORTYes, via the routerMust bind to the assigned port within a timeout
workercelery -A app workerNoRuns continuously and processes background jobs
clockpython scheduler.pyNoUsually limited to one instance to avoid duplicate runs
releasepython manage.py migrateNoRuns once per deploy; failure aborts the release
Common process types declared in a Procfile

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.

StageWhat happensProcfile involvement
BuildDependencies installed, artifact createdRead and validated, not executed
ReleaseConfiguration attached to the buildThe release command runs once
RunInstances started per formationEach type’s command starts its processes
Restart or deployOld instances replacedCommands rerun for every new instance
Procfile role across the deployment lifecycle

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.

FormatMain purposeLevel of detailTypical environment
ProcfileDeclare process types and start commandsMinimal, one line per typePlatform as a service, buildpacks
systemd unit fileDefine a host serviceHigh, including restart policy and dependenciesSingle Linux server
Supervisord configurationSupervise several programsModerate, with restart and logging optionsVirtual machines, containers
Docker Compose fileDefine multi-container applicationsHigh, including networks and volumesLocal development, small deployments
Kubernetes manifestDescribe desired cluster stateVery high, including probes and resourcesContainer orchestration
Procfile and related process definition formats

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.

MistakeSymptomFix
Hard-coded portWeb boot timeout, process killedBind to $PORT
File named procfile.txtNo processes start after deployRename to Procfile without extension
Daemonized commandRepeated restarts in a crash loopRun the program in the foreground
Migrations in the web commandLocking errors during scale-outMove them to a release entry
Several clock instancesScheduled tasks run more than onceScale the clock type to exactly one
Common Procfile mistakes

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.