Spindle: A New Type-Safe Web Framework for OCaml 5
The OCaml ecosystem has gained a powerful new tool with the introduction of Spindle, a web framework designed from the ground up to leverage the multicore capabilities of OCaml 5. Built natively on Eio, Spindle aims to bridge the gap between high-level expressive APIs and the rigorous safety requirements of modern web development.
At its core, Spindle is driven by a type-first philosophy. The framework is designed to derive essential components automatically, including codecs, request validation, and OpenAPI specifications. Furthermore, it supports frontend schema generation for tools like Zod and Melange. This capability ensures that the contract between the server and the client remains perfectly synchronized, eliminating the tedious and error-prone process of maintaining separate definitions for different parts of the stack.
Beyond its type-safety features, Spindle provides a comprehensive suite of tools required for modern production environments. It includes an RFC-strict HTTP server, support for WebSockets and Server-Sent Events (SSE), and high-level primitives specifically designed for building Model Context Protocol (MCP) servers. For observability, the framework integrates distributed tracing, OpenTelemetry-compatible metrics, and robust logging, ensuring that developers have the necessary visibility into their applications.
While the creators of Spindle emphasize that raw performance was not their primary design goal, the framework has demonstrated impressive results in preliminary benchmarks. It reportedly runs twice as fast as NestJS and five times faster than FastAPI on a single core, suggesting that the focus on type-driven development does not come at the expense of efficiency. By offering a multicore-native architecture, Spindle positions itself as a compelling choice for developers looking to build scalable, type-safe web services in OCaml. Documentation and further details are currently available through the project’s official GitHub pages. Sources: Hacker News
Aggregated summary. Original: Hacker News