DEVOPS, SRE AND CLOUD · PART 0 · START HERE · BASICS · 3 OF 187

How Code Reaches Users: Commit to Production

Follow one small change to ShopRung from a laptop to real users: commit and push, pull request and review, continuous integration (tests in 0.23 s on our run), an artifact built once, staging, a deploy with a health check (healthy 60 to 134 ms after start in our runs), monitoring, and rollback. Every stage is a part of this track.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
1 / 14

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Commit
  • review
  • CI
  • build once
  • staging
  • rolling deploy with health checks
  • monitor
  • roll back fast

Notes

The change

It starts on a laptop. The developer makes a branch, changes the health check so it also reports how long the app has been running, and runs the tests locally: nine tests, nine pass. Then a commit with a clear message, and a push to the shared repository. Git, the version control system, now has an exact record of who changed what and why, which is the first rule of DevOps: everything lives in version control.

On the laptop
$ git switch -c health-uptime
# edit src/server.js
$ npm test
# tests 9  pass 9  fail 0
$ git commit -am "Health check
    reports uptime"
$ git push -u origin
    health-uptime

Review

On the shared repository the developer opens a pull request, a proposal to merge the branch into main. Automatic checks start running on it, and a teammate reads the change, asks a question, and approves. Only then is it merged. Teams keep one rule here: the main branch must always be in a state you could release. Part four covers Git, branching and reviews properly.

Pull request
  • what changed and why
  • automatic checks run on it
  • a teammate reviews the diff
  • comments, a fix, approve
  • merge into main
  • main must always be releasable

Continuous integration

Every push triggers continuous integration, or CI. A fresh machine checks out the code and runs the tests. ShopRung's nine tests took between two and four tenths of a second in our three runs; the first run is slower while files warm up. Real projects have thousands of tests and take minutes. If any test fails, the line stops, and nothing broken travels further. Part seven builds pipelines like this.

CI on ShopRung (our runs)
$ npm test
# tests 9
# pass 9
# fail 0
three runs: 412 ms, 232 ms,
  229 ms (first run warms up)

a red test stops the line:
  nothing broken goes further

Build once

When the tests pass, CI builds an artifact: something you can deploy. For ShopRung that is a container image tagged with the version, pushed to a registry, a store for images. The important rule is build once. The very same image goes to staging and then to production, so what you tested is exactly what you ship. Rebuilding for each environment invites surprises. Containers are part six.

The artifact
$ docker build -t
    shoprung:1.0.1 .
$ docker push
    registry/shoprung:1.0.1

the SAME image goes to
  staging and production
never rebuild per environment

Staging

Next, the image is deployed to staging, an environment built like production but with fake data. Smoke tests check the basics: does it start, does the home page load, can you check out. Integration with real neighbours, like the database and payments sandbox, gets tested here too. If staging is healthy, the same image is promoted to production.

In staging
  • same image, same config shape
  • smaller, fake data
  • smoke tests: does it start, does checkout work
  • integration with real dependencies
  • pass → promote to production

Deploy

Production runs several copies of the app behind a load balancer. A rolling deploy starts one new copy, waits until its health check says it is ready, sends it traffic, then stops one old copy, and repeats. Users never see the site go down. Other strategies, blue-green and canary, are in part seven. Infrastructure for all of this is written as code, in part nine, and often runs on Kubernetes, part ten.

A rolling deploy
  • start one new instance
  • wait for its health check
  • send it traffic
  • stop one old instance
  • repeat until all are new
  • users never see a gap

The health check

The health check is a tiny endpoint that answers when the app is ready. ShopRung's says status up, with the app name and version. In our three runs it answered sixty to a hundred and thirty four milliseconds after the process started. Deploy tools poll it. If a new copy never becomes healthy, the deploy stops by itself, and the old copies keep serving users. A good health check is one of the cheapest safety nets you can build.

ShopRung health (our runs)
GET /api/health
{"status":"UP",
 "app":"ShopRung",
 "version":"1.0.0"}

start to healthy:
  134 ms, 64 ms, 60 ms

not healthy in time?
  the deploy stops itself

Watch it

Deployed is not done. Monitoring watches the error rate, how long requests take, how much traffic there is, how full the machines are, and business numbers like orders per minute. The team compares them with the minutes before the deploy. If errors rise, an alert fires. This is observability, part eleven, and the habits around incidents and reliability are part twelve.

After the deploy, watch
  • error rate
  • response time (latency)
  • traffic
  • saturation: CPU, memory
  • business: orders per minute
  • compare to before the deploy

Rollback

And when something is wrong? Roll back first, debug second. The previous image, version one point zero point zero, is still in the registry, so the platform simply redeploys it, and users are safe within minutes. Then the team finds the cause calmly. This is why small changes matter: when only one line changed, finding what broke is easy. When a release has three months of changes, it is a nightmare.

Rollback
  • the old image is still in the registry: 1.0.0
  • redeploy it: minutes, not hours
  • users are safe again
  • then find the cause calmly
  • small changes = easy to find what broke

Your map

That is the whole journey, and your map of the course. Under every stage sit Linux and networking, parts one and two. Scripting and Git are parts three and four. Building and running apps is five, containers six, CI and CD seven. The cloud and infrastructure as code are eight and nine, Kubernetes is ten, and monitoring and site reliability are eleven and twelve. Security, GitOps and platforms in part thirteen tie it together.

Where each stage is taught
  • Linux, networking: under all of it, parts 1 and 2
  • scripting, Git: parts 3, 4
  • build and run apps: part 5
  • containers: part 6
  • CI/CD: part 7
  • cloud and IaC: parts 8, 9
  • Kubernetes: part 10
  • monitoring, SRE: parts 11, 12

Common mistakes

Mistakes. Building a new artifact for each environment, so production runs something nobody tested. A staging environment that looks nothing like production. A health check that always says OK, even when the database is down. Deploys that nobody watches. No quick way to roll back. And big, rare releases, which make every one of these problems worse.

Avoid these
  • building a new artifact per environment
  • staging that looks nothing like production
  • a health check that always says OK
  • deploys nobody watches
  • no fast way back
  • giant, rare releases

Say it like this

In the interview: a change is pushed to a branch and reviewed in a pull request. CI runs the tests and builds one versioned image, pushed to a registry. The same image goes to staging for smoke tests, then to production with a rolling or canary deploy, gated by health checks. We watch error rate and latency against the baseline, and if they get worse we roll back to the previous image, then investigate.

In the interview
  • "A change is pushed and reviewed
  • in a pull request. CI runs the tests and builds one versioned
  • image. It goes to staging for smoke tests, then a rolling or canary deploy gated by health
  • checks. We watch errors and latency, and roll back fast."

Interview questions

Q1What are the stages from commit to production?

Commit and push, pull request and review, continuous integration (tests and build), an artifact in a registry, deploy to staging and smoke tests, deploy to production with health checks, monitoring, and rollback if needed.

Q2What does "build once, deploy many" mean?

Build one versioned artifact (for example a container image) and promote that same artifact through staging to production, so what was tested is exactly what ships.

Q3What is a health check?

A small endpoint or command that says whether an instance is ready to serve; deploy tools and load balancers use it to decide when to send traffic and to stop a bad deploy.

Q4What is a rolling deployment?

Replacing instances a few at a time behind a load balancer, waiting for each new one to be healthy before removing an old one, so there is no downtime.

Q5Why roll back before debugging?

Rolling back to the previous known-good version restores users quickly; the cause can then be found without pressure.

Q6What is staging for?

A production-like environment with fake data where the release is rehearsed: smoke and integration tests before production.

Q7Why are small changes safer?

Less can break, problems are easier to trace to a cause, reviews are better, and rollbacks are simpler.

Q8What do you watch after a deploy?

Error rate, latency, traffic, saturation (CPU, memory) and business metrics, compared with the baseline before the deploy.