Middleware runs before a request is completed (often at the edge) and is great for redirects, rewrites, and auth gating. Limitations: it runs in an Edge‑like runtime (no Node‑specific APIs), should be fast, and is not a place for heavy DB access.