The twelve-factor methodology is a set of best practices for cloud-native apps: storing configuration in environment variables (so the same build deploys unchanged across environments), treating backing services as attached resources via a URL, keeping the app stateless so any instance can handle any request, and logging to stdout rather than managing log files directly.
A twelve-factor Node.js API deploys unchanged to a laptop, staging, and production simply by supplying different environment variables, without separate config files or code branches per environment.
Likely follow-ups
Why does storing state on a specific instance's local disk violate the stateless principle, and what's the cloud-native alternative?
How does this methodology specifically enable horizontal auto-scaling?
Environment Variables & ConfigurationDocker & Containerization for Node.js
Kubernetes distinguishes liveness probes (is the process alive and not deadlocked? failing restarts the container) from readiness probes (is the instance ready for traffic right now? failing just removes it from the load balancer temporarily, without restarting), since a temporarily overloaded but otherwise healthy instance should stop receiving traffic without a needless restart.
A service that temporarily loses its database connection fails its readiness probe (removed from traffic without a disruptive restart) while still passing liveness, rejoining traffic once the connection is restored.
Likely follow-ups
What's the risk of making the liveness probe check external dependencies rather than just the process's own health?
How do you tune failureThreshold and periodSeconds to avoid both false positives and slow detection?
Docker & Containerization for Node.jsDeployment & Process Managers (PM2)
A typical pipeline includes: installing dependencies, running linters/type checks, running the test suite, building a production artifact (a Docker image), and deploying it to staging then production, often with manual approval gates or automated canary/blue-green rollout strategies for production.
name: CI
on: [push]
jobs:
test:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm ci
- run: npm run lint
- run: npm test
- run: docker build -t myapp:${{ github.sha }} .
Real-world example
A team's pipeline runs the full test suite and builds a Docker image on every pull request, blocking merges until tests pass, and auto-deploys to staging on merge with a manual approval step for production.
Likely follow-ups
What's the difference between continuous delivery and continuous deployment, given both are abbreviated CD?
How would you add a rollback mechanism in case a deployed change causes issues?
Docker & Containerization for Node.jsGit & Project Management
IaC defines cloud infrastructure in version-controlled configuration rather than manual console clicks, enabling reproducible, reviewable infrastructure changes. The AWS CDK lets teams define infrastructure using actual TypeScript/JavaScript code rather than a separate declarative language, letting a Node.js team reuse familiar tooling for infrastructure too.
A team migrating from manually configured AWS resources to the CDK captures their entire infrastructure as version-controlled TypeScript, letting infrastructure changes go through the same PR review process as application code.
Likely follow-ups
What's the tradeoff of using the CDK versus a purely declarative tool like Terraform?
How do you handle infrastructure state drift when using IaC alongside occasional manual console changes?
Horizontal scaling adds more instances behind a load balancer rather than making one instance more powerful -- this requires the application to be stateless: any instance must handle any request without depending on data that only exists on one instance, which is why session state needs a shared store like Redis and uploads need shared storage like S3.
An application that worked with a single instance started randomly logging users out after being scaled to three instances, traced to in-memory sessions, fixed by moving to Redis-backed sessions.
Likely follow-ups
How does sticky sessions at the load balancer offer a partial alternative to making the app fully stateless?
What's the difference between horizontal scaling and Node's built-in cluster module?
A load balancer sits in front of multiple instances, distributing requests according to an algorithm (round-robin, least-connections, IP-hash), improving availability (traffic routes only to healthy instances) and throughput, commonly implemented via a managed cloud load balancer or software like Nginx or HAProxy.
upstream node_app {
server 10.0.0.1:3000;
server 10.0.0.2:3000;
}
server {
listen 80;
location / { proxy_pass http://node_app; }
}
Real-world example
A production API runs three instances behind an AWS ALB configured with health checks, so a crashed instance is automatically removed from rotation until it recovers.
Likely follow-ups
How does the load balancer itself avoid becoming a single point of failure?
What's the difference between Layer 4 and Layer 7 load balancing, and when does it matter for a Node.js app?
HTTP & HTTPS ModulesDocker & Containerization for Node.js
Blue-green deployment maintains two identical environments -- the new version is deployed and tested against 'green' while 'blue' serves all live traffic, and once verified, traffic is switched instantly, with blue kept running briefly as an instant rollback target.
A payments API deploys an update to a parallel green environment, smoke-tests it while blue serves real traffic, and switches the load balancer to green only after verification passes.
Likely follow-ups
How does blue-green deployment compare to canary release in terms of risk exposure?
What's the cost implication of running two full production environments simultaneously?
Docker & Containerization for Node.jsDeployment & Process Managers (PM2)
Sensitive values (API keys, database passwords) should ideally come from a dedicated secrets manager rather than plain environment variables or files, since secrets managers provide encryption at rest, access control, and audit logging that plain environment variables typically don't.
A team migrates database credentials from a plain .env file to AWS Secrets Manager, gaining automatic credential rotation and a full audit trail of secret access.
Likely follow-ups
What's the specific security risk of environment variables versus a dedicated secrets manager?
How do you handle secret rotation without requiring a full redeploy?
Auto-scaling automatically adjusts running instance count based on demand -- common triggers include CPU utilization, memory usage, request latency, and queue depth for background-job services, since a growing backlog signals worker capacity falling behind incoming volume.
An e-commerce platform auto-scales when CPU exceeds 60% for two minutes, handling a traffic surge without manual intervention, then scales down overnight.
Likely follow-ups
Why is scale-in cooldown typically set longer than scale-out cooldown?
How does auto-scaling a stateless HTTP API differ from auto-scaling a background-job worker fleet?
Background Jobs & QueuesPerformance Optimization & Profiling
A reverse proxy forwards client requests to backend servers -- Nginx is placed in front of Node.js to handle TLS termination, serve static files directly, provide basic load balancing, and buffer slow client connections so they can't tie up limited Node.js concurrency.