Senior Node.js Developer Interview Questions: Advanced Topics and Answers

Senior Node.js developer interview questions and answers: event loop, worker threads, backpressure, leaks, BFFs, type stripping, containers and load testing.
作者
GreatFrontEnd Team
20 分钟阅读
Oct 21, 2026
Senior Node.js Developer Interview Questions: Advanced Topics and Answers

Senior Node.js developer interview questions rarely test whether you know async/await syntax or how to wire up an Express route. At senior level, the questions shift to platform internals: what actually happens inside the event loop on a given tick, when a native concurrency primitive like worker_threads is the right call versus cluster, how a stream behaves under backpressure, and how you'd diagnose a memory leak or event-loop stall in a running production process. The questions below focus on that platform-level reasoning, with a worked answer for each.

Questions 9 to 13 move from the runtime to the decisions around a Node service that a senior engineer is often expected to own: whether a frontend team should run a backend-for-frontend, whether to drop the TypeScript build step, how to containerize the service, how to load test it, and how to keep the API and its frontend consumers from breaking each other.

What separates senior from mid-level Node.js candidates

A mid-level candidate can write correct async code, use npm and set up basic Express routing. A senior candidate is expected to reason about Node.js as a runtime: what the event loop is actually doing at each phase, which concurrency primitive fits a specific bottleneck (CPU-bound work versus I/O-bound scaling versus running an external program), and how to diagnose a real production incident, a memory leak or an unresponsive server, rather than describe these things in the abstract.

Question 1: Walk through the phases of the Node.js event loop, and where do microtasks fit in?

How to approach it

The event loop moves through several libuv phases: timers, pending callbacks, idle/prepare (internal), poll, check, and close callbacks. Since Node.js 20, timers are run after the poll phase rather than both before and after it. setTimeout and setInterval callbacks become eligible to run once their delay threshold has elapsed. The poll phase retrieves new I/O events and executes their callbacks, while setImmediate() callbacks run in the check phase after poll. This is why a setImmediate() and a zero-delay setTimeout() can run in different orders depending on where they're scheduled.

The detail that actually separates a senior answer is where process.nextTick() and microtasks fit. After the current JavaScript operation completes, Node processes the process.nextTick() queue before V8's microtask queue, which includes Promise callbacks and queueMicrotask(). These queues are not simply processed once at the end of an event-loop tick. A recursive chain of process.nextTick() calls can starve I/O because Node keeps processing newly queued callbacks before returning control to the event loop, a real, checkable failure mode rather than trivia.

Question 2: When would you reach for worker_threads instead of cluster or child_process?

How to approach it

These solve three different problems, and reaching for the wrong one is the most common trap in this question.

worker_threads runs JavaScript in parallel within the same Node.js process, generally with lower overhead than spawning full processes. Workers can share memory using SharedArrayBuffer, or avoid copying some data by transferring ownership of ArrayBuffers. They're a good choice for CPU-bound work such as image processing, encryption, or large computations that would otherwise block the main thread's event loop.

cluster creates multiple Node.js worker processes that can share a server port, with each process having its own event loop, memory space, and V8 instance. It can be useful when you specifically want multiple isolated Node.js processes handling incoming connections across CPU cores, although modern deployments often achieve the same process-level scaling through multiple application or container instances.

child_process is the general-purpose API for spawning other processes, whether that's another Node.js process or an arbitrary external program. Full processes generally have greater startup and memory overhead than worker threads, but they provide process isolation. It's the right tool when you need to run an external command, script, or separate process rather than parallelize JavaScript inside the same Node.js process.

The trap is assuming that adding worker threads automatically makes an I/O-bound server handle more concurrent requests. Node's event loop already provides high I/O concurrency, so worker threads are primarily useful when CPU-heavy JavaScript is blocking request processing. If the goal is instead to run multiple isolated server processes across CPU cores, cluster or process-level scaling through multiple application instances is usually the better fit.

Question 3: What is backpressure in Node.js streams, and how do you handle it correctly?

How to approach it

