How HTTP Request Lifecycles Work in Express and Fastify
In Node.js frameworks like Express and Fastify, an incoming HTTP request passes through a fixed sequence of steps — from TCP connection and header parsing to middleware execution, route matching, response serialization, and socket closure. Express processes requests through a flat middleware stack where each function must call next() to pass control to the next layer; failing to do so leaves the request hanging until a timeout occurs. Fastify replaces this with a named, ordered hook pipeline — onRequest through onResponse — and uses a radix trie for route matching and schema-compiled serialization for better performance. Critically, stalled requests caused by missing next() calls or incomplete hook handling produce no exceptions or error logs, surfacing only as elevated p99 latency and a growing count of ESTABLISHED sockets. Understanding this lifecycle is essential for debugging silently disappearing requests and for placing middleware in the correct order.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in