Chapter 14
Deployment, DevOps, Observability and Operations
Diploma in Full Stack Programming
Backend Development with Node.js/Express
•
Diploma
Deployment, DevOps, Observability and Operations
Introduction and Context
A backend application is not complete when it runs successfully on a developer’s laptop. It becomes a dependable product only when it can be built, configured, deployed, observed, secured, scaled, and maintained in a real operating environment. Deployment and operations therefore extend software engineering beyond source code. They connect programming decisions with infrastructure, organizational processes, reliability, cost, security, and user experience.
For Node.js and Express services, operational quality is especially important because applications are commonly deployed as network services that depend on databases, queues, object storage, authentication providers, and other APIs. A defect may appear as slow requests, exhausted memory, failed background jobs, or an apparently healthy process that cannot serve users. Professional backend development consequently requires a systematic approach to delivery and operations.
This chapter presents a practical foundation for containerization, cloud deployment, infrastructure configuration, continuous integration and continuous delivery (CI/CD), observability, service-level objectives (SLOs), cost awareness, and incident response.
Learning Objectives
By the end of this chapter, you should be able to:
Explain the relationship between development, operations, DevOps, and platform engineering.
Containerize a Node.js/Express application using a secure and efficient image design.
Describe deployment models and select an appropriate cloud service.
Design a basic CI/CD pipeline with quality and security gates.
Distinguish logs, metrics, traces, events, and health indicators.
Define useful service-level indicators (SLIs) and SLOs.
Apply safe configuration, secret management, rollback, and scaling practices.
Investigate an operational incident using evidence rather than guesswork.
Recognize reliability, ethical, governance, and cost implications of deployment decisions.
1. From Application to Operated Service
A service has at least four operational dimensions:
Functionality: Does it produce correct results?
Availability: Can users access it when needed?
Performance: Does it respond within an acceptable time?
Operability: Can a team deploy, monitor, diagnose, and recover it safely?
DevOps is not merely a collection of tools. It is a set of practices and cultural principles that reduce the separation between development and operations. Its central ideas include automation, small and reversible changes, shared responsibility, rapid feedback, and learning from failures. Continuous integration validates changes frequently; continuous delivery keeps software in a deployable state; continuous deployment automatically releases approved changes to production.
A useful delivery chain is:
Software delivery and operations feedback cycle
Figure: Software delivery and operations feedback cycle
Figure: A delivery cycle in which operational feedback informs future code and deployment decisions.
2. Packaging Node.js/Express Services
2.1 Configuration and process design
A production service should obtain environment-specific values from configuration rather than embedding them in source code. Typical configuration includes the listening port, database URL, log level, external service endpoints, and feature flags. Secrets such as passwords, private keys, and tokens must not be committed to source control or printed in logs.
Express applications should listen on the port supplied by the environment and bind appropriately for the hosting platform:
const port = Number(process.env.PORT || 3000);
app.listen(port, '0.0.0.0', () => {
console.log(`API listening on port ${port}`);
});
In production, use structured logging, centralized error middleware, graceful shutdown, request timeouts, input validation, and a database connection strategy appropriate for the deployment platform. A process should stop accepting new work, finish safe in-flight work, close connections, and then exit when it receives a termination signal such as SIGTERM.
2.2 Containers
A container packages an application with its runtime and dependencies while sharing the host operating system kernel. It is not a complete virtual machine. Containers improve consistency between development, testing, and production, but they do not automatically provide security, reliability, or scalability.
A suitable Dockerfile for a simple service might be:
FROM node:20-bookworm-slim AS dependencies
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
FROM node:20-bookworm-slim
ENV NODE_ENV=production
WORKDIR /app
RUN useradd --create-home --shell /usr/sbin/nologin appuser
COPY --from=dependencies /app/node_modules ./node_modules
COPY package*.json ./
COPY src ./src
USER appuser
EXPOSE 3000
CMD ["node", "src/server.js"]
The example uses a multi-stage structure, installs reproducible dependencies with npm ci, omits development dependencies, avoids running as root, and copies only required files. A .dockerignore should exclude .git, local dependencies, test output, environment files, and unnecessary documentation. Image tags should be immutable in deployment records, preferably using a content digest or a unique commit identifier rather than repeatedly moving the latest tag.
A container image should be scanned for vulnerable operating-system packages and application dependencies. Vulnerability reports require judgment: a finding may be unreachable, mitigated, or genuinely urgent. Nevertheless, teams should define ownership, remediation time targets, and an exception process.
2.3 Health endpoints
A health endpoint is an operational contract, not a substitute for monitoring. A liveness check asks whether the process is running and able to make progress. A readiness check asks whether the instance can accept traffic, including whether essential dependencies are usable. A startup check may allow slow initialization without being restarted prematurely.
For example, /live might return HTTP 200 if the event loop and server are functioning. /ready might return HTTP 200 only after configuration is validated and a database connection is available. Health checks must be lightweight and must not perform expensive queries on every request. If a nonessential dependency fails, the service may remain live and partially ready according to an explicit policy.
3. Deployment Models and Infrastructure Configuration
Cloud deployment choices include virtual machines, managed application platforms, containers-as-a-service, and container orchestration systems such as Kubernetes. Managed platforms reduce infrastructure administration; orchestration systems offer extensive control but introduce complexity in networking, scheduling, security, upgrades, and observability.
Infrastructure configuration should be versioned and reviewable. Infrastructure as Code (IaC) represents networks, compute resources, databases, permissions, and monitoring rules in declarative files. The desired state is reviewed, tested, and applied by controlled automation. Separate state management, access controls, and environment configuration are essential. Never store plaintext secrets in a public repository or unencrypted state file.
A basic deployment architecture commonly contains:
A source repository and CI runner.
An image registry.
A load balancer or API gateway.
One or more application instances.
Managed data services.
Centralized logs, metrics, and traces.
Identity, network, backup, and alerting controls.
Cloud design should consider region selection, data residency, availability zones, backup restoration, quotas, vendor dependency, and the shared-responsibility model. The provider secures some underlying infrastructure, while the customer remains responsible for code, identities, configurations, data handling, and often the guest operating system.
4. CI/CD Pipeline Design
A professional pipeline should provide fast feedback without allowing unsafe changes to reach users. A representative sequence is:
Validate: format checks, linting, dependency checks, and unit tests.
Build: compile or package the application and build the container image.
Test: run integration, contract, and security tests.
Publish: sign and push the image to a registry.
Deploy to a non-production environment: apply approved infrastructure and configuration.
Verify: run smoke tests and inspect health indicators.
Release progressively: use canary, blue-green, or rolling deployment.
Observe and promote or roll back: use defined criteria and a human approval when risk requires it.
A pipeline is itself production infrastructure. Protect its credentials, restrict who can modify workflows, record artifacts, and prevent untrusted pull-request code from accessing production secrets. Dependency lockfiles, provenance information, image signing, and software bills of materials improve supply-chain visibility.
A rolling deployment replaces instances gradually and is economical, but mixed application versions may coexist. A blue-green deployment maintains two environments and switches traffic, making rollback simple but temporarily requiring more resources. A canary deployment sends a small proportion of traffic to the new version and expands exposure when indicators remain acceptable.
Rollback is not always sufficient. A schema migration may be irreversible, and an old application version may not understand new data. Database changes should generally follow an expand-and-contract pattern: add backward-compatible structures, deploy code that supports both forms, migrate data, then remove obsolete structures in a later change.
5. Observability: Evidence About System Behaviour
Monitoring reports known conditions; observability helps engineers infer unknown internal conditions from externally visible evidence. The principal signals are:
Logs: timestamped records of events, decisions, errors, and context.
Metrics: numerical measurements collected over time.
Traces: connected records showing a request’s path across services.
Profiles: measurements of resource usage within a process.
Events: significant state changes, such as a deployment or failover.
A useful log entry is structured JSON containing a timestamp, severity, service name, environment, request or trace identifier, event name, and safe contextual fields. Do not log passwords, access tokens, unnecessary personal data, or full payment information. Error logs should include a stable error classification and enough context to reproduce the problem without exposing secrets.
Metrics should be designed around questions. Common categories include request rate, error rate, latency, saturation, queue depth, CPU, memory, database connection utilization, and business outcomes. Histograms or appropriately calculated percentiles are usually more useful than average latency because averages can hide a slow tail. Percentiles must be interpreted with care: a percentile calculated by aggregating averages from instances is not generally the same as the percentile calculated from all request observations.
Distributed tracing propagates a trace identifier and span context across service boundaries. It can reveal that an apparently slow API is waiting on a database or an external provider. Sampling reduces overhead, but sampling policy should preserve errors, slow requests, and representative normal traffic.
6. SLIs, SLOs, SLAs, and Error Budgets
An SLI is a measured indicator of service performance. Examples include the proportion of valid requests that succeed or the proportion completed below a latency threshold. An SLO is the target for an SLI over a defined time window. An SLA is a formal agreement that may include consequences when commitments are not met.
The numerator and denominator must be defined precisely. For example, a team may exclude deliberately rejected requests caused by invalid client input, but it should not quietly exclude failures that make the service appear healthier. The time window and measurement source must also be stated.
If an SLO is 99.9% availability for a 30-day period, the permitted unavailability is:
This calculation assumes the SLO is a time-based availability target and that all minutes are weighted equally. A request-based SLO may produce a different budget because it counts requests rather than elapsed time.
Error budgets create a decision framework. When the budget is healthy, a team may accept controlled delivery risk and invest in features. When the budget is exhausted, it may pause risky releases and prioritize reliability work. SLOs should represent user impact, not merely what is easy to measure.
7. Reliability, Capacity, and Cost
Reliability is a system property produced by architecture, code, operations, and organizational decisions. Redundancy can reduce single points of failure, but it adds cost and complexity. Timeouts, retries, and circuit breakers must be designed together. Unbounded retries can amplify an outage; exponential backoff with jitter reduces synchronized retry storms. Idempotency keys are important when clients may safely retry commands such as payment or order creation.
Capacity planning considers expected traffic, resource limits, and scaling response time. Vertical scaling increases resources for an instance; horizontal scaling adds instances. Stateless application instances are easier to scale horizontally, while sessions should be stored in a shared, durable service when necessary. Connection pools must be sized with the database’s total connection limit in mind; simply increasing every application pool can overload the database.
Cloud cost is an operational metric. Major cost drivers include compute time, database capacity, storage, data transfer, logs, metrics retention, and idle resources. Cost optimization should not remove essential backups, security controls, or observability. Useful practices include budgets and alerts, retention policies, rightsizing, autoscaling limits, scheduled shutdown of non-production environments, and cost allocation tags.
8. Incident Response and Operations
An incident is an event that threatens service reliability, security, data integrity, or user trust. Incident response should be organized rather than improvised. A basic lifecycle is:
Detect and acknowledge the issue.
Assess severity and user impact.
Stabilize the system, for example by rollback, traffic reduction, or feature disabling.
Communicate with stakeholders at an agreed cadence.
Diagnose using timelines, logs, metrics, traces, and recent changes.
Restore normal service.
Conduct a blameless review and track preventive actions.
A runbook gives explicit steps for a known operational situation, such as rotating a credential or restoring a database backup. An on-call arrangement must include escalation, access, handover, and reasonable workload expectations. Alerts should be actionable: an alert without a clear response path creates fatigue and encourages dismissal of genuine warnings.
A post-incident review should explain what happened, why defenses did not prevent or detect it, how users were affected, and which system improvements will be made. Blamelessness does not mean absence of accountability; it means examining system conditions rather than reducing learning to individual fault.
9. Security, Governance, and Ethical Responsibilities
Deployment decisions affect privacy, safety, and equity. Teams should apply least privilege, encrypt data in transit and at rest where appropriate, rotate credentials, patch dependencies, validate inputs, and maintain auditable access records. Personal data should be collected and retained only for legitimate purposes. Logs and traces may contain identifiers and therefore require retention, access, masking, and deletion policies.
Regulatory obligations depend on context and jurisdiction. Examples include privacy, financial, health, accessibility, records-retention, and breach-notification requirements. A deployment pipeline should support evidence such as approvals, test results, change records, and access logs.
AI-assisted coding and operations can generate deployment files, tests, queries, and incident summaries. It can also introduce insecure dependencies, incorrect assumptions, leaked confidential context, or misleading explanations. Human review, automated testing, secret scanning, provenance, and approval controls remain necessary. AI should support professional judgment rather than replace it.
10. Illustrative Case: Deploying a Course Registration API
Background
A college operates a Node.js/Express course-registration API. The initial system runs on one virtual machine, writes local log files, and is deployed manually by copying source files. During enrollment periods, response times increase and operators cannot determine whether the database, application, or network is responsible.
Problem
The service has no reproducible build, no readiness check, no rollback procedure, and no defined reliability target. A failed deployment previously caused several hours of disruption. Logs contain student identifiers and are retained indefinitely.
Analysis
The team identifies four risks: the single application instance is a failure point; manual deployment causes configuration drift; local logs disappear when the machine is replaced; and database connection usage is not visible. The most important user journey is submitting a registration request, not merely receiving an HTTP response.
Approach and Solution
The team packages the service in a non-root container using a lockfile and a minimal runtime image. Configuration is injected through the platform’s secret and environment mechanisms. /live checks process progress, while /ready verifies required startup dependencies. The service is deployed behind a load balancer with two instances.
The CI pipeline runs linting, unit tests, integration tests against a temporary database, dependency scanning, image scanning, and smoke tests. Images are identified by commit digest. A canary release receives 10% of traffic initially. The registration workflow emits a trace and records a success metric that excludes intentionally rejected duplicate registrations but includes server failures.
The team sets an initial SLO of 99.9% successful registration requests over 30 days and a latency objective for the 95th percentile. Logs are centralized with student identifiers masked. Alerts cover registration error rate, database saturation, readiness failures, and error-budget consumption. A runbook documents rollback, database restoration testing, and escalation.
Outcome
During the next enrollment rehearsal, the canary shows elevated database latency. Promotion stops automatically, and the previous version remains active. Investigation shows an inefficient query introduced by the new release. The team optimizes the query, adds a regression test, and repeats the canary. The incident is contained without a broad outage.
Learning Points
The case demonstrates that deployment safety depends on more than containers. Reproducibility, progressive delivery, user-centered SLIs, privacy-aware telemetry, database capacity management, and rehearsed recovery procedures work together. The team also learns that observability must be designed before an incident, not retrofitted during one.
11. Best-Practice Checklist
Before production release, confirm that:
The image is reproducible, minimal, scanned, and not run as root.
Dependencies are locked and vulnerabilities have owners or approved exceptions.
Configuration and secrets are externalized and access-controlled.
The service handles termination and exposes meaningful health checks.
Automated tests and deployment gates are passing.
Rollback and database migration compatibility have been considered.
Logs, metrics, traces, dashboards, and actionable alerts exist.
SLIs, SLOs, and error-budget policies are written down.
Backups have been restored in a test, not merely created.
Cost, data residency, privacy, and retention have been reviewed.
An incident owner, runbook, escalation route, and communication plan exist.
Chapter Summary
Deployment turns a Node.js/Express application into an operated service. Containers improve packaging consistency, while secure images, external configuration, non-root execution, and health checks reduce operational risk. Cloud and IaC decisions determine control, cost, resilience, and governance responsibilities. CI/CD pipelines automate validation, artifact creation, progressive release, and rollback, but they must themselves be secured.
Observability combines logs, metrics, traces, profiles, and events to explain system behaviour. SLIs measure user-relevant performance; SLOs define targets; SLAs formalize commitments; and error budgets connect reliability with release decisions. Reliable operations also require capacity planning, bounded retries, graceful shutdown, cost controls, incident response, runbooks, and blameless learning. Security, privacy, regulatory compliance, and responsible use of AI are integral to deployment rather than optional additions.
Key Terms
Container: An isolated process environment packaging an application and its dependencies.
Container image: An immutable template from which containers are created.
DevOps: Practices that integrate software development and operations through collaboration, automation, and feedback.
CI/CD: Continuous integration and continuous delivery or deployment practices.
Infrastructure as Code: Declarative, version-controlled management of infrastructure resources.
Health check: An automated test of process liveness, startup state, or readiness for traffic.
Liveness: The condition that a process is running and making progress.
Readiness: The condition that an instance can safely receive requests.
Observability: The ability to infer internal system state from external outputs.
Log: A timestamped record of an event or application message.
Metric: A numerical measurement tracked over time.
Trace: A connected representation of a request’s path through services.
SLI: A quantitative service-level indicator.
SLO: A target value for an SLI over a stated period.
SLA: A formal service-level agreement with defined commitments.
Error budget: The tolerable amount of failure implied by an SLO.
Canary deployment: A release exposed initially to a small traffic fraction.
Rollback: Returning service operation to a previous known version or configuration.
Runbook: Documented steps for responding to a recurring operational situation.
Idempotency: The property that repeating an operation has the same intended effect as performing it once.
Review Questions
Short Answer Questions
Why should production containers normally avoid running processes as root?
Distinguish a liveness check from a readiness check.
What are the three principal observability signals discussed in this chapter?
Define an error budget in relation to an SLO.
Why can unbounded retries worsen an outage?
Long Answer Questions
Explain how a CI/CD pipeline can improve both delivery speed and production safety.
Compare rolling, blue-green, and canary deployments, including their principal trade-offs.
Explain how logs, metrics, and traces complement one another during incident diagnosis.
Discuss the security and governance responsibilities of a team deploying a Node.js service to the cloud.
Describe a complete incident-response lifecycle from detection through post-incident learning.
Analytical / Application Questions
An API has an SLO of 99.9% availability over 30 days. Calculate the approximate permitted downtime and explain why a request-based SLO might produce a different result.
Design an SLI and SLO for a course-registration operation. Define which requests belong in the numerator and denominator and justify your choices.
A canary release shows normal CPU usage but a sharp increase in database latency and registration failures. Using the principles in this chapter, propose an immediate response and a follow-up investigation plan.
Multiple Choice Questions with Answers
Question 1
Which practice most directly improves reproducibility between development and production?
A. Copying source files manually to a server
B. Using a versioned container image built from a locked dependency set
C. Storing configuration inside application source code
D. Using the mutable latest image tag for every release
Correct Answer: B. Using a versioned container image built from a locked dependency set
Question 2
What is the primary purpose of a readiness check?
A. To determine whether an instance should receive traffic
B. To verify that source code has been formatted
C. To measure monthly cloud expenditure
D. To encrypt application logs
Correct Answer: A. To determine whether an instance should receive traffic
Question 3
Which observability signal is most suitable for following one request across multiple services?
A. A trace
B. A disk quota
C. A deployment manifest
D. A dependency lockfile
Correct Answer: A. A trace
Question 4
An availability SLO is 99.9% over a 30-day period of 43,200 minutes. What is the approximate permitted downtime?
A. 4.32 minutes
B. 43.2 minutes
C. 432 minutes
D. 4,320 minutes
Correct Answer: B. 43.2 minutes
Question 5
Which deployment strategy initially sends only a small proportion of traffic to the new version?
A. Canary deployment
B. Uncontrolled deployment
C. Single-instance deployment
D. Full replacement without verification
Correct Answer: A. Canary deployment
Question 6
Why are structured logs useful in production operations?
A. They prevent all application errors
B. They make events consistently searchable and aggregatable
C. They eliminate the need for metrics
D. They guarantee that sensitive data is safe to print
Correct Answer: B. They make events consistently searchable and aggregatable
Question 7
Which action is safest when a new release causes a severe user-facing failure and a known compatible version exists?
A. Increase retries without a limit
B. Disable all monitoring
C. Roll back or stop promotion while investigating
D. Delete the database immediately
Correct Answer: C. Roll back or stop promotion while investigating
Question 8
What is a major danger of storing secrets in a source repository?
A. The application will always start more slowly
B. The secrets may be exposed through repository history and access
C. The container cannot expose a port
D. Metrics cannot be collected
Correct Answer: B. The secrets may be exposed through repository history and access
Question 9
Which statement about an error budget is correct?
A. It is the amount of failure allowed by an SLO over its measurement window
B. It is the monthly salary of the operations team
C. It is the maximum number of source-code lines in a service
D. It is the number of containers that may run simultaneously
Correct Answer: A. It is the amount of failure allowed by an SLO over its measurement window
Question 10
Why should a database connection pool be considered when horizontally scaling an application?
A. Each new instance can increase total database connections and overload the database
B. Horizontal scaling automatically removes all database connections
C. Connection pools affect only browser rendering
D. Database limits are unrelated to application instance count
Correct Answer: A. Each new instance can increase total database connections and overload the database
Backend Development with Node.js/Express
Chapter 14
of 15