Platform as a Service — DevOps

A PaaS (Platform as a Service, such as Heroku, Railway, Render) builds and runs code from a git push: the platform recognises the language from files such as…

On a VPS, the first hour goes into locking the server. After that come nginx, systemd, TLS certificates, and an apt upgrade for every security patch. All of it has to be done before a single notes-api feature reaches the people using it.

A PaaS (Platform as a Service) removes all of that. You only give it your code, and the platform builds it, runs it, restarts it, and adds copies when you ask. You don't log in to a server, run apt upgrade or manage systemd. Picture living in a serviced apartment. You only bring your things. Power, water, cleaning and repairs are handled by the management. Want another room, just say so. But you can't knock down walls, anything you leave on the floor is thrown away whenever the room is cleaned, and the price per night is higher than renting a house. Your things are the code, the management is the platform, and power and repairs are the OS, patches and restarts. Another room means another copy of the app. The walls you can't knock down are the limited control. The things on the floor are files the app writes to its disk, which are gone after every restart. The rented house is a VPS. In this lesson the same notes-api moves from web-1 to Heroku, the PaaS that popularised this way of working. Railway, Render and Fly.io are similar.

Deploying with git push

In the notes-api repo you only add one file named Procfile (no extension), which lists the processes the platform runs:

web: node app.js

It means: the process called web runs with node app.js, and that web process is the one that receives HTTP requests. Then heroku create makes the app on Heroku and adds a git remote called heroku (the address of the repo on Heroku). git push heroku main sends your code there:

$ heroku create notes-api
$ git push heroku main
remote: -----> Building on the Heroku-24 stack
remote: -----> Determining which buildpack to use for this app
remote: -----> Node.js app detected
...
remote: -----> Build succeeded!
remote: -----> Discovering process types
remote:        Procfile declares types -> web
...
remote:        Released v3
remote:        https://notes-api-3f9a1c2b4d5e.herokuapp.com/ deployed to Heroku

PORT and config vars

On web-1, notes-api listens on port 3000, and nginx passes requests on to it. On Heroku, requests from the internet reach the Heroku router: a part of the platform that works like nginx on web-1 (not a network router). The platform chooses the app's port through the PORT environment variable:

const port = process.env.PORT || 3000;
app.listen(port);

|| 3000 is used when PORT is empty, for example when the app runs on your laptop. If the app keeps using app.listen(3000), the router can never connect, and after 60 seconds the log says Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch.

Secrets and the database address are kept as config vars: environment variables that the platform stores and gives to the app when it starts. How to manage secrets is in the lesson Environment Variables & Secrets. heroku addons:create attaches an add-on (an extra service from the platform), here a Postgres database, and heroku config:set stores one config var:

$ heroku addons:create heroku-postgresql:essential-0
$ heroku config:set JWT_SECRET=...

The Postgres add-on sets DATABASE_URL automatically. Without it, notes-api crashes on start, and the router answers every request with code=H10 desc="App crashed" and status 503.

A disk that is always emptied

Each instance on Heroku is called a dyno, and its disk is ephemeral (temporary): every file the app writes is gone whenever the dyno restarts. A dyno restarts on every deploy, every config change, and roughly once a day. So an attachment saved to storage/attachments is gone as soon as you git push, and a GET for it is answered 404.

There's a second problem: each dyno has its own disk. With 2 dynos (web.1 and web.2), the router spreads requests at random. So an attachment stored on web.1 sometimes gets a 404, because the request landed on web.2. The fix is the same for both problems: keep files in object storage (a service in the cloud that stores files) such as S3 or R2, which the lesson Object Storage (S3/R2/GCS) covers. Use the dyno's disk only for temporary files.

Scaling: adding dynos

Adding dynos takes one command:

$ heroku ps:scale web=2
Scaling dynos... done, now running web at 2:Standard-1X

Now two copies of notes-api run behind the router. This is only safe if the app is stateless: it keeps nothing in a dyno's memory or disk that the next request needs. Sessions (data on who is logged in) and caches go in Postgres or Redis.

When PaaS stops being cheap

The prices in this table are examples to calculate with, not current prices:

Need PaaS (example) VPS (example)
Starting out: 1 small instance + Postgres $7 + $5 = $12 a month a 1 GB VPS at $6, plus your hours managing a server
Busy: 4 dynos of 512 MB + Postgres 4 × $25 + $20 = $120 a month 2 VPSes of 4 GB = $48 a month

Per GB of RAM, a PaaS can cost several times as much as a VPS. In exchange you don't manage the OS, patches, TLS, restarts or a deploy pipeline. Besides the cost, control is limited: no root access, no installing system software as you like, an ephemeral disk, and Heroku stops requests that take more than 30 seconds.

A PaaS fits best for a small team without a DevOps engineer (a person whose job is managing servers and deploys) that wants to focus on the product, for an MVP (the simplest first version of a product), and for side projects. A VPS (or other IaaS) starts to make more sense when the PaaS bill is bigger than the value of the time it saves you, or when you need full control.

Netlify, Vercel, Railway or Render?

In the exercise, recommendPlatform({ type, framework, needsDatabase, budget }) uses the following rules. They are checked in order, stopping at the first rule that matches:

  1. type is "static": "Netlify" (static site hosting)
  2. framework is "nextjs": "Vercel" (the makers of Next.js)
  3. needsDatabase is true and budget is "low": "Railway"
  4. needsDatabase is true and budget is "high": "AWS Elastic Beanstalk", the PaaS of AWS
  5. anything else: "Render"

The order matters: { type: "ssr", framework: "nextjs", needsDatabase: true, budget: "low" } matches rules 2 and 3, but rule 2 is checked first, so the result is "Vercel".

Heroku's status as of November 2026: on 6 February 2026, Heroku announced a move to a sustaining engineering model (Heroku blog, "An Update on Heroku"). Under this model the platform is still maintained for stability, security and support, but there are no new features, and Enterprise contracts are no longer offered to new customers. Customers who pay by credit card, existing and new, can keep using it with no change in price. This lesson still uses Heroku because its flow is the clearest. The ideas are the same on other platforms: a port chosen by the platform, secrets in environment variables, and a disk that is empty again after each deploy. Other options for an app that runs code on a server:

Platform When to pick it
Render the closest to Heroku: web services, workers, cron jobs (scheduled tasks) and managed Postgres in one place
Railway an app plus a database that you want online quickly, with costs based on usage
Fly.io an app in a container (a Dockerfile) that should run close to users in several regions

⚠️ Why does an app that ran fine on a VPS break on Heroku?

TL;DR: A PaaS (Platform as a Service, such as Heroku, Railway, Render) builds and runs code from a git push: the platform recognises the language from files such as package.json, reads the Procfile (the list of processes: web: node app.js), then publishes a numbered release. The app must listen on process.env.PORT, the port the platform chose, and secrets and DATABASE_URL become config vars (environment variables the platform stores). The disk of a dyno (an instance on Heroku) is ephemeral: files vanish on every deploy and restart, and each dyno has its own disk, so uploads go in object storage such as S3. heroku ps:scale web=2 adds instances, as long as the app is stateless (keeps no data in a dyno's memory or disk). Its main drawbacks are a higher cost and limited control. A PaaS fits best for a small team without a DevOps engineer that wants to focus on the product.

⚡ Deploying with git push

Write:

web: node app.js
$ heroku create notes-api
$ git push heroku main

Meaning: On a PaaS (a platform that runs your code, here Heroku), one Procfile is enough: the web process runs with node app.js and receives HTTP requests. git push heroku main sends the code. The platform recognises Node from package.json, builds it, then publishes a numbered release (a version of the app) that can be rolled back. Similar PaaS options: Railway and Render.

⚡ The platform picks the port

Write:

const port = process.env.PORT || 3000;
app.listen(port);
Guess first: Heroku tells the app which port to use through PORT. If the app keeps using app.listen(3000), what happens?

The Heroku router (which passes requests from the internet to the app) can never connect, and after 60 seconds the log says Error R10 (Boot timeout) -> Web process failed to bind to $PORT.

Meaning: The app listens on the port from process.env.PORT, and uses 3000 only when PORT is empty, for example on your laptop. Secrets and DATABASE_URL are also stored on the platform as config vars, not in a .env file that gets committed.

⚡ A disk that is always emptied

Meaning: Each instance (running copy of the app) on Heroku is called a dyno. A dyno's disk is ephemeral (temporary): an attachment in storage/attachments is gone as soon as you git push, because every deploy restarts the dynos. Each dyno also has its own disk, which other dynos can't see. So files go in object storage (a service that stores files) such as S3 or R2.

⚡ Adding dynos

Write:

$ heroku ps:scale web=2

Meaning: Now two dynos run, and the Heroku router shares the requests between them. This is safe as long as the app is stateless, meaning it keeps no data in a dyno's memory: sessions (login data) and caches live in Postgres or Redis.

What you will learn