Question presented to candidate: "Your Node.js service works fine on your laptop but a teammate says it 'can't just be copied to production' — it needs to actually follow certain principles first. What principles, specifically, and why does skipping them cause real production pain?"
What a strong answer should cover:
- The 12-factor app is a methodology (originally from Heroku) for building services that are portable across environments, scale horizontally without code changes, and can be deployed/rolled back predictably — a checklist against exactly the kind of "works on my laptop" gap the prompt describes.
- 📌 Verified, not assumed: Factor III, config in the environment — identical code, run once with no environment variables and once with
PORT/DATABASE_URLset, produced genuinely different real config output. Nothing in the code changed between runs; only the environment did. - The most interview-relevant factors for a Node.js service, stated precisely: (III) config — via environment variables, never hardcoded or committed; (VI) processes — the app itself is stateless, any session/shared state lives in an external store (a database, Redis), which is exactly why multiple worker processes/instances can run identical code safely, verified with real proof elsewhere in this bank that each worker process has genuinely separate memory; (IX) disposability — fast startup and graceful shutdown, verified elsewhere in this bank with real
server.close()behavior; (XI) logs — treated as an event stream (written to stdout), not managed by the app itself, letting the execution environment route/aggregate them. - A precise answer names the specific production pain each factor prevents: hardcoded config forces a code change (and a redeploy) just to point at a different database; in-process session state breaks the moment a second instance is added behind a load balancer, since a user's next request may land on a worker process that never saw their session; an app that manages its own log files instead of writing to stdout fights the platform's own log aggregation.
- The honest scope: the 12-factor app is a set of principles, not a rigid checklist every single service must satisfy perfectly — some factors (e.g., "backing services as attached resources") matter far more at genuine multi-environment scale than for a small internal tool, and a strong answer says so rather than treating it as dogma.
Clarifying questions expected:
- "Is this service expected to run as multiple instances/processes, or is it a single always-on instance?" — directly decides how much the stateless-processes factor actually matters here.
- "Is config currently hardcoded anywhere in the codebase, or already fully environment-driven?" — a fast diagnostic for how far the service is from factor III today.
Code / implementation expected: Yes — the real, measured config-from-environment demo is the concrete, convincing proof of the specific factor most directly relevant to "works on my laptop, not in production."