🟢 Node.js Intermediate

What is the event-driven architecture in Node.js?

Why Interviewers Ask This

Candidates at the intermediate level are expected to not only know this concept but explain the trade-offs involved. Interviewers use this question to see if you can reason about design decisions, not just recall facts.

Answer

Event-driven architecture is a design paradigm where program flow is determined by events — signals that something has happened (user action, data arrival, timer expiry). Node.js is fundamentally event-driven: rather than sequentially executing operations and blocking on I/O, it registers callbacks for events and handles them as they occur. The EventEmitter class is the backbone: components emit events and other components listen and react. This enables loose coupling — emitters do not need to know about listeners, and listeners do not need to know what triggered the event. In a Node.js HTTP server, each incoming request fires a "request" event. A readable stream fires "data" events as chunks arrive and "end" when complete. This architecture makes Node.js excellent for real-time systems, message queues, and microservices. The main challenge is that complex event flows can be hard to trace — tools like distributed tracing and careful naming of events help manage complexity.

Pro Tip

This topic has Node.js-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.