Build a high-performance Node.js backend framework
Construct a complete web framework from node:net up, use no node:http anywhere, and tune every measurable cost out of the hot path.
Most Node.js frameworks begin above the connection engine and HTTP parser. This capstone removes that box. You build the layer beneath the framework - a byte-level HTTP/1.1 parser, a radix-tree router, a middleware pipeline, the full application surface, production hardening, and a hot path tuned through measurement until it becomes super blazingly fast. You build it on your own machine, one lesson at a time, and every claim is something you can reproduce.
10 of 23 chapters live · 50 lessonsThe build, chapter by chapter
Bytes on the Wire
The layer that every framework hides from you - raw TCP, and the exact bytes of one HTTP response.
A Parser That Never Allocates
Turn a socket's raw bytes into a request object by walking them one at a time. No toString, no split, and no request smuggling.
TCP Is a Byte Stream
Every toy server assumes one read is one request. TCP promises nothing of the sort. You remove that assumption, then read a body without ever swallowing the next request.
Answering Back
So far the handler answers by hand-writing socket bytes. This chapter gives it a Response object that frames every answer correctly, exactly once, and a connection that stays open for the next request in line.
The Radix Tree
The if-ladder pays for every route it did not match; replace it with a prefix-compressed tree that finds a handler in time proportional to the path, not the route count.
Params, Wildcards, and Method Semantics
The colon marker matches one segment and hands it back, the star takes the rest, and a method miss is not a path miss.
The Middleware Onion
Run ordered application, router, and route middleware before and after a handler, with explicit short-circuiting.
Errors That Don't Crash the Server
One handler failure may end one response or connection. It must not terminate the Node process.
Cookies, Redirects, and Content Negotiation
Cookies, redirects, and a response that can label its own bytes - the application surface every web app touches.
Streaming Bodies and Backpressure
Hand the handler the request before the body arrives, decode chunked framing byte by byte, and pause socket reads when a consumer falls behind.
Body Parsers and Multipart
Turn raw body bytes into structured data - JSON, forms, query strings, and multipart uploads that stream to disk.
Released to everyone when readyStreaming Responses
Chunked encoding, honest backpressure, and the one streaming spine every later feature reuses.
Released to everyone when readyStatic Files, Ranges, and Conditional Requests
Serve files without serving your filesystem - traversal defense, range requests, ETags, and the 304 flow.
Released to everyone when readyCORS and Compression
Preflights answered at the middleware layer, origins reflected with Vary discipline, and compression that pays for itself.
Released to everyone when readyServer-Sent Events, Hooks, and Validation
Live event streams over plain HTTP, lifecycle hooks with deterministic order, and validators compiled once per route.
Released to everyone when readyHardening - Limits, Slowloris, and Graceful Shutdown
Caps on everything, per-phase timeouts that starve slowloris, and a shutdown that drains instead of drops.
Released to everyone when readyMeasure First - Benchmarking Discipline and Lazy Headers
The measurement protocol every number rides on, then the first hot-path win - headers that never become strings.
Released to everyone when readyThe Write Path - Cached Date, Precomputed Buffers, One Syscall
Make the response head nearly free - a per-second date cache, prebuilt status lines, and one syscall per response.
Released to everyone when readyCompiling JSON
A schema-compiled serializer that builds the exact string a route already knows the shape of.
Released to everyone when readyHidden Classes and the Monomorphic Pipeline
Fixed object shapes, monomorphic call sites, and a middleware chain compiled once per route instead of per request.
Released to everyone when readyFeeding the GC Nothing
Pooled request contexts with full-field reset - the hot path stops allocating and the collector goes quiet.
Released to everyone when readyThe Performance Gauntlet
Four workloads, a disciplined harness, a correctness gate, and a reproducible performance report.
Released to everyone when readyEvery Core - SO_REUSEPORT and the Cluster Fallback
The same hot path on every core - kernel socket sharding where the platform has it, cluster round-robin where it does not.
Released to everyone when ready