Interview reasoning
Prerequisite: node-debugging-portfolio. Objective: Explain event loop and system trade-offs. Each example is independent. Use Node.js 22.16.0 in a disposable directory; save as main.mjs and run node main.mjs. No external service is contacted.
How it works
Node can overlap asynchronous I/O while JavaScript executes within an isolate. CPU-intensive synchronous work still delays other callbacks on that isolate. Streams with bounded buffering reduce uncontrolled accumulation, but backpressure must be propagated. For service design, compare transactional requirements, timeout budgets, idempotency and operational complexity. Give a clear answer, then describe one counterexample and one practical test.
Explain promise versus timer ordering
const events=[];setTimeout(()=>{events.push('timer');console.log(events.join(','));},0);Promise.resolve().then(()=>events.push('promise'));events.push('sync');Expected output:
sync,promise,timerFor this top-level fixture, synchronous work occurs before the promise reaction and timer.
Explain retry ambiguity
const seen=new Set();function apply(id){if(seen.has(id))return 'duplicate';seen.add(id);return 'applied';}console.log(apply('order-1'),apply('order-1'));Expected output:
applied duplicateAn in-memory key prevents a repeated effect within this process only.
Common mistake
Do not generalize one timer ordering example to every event-loop context or claim memory-only deduplication survives restarts.
Practice
Explain how you would replace the in-memory set with a durable idempotency contract, including what happens if a response is lost.
Reference candidate: node-interview-reasoning-lookup (route unverified). Original instructional model; independent source review pending.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Interview reasoning — knowledge check
Apply the lesson to a fresh scenario and explain the evidence boundary.
Can synchronous CPU work delay timers?
What does the in-memory set lose on restart?
How should you support a performance claim?