Backpressure happens when a readable stream produces data faster than a writable stream can consume it. .pipe() handles this automatically, which is exactly why most application code never has to think about it directly.

Writing manually is where the mechanism becomes visible:

const canContinue = writableStream.write(chunk);
if (!canContinue) {
// internal buffer exceeded highWaterMark, pause until drained
readableStream.pause();
writableStream.once('drain', () => {
readableStream.resume();
});
}

writable.write() returns false when the amount of buffered data reaches or exceeds the stream's highWaterMark. Ignoring that return value and continuing to write anyway is the actual bug: unhandled backpressure buffers data in memory with nowhere to drain it, until the process runs out of memory and crashes. This is a specific, reproducible failure mode, not an abstract performance concern, which is why interviewers use it to check whether a candidate has actually worked with raw streams or only ever used .pipe().

Question 4: How would you diagnose a memory leak in a running Node.js process?

How to approach it

Start with the actual tool, not the theory. Running the process with --inspect and taking heap snapshots at intervals through Chrome DevTools or a tool like clinic.js lets you compare retained memory over time and see which object types are accumulating.

The common root causes worth naming specifically: an unbounded in-memory cache that never evicts entries, event listeners registered on a long-lived emitter (like a shared database client) that are never removed when the subscribing object should be garbage collected, and closures that unintentionally hold a reference to a large object, keeping it alive far longer than intended.

A senior-level answer connects the diagnosis to the fix: for a cache, add an eviction policy or a WeakMap where the key's lifetime should govern the cache entry's lifetime; for listeners, explicitly call .removeListener() or .off() when the subscribing object is done; for closures, restructure so the closure only captures what it actually needs, not the entire enclosing scope. Naming the tool without connecting it to a specific class of leak is the shallow version of this answer.

Question 5: How does AsyncLocalStorage help with request-scoped context, and what's the trade-off?

How to approach it

AsyncLocalStorage carries context, a request ID, the authenticated user, a trace ID, through an async call chain without threading it explicitly through every function's parameters. This solves the practical problem of "prop drilling" in a request-handling codebase: without it, every function between the HTTP handler and a deeply nested logging call would need an extra parameter just to pass the request ID along.

A common pattern is to establish request-scoped context with asyncLocalStorage.run(context, callback) near the start of request handling, so asynchronous work created within that callback can access the same store. Node's diagnostics_channel module is a separate but complementary observability API that allows instrumentation code to subscribe to structured lifecycle events without tightly coupling itself to application logic.

The trade-off worth naming honestly: AsyncLocalStorage does carry a real, measurable performance overhead, since it has to track context across every async boundary, not just the ones you care about. For most request-handling code the overhead is small relative to actual I/O latency, but it is not free, and a senior answer should be able to say that rather than presenting it as a costless convenience.

Question 6: How do you implement a graceful shutdown for a Node.js HTTP server?

How to approach it

On receiving SIGTERM, the server should stop accepting new connections, server.close() does this, while letting in-flight requests finish within a bounded window, then close database and other connection pools before the process exits.

This is directly tied to how container orchestration actually works, not a theoretical concern: during termination, Kubernetes normally sends SIGTERM and allows the process a configured grace period before forcefully terminating anything that is still running. Without graceful-shutdown handling, a Node.js process may exit while requests are still in flight, producing intermittent failures during deploys or scale-down events. A senior answer connects the code (server.close(), draining in-flight work, closing pools) to this operational trigger rather than describing graceful shutdown as an abstract best practice.

Question 7: What changed in Node.js's release model in 2026, and why does it matter for choosing a version in production?

How to approach it

Node.js 26 enters Active LTS on October 28, 2026, replacing Node.js 24 ("Krypton") as the Active LTS line. Node.js 24 moved into Maintenance LTS on October 20, 2026, joining Node.js 22 ("Jod"). These release statuses matter when choosing a supported Node.js version for production.

The genuinely current platform fact worth being able to discuss: starting with Node.js 27 in April 2027, the release model changes from two major releases a year to one. Every release becomes LTS, removing the old odd/even distinction, with a new six-month Alpha phase preceding each annual Current phase. The stated reason is that odd-numbered releases saw minimal real-world adoption, since most production teams only ever moved to LTS versions anyway, and maintaining security releases across four or five simultaneously active lines had become difficult for the project to sustain.

The senior-level point isn't memorizing version numbers, it's the underlying judgment: production applications should generally run on an Active or Maintenance LTS release rather than Current, and being able to say why (a Current release exists specifically to let library authors add support before the wider ecosystem depends on it) is what separates an answer that names a version from one that understands what the version status actually means operationally.

Question 8: How do you detect and prevent the event loop from being blocked by synchronous code?

How to approach it

Node's own perf_hooks.monitorEventLoopDelay() measures event-loop lag directly, the time between when a callback should have run and when it actually did, which is the concrete signal a blocked or overloaded event loop produces. This is a genuinely different signal from slow downstream I/O. A slow or overloaded database can increase the latency of many requests while the Node.js event loop remains healthy. Elevated event-loop delay instead tells you that JavaScript callbacks themselves are not getting scheduled promptly, which commonly points to CPU-heavy synchronous work or an overloaded process.

Common causes worth naming specifically: heavy synchronous JSON parsing or serialization on large payloads, synchronous cryptographic operations (crypto.pbkdf2Sync instead of the async variant), and large synchronous loops over in-memory data. The fix connects back to Question 2. CPU-bound work can either be partitioned into small chunks that periodically yield control back to the event loop, or offloaded to worker threads. Partitioning can keep the main thread responsive for bounded computations, while worker threads are a better fit for substantial CPU-heavy work where parallel execution justifies the additional communication and coordination overhead.

Question 9: When should a frontend team own a backend-for-frontend in Node, and when is it a mistake?

How to approach it

A backend for frontend (BFF) is a separate backend service for each frontend interface, instead of one general-purpose backend for all of them. That definition is from Microsoft's Backends for Frontends pattern guidance, and Sam Newman, who named the pattern, describes it as one backend per user experience in his original write-up, usually maintained by the same team as the UI.

The benefits listed in the Microsoft guidance are that each backend is tailored to its client, the frontend team controls its own release cadence, failures are contained per client, and security can be customized per client. The costs are named just as plainly: more services to operate, an extra network hop, and code duplication, which the page calls a probable outcome.

The senior part is knowing when not to build one. Microsoft's guidance lists cases where the pattern is a poor fit: when interfaces make the same or similar requests to the backend, or when only one interface talks to the backend. Newman is similarly conditional for a web-only product, saying a BFF only makes sense when there is a significant amount of server-side aggregation required. And when GraphQL with frontend-specific resolvers is already in place, the Microsoft page says a BFF might not add value.

Two things to say about ownership. A BFF should primarily handle client-specific logic. Cross-cutting concerns such as authentication, authorization, rate limiting, and logging should be shared or centralized where appropriate, rather than duplicated across BFF services. And a BFF owned by the frontend team means that team now carries on-call for a Node service, which is a staffing decision, not only an architecture one.

Question 10: Node can run TypeScript files directly now. Do you drop the build step?

How to approach it

The accurate answer depends on versions. Per the Node.js TypeScript documentation, type stripping was enabled by default in v23.6.0 and v22.18.0, and was declared stable in v25.2.0 and v24.12.0. In v26.0.0 the --experimental-transform-types flag was removed.

The important word is "stripping". Node replaces TypeScript syntax with whitespace and performs no type checking, so a type error does not stop the program from running. That has a direct consequence for a senior engineer: CI must still run tsc --noEmit, because Node will happily execute code that does not type check.

A second consequence is that only erasable syntax works. The documentation says Node only removes inline types, so enum declarations, namespaces with runtime code, parameter properties and import aliases are not supported by stripping. Code written in the style of a decorator-heavy framework will need changes. TypeScript 5.8 added the erasableSyntaxOnly option, announced on 28 February 2025, which makes the compiler report exactly those constructs, so the editor warns before Node fails at runtime.

Other rules from the same page: relative imports must include the .ts file extension, Node ignores tsconfig.json (so path aliases are not resolved), and Node refuses to process TypeScript files under node_modules, which the documentation says is meant to discourage publishing packages as TypeScript source.

So the senior answer is: for an application service whose code is already erasable-syntax-only, dropping the build step is reasonable and removes a moving part. For a library, for code that uses enums or path aliases, or for anything needing .tsx, keep a build step. Either way, keep the type check in CI.

Question 11: What do you decide when containerizing a Node service?

How to approach it

Most of the decisions are documented in the official docker-node best practices, so cite them instead of inventing a checklist.

  • Run as a non-root user. The images provide a node user with uid 1000 for this purpose, selected with USER 1000 in the Dockerfile, in line with the principle of least privilege.
  • Handle signals. The document says Node.js was not designed to run as PID 1, and that a Node process running as PID 1 will not respond to SIGINT and similar signals by default. Its fixes are docker run --init or adding Tini in the image.
  • Start with node, not npm. Put CMD ["node", "index.js"] in the image so exit signals reach Node and are not swallowed by npm.
  • Choose the base image deliberately. The README warns that Alpine images use musl libc and that applications written for Debian, which uses glibc, will not generally run under Alpine. It describes the slim variant as minimal and recommends the default image unless you have space constraints.

Be careful with NODE_ENV=production. Node itself does not change behavior. The effect comes from libraries: per Express's performance best practices, it caches view templates and CSS and generates less verbose error messages, and npm's omit setting defaults to dev when it is set, per the npm audit documentation. The Express page also quotes a third-party test claiming a threefold improvement, which is old and specific to workloads that render views, so do not repeat the figure as a general promise.

Senior-level additions: set a container memory limit, pin the image by version or digest so a rebuild is reproducible, and keep the image free of build tools by using a multi-stage build.

Question 12: How do you decide a Node service is fast enough, and how do you load test it?

How to approach it

Start with what to measure. Averages hide the cases users complain about. The Google SRE book's chapter on monitoring distributed systems gives the example of a service with a 100 ms average latency at 1,000 requests per second where 1 percent of requests might easily take 5 seconds, and notes that the 99th percentile of one backend can become the median response of the frontend that calls it. So the targets should be percentile-based, such as p95 under a stated number.

Then name a load testing tool and what it should enforce. k6 thresholds are pass or fail criteria on metrics, for example http_req_failed: ['rate<0.01'] and http_req_duration: ['p(95)<200'], and a failed threshold makes k6 exit with a non-zero code, so a load test can gate a pipeline. autocannon, a Node-based HTTP benchmarking tool, is a lighter option for a quick check.

Know the measurement trap. A load generator that waits for each response before sending the next request understates tail latency when the server stalls, a problem called coordinated omission. The autocannon README says that when a rate option is used its latency data is corrected for this, and links to Gil Tene's talk on the subject.

For finding where time goes, Node provides --cpu-prof, which writes a .cpuprofile file on exit, per the CLI documentation, and perf_hooks.monitorEventLoopDelay(), which returns a histogram of event loop delay in nanoseconds with a percentile() method, per the perf_hooks documentation. Exporting that histogram as a metric is a cheap way to see saturation early.

The senior part: load test against an environment shaped like production, with realistic data volumes, and write down the expected capacity so a regression has something to be compared against.

Question 13: How do you keep a Node API and its frontend consumers from breaking each other?

How to approach it

Make the contract explicit and checked automatically. There are two complementary tools, and the interview point is that they answer different questions.

A schema-first contract. OpenAPI 3.1 defines its schema objects as a superset of JSON Schema Draft 2020-12, per the 3.1.0 specification. The specification index also lists version 3.2, with 3.2.0 dated 19 September 2025, so state which version your tooling supports. From a schema you can generate frontend types: the documentation for the openapi-typescript package covers OpenAPI 3.0 and 3.1 and generates runtime-free types. And you can diff versions in CI: oasdiff has an oasdiff breaking command, and defines a breaking change as one where a previously valid request can now be rejected or a response can now carry something clients were not written to handle.

Consumer-driven contracts. The Pact documentation describes a contract generated from the consumer's automated tests, so provider behavior that no consumer uses is free to change without breaking tests. Unlike a schema, it is contract by example.

A spec diff checks the whole described surface and will flag a change nobody calls. A consumer contract checks only what is used and will miss a consumer that has not written a test. Choosing one or both depends on how many consumers you have and whether you control them. For a public API with unknown clients, a spec diff is the safer gate. For a few internal frontends, consumer contracts give faster, more precise feedback.

Add a process point: breaking changes are not forbidden, they are scheduled. Deprecate, give consumers a window, then remove.

Common mistakes and red flags at the senior level

Reaching for worker_threads simply because a server needs to handle more concurrent I/O is a common concurrency-model mistake at this level; workers are most useful when CPU-heavy JavaScript is the actual bottleneck. Ignoring the return value of writable.write() and never handling the 'drain' event is the same category of mistake for streams, code that works in testing and fails only under real load. Presenting AsyncLocalStorage or graceful shutdown as costless best practices, rather than naming their actual trade-offs and operational triggers, reads as memorized rather than understood. Naming a diagnostic tool (heap snapshots, --inspect) without being able to connect it to a specific class of leak is the shallow version of the memory-leak question.

Frequently asked questions

Is Node.js actually single-threaded? JavaScript execution in Node.js runs on a single thread, but libuv maintains a thread pool underneath for certain operations (some file system calls, DNS lookups, and a few crypto functions), and worker_threads adds genuine parallel JavaScript execution on top of that. "Single-threaded" describes the JavaScript execution model, not the whole runtime.

Do I need worker_threads for a typical CRUD API? Usually not. A typical CRUD API is I/O-bound (database calls, network requests), which Node's event loop already handles well without additional threads. worker_threads earns its complexity specifically when there's real CPU-bound work blocking the main thread.

How current does my Node.js version knowledge need to be for an interview? Knowing which release line is Active LTS conceptually, and why production code should stay on LTS, matters more than memorizing exact version numbers or release dates, since those change on a predictable schedule.

Is this the same material as a general backend system-design interview? No. System-design rounds test how you'd architect a distributed system across services; this guide covers Node.js-specific runtime internals, the event loop, concurrency primitives, streams, that apply regardless of the broader architecture you're asked to design.

How to prepare

Work through the mechanics above with a real scenario attached, not just the definitions: given a slow endpoint, would you check for a CPU-bound bottleneck or event-loop lag first, and how would you tell the difference. Practicing the diagnosis questions (memory leaks, event-loop lag) by actually running --inspect against a small reproduction is worth more than reading about the tools, since a senior round is more likely to describe a symptom and ask how you'd investigate it than to ask you to define a term.

If you're also preparing frontend-adjacent rounds, GreatFrontEnd's Next.js interview questions guide covers the framework layer that runs on top of Node.js in a full-stack interview, and the reasoning behind senior-level trade-off questions in other domains carries over even though the specific APIs differ.

Conclusion

Senior Node.js developer interview questions test whether you can reason about the runtime itself, not whether you can write correct async code. The event loop's actual phase-by-phase behavior, the right concurrency primitive for a specific bottleneck, stream backpressure mechanics, and real production diagnosis are the actual differentiators. What separates a senior answer is connecting each mechanism to a concrete failure mode or operational trigger, rather than describing it as an abstract best practice. The later questions add the operating decisions around a service: when a backend-for-frontend is worth owning, what type stripping does and does not check, how a container should run Node, how to set percentile-based performance targets, and how to keep an API contract from breaking its consumers.

相关文章

Next.js Interview Questions for Experienced Developers: Mid to Senior (2026)Prepare for mid-level and senior Next.js interviews in 2026 with advanced questions on App Router, Server Components, rendering, caching, auth, migration, and deployment.
Data Structures Interview Questions for Senior Frontend EngineersIf you are researching senior data structures developer interview questions, the first thing worth knowing is that the question set looks less like a general SWE algorithms round and more like it was built around the browser.