Node.js course · Part 8: Running it for real · lab 8 of 9
Shipping it, and running it
What a deploy actually does, logs you can search at three in the morning, health checks that tell the truth, and shutting down without dropping anyone's request.
By the end you can
- Say what happens at build time and what happens at run time, and why it matters
- Write structured logs that are searchable and contain no secrets
- Tell liveness from readiness, and answer both honestly
- Shut a server down without dropping requests that are already in flight
Easier if you did first
step 1 of 4
What a deploy actually does
A deploy is two things that people blur together: making an artefact, and running it.
The build happens once. Your code is compiled, bundled and turned into something that no longer needs your source or your laptop. The result should be identical whatever machine built it, which is why the lock file matters and why the build must not depend on anything it did not bring with it.
The run happens every time a machine starts. It reads its environment, connects to its database, and begins answering. The same artefact runs in staging and in production; only the environment differs. That is the whole point: if the thing you tested is the thing you ship, a bug in production is a bug in something you can reproduce.
The practical consequence catches everyone once. A value read at build time is baked in; a value read at run time can differ per environment. Put a secret in the first category and you have shipped it inside the artefact.
And a deploy must be undoable. The question is never whether you will ship something broken; it is how many minutes pass before it is gone.
Five questions.
What these words mean
- artefact
- The built output you deploy. Same bytes everywhere.
- build time
- When the artefact is made. Values read here are baked in.
- run time
- When the server starts and runs. Values read here can differ per environment.
- rollback
- Putting the previous artefact back. The first move in an incident.
- health check
- An endpoint the platform calls to decide whether this instance is usable.
- zero downtime
- Starting the new version before stopping the old one.
question 1 of 5
You read process.env.API_URL in a module that runs during the build. What happens in staging?
question 2 of 5
A deploy goes out and errors spike. What is the first move?
question 3 of 5
Your health check queries the database. The database goes down. What happens?
question 4 of 5
Why is logging the whole request body a problem?
question 5 of 5
A deploy stops the old server immediately. What breaks?