Fastify
Fastify — Node.js APIs That Handle 35,000 Requests per Second Out of the Box
Fastify
Fastify 5.0 (October 2024, requires Node.js 20+) achieves 90,000+ requests/second in benchmarks—40-80% more than Express on identical hardware. The schema-based validation and serialization pipeline eliminates JSON.stringify overhead that plagues other frameworks. With 7M+ weekly npm downloads and 33K GitHub stars, Fastify is the proven high-performance Node.js framework trusted by Microsoft, Mercurius GraphQL, and NestJS as an optional transport layer.
Build with FastifyBackend Development
Who Should Use Fastify?
Fastify is the right choice when API throughput is a measurable business constraint—payment gateways, IoT data ingestion, high-frequency trading APIs, and real-time data endpoints where request volume makes Express's overhead meaningful. Teams willing to learn Fastify's plugin model in exchange for 40-80% more throughput make the right tradeoff.
High-Throughput API Services
APIs handling 10,000+ requests/second where Express's throughput ceiling is a real constraint benefit from Fastify's performance architecture. Payment processing endpoints, notification APIs, and analytics ingestion services are where 40-80% throughput improvement translates to meaningful infrastructure cost savings.
IoT Data Ingestion
IoT backends receiving thousands of small device payloads per second benefit from Fastify's schema-based validation—each payload validates against a JSON Schema without marshaling through Zod or Joi. High connection counts with small payload sizes is exactly Fastify's optimal profile.
Microservices Requiring Performance Efficiency
Microservices where deployment cost matters—each Fastify service handles more requests per instance than Express, potentially halving the instance count required for the same load. The infrastructure cost reduction compounds across dozens of microservices.
Teams Starting New Node.js Projects
New Node.js projects in 2026 have no legacy Express dependency—starting with Fastify 5.0 gets the performance baseline from the first commit. The plugin model, while different from Express middleware, is clean and well-documented for engineers learning it fresh.
NestJS Teams Optimizing Throughput
NestJS supports Fastify as a drop-in adapter replacing Express—switching NestJS from Express to Fastify adapter closes the ~10% NestJS overhead gap with near-raw Fastify performance. We've switched NestJS applications to the Fastify adapter and measured consistent throughput improvements.
APIs with Large JSON Payloads
APIs serializing large JSON responses benefit most from Fastify's schema serialization—the response serializer generates optimized code from the schema rather than calling JSON.stringify on arbitrary objects. For responses with 100+ field objects, Fastify's serialization is 3-10x faster than Express's JSON response.
When Fastify Might Not Be the Best Choice
We believe in honest communication. Here are scenarios where alternative solutions might be more appropriate:
Teams strongly invested in Express middleware ecosystem—many Express middlewares don't have Fastify plugin equivalents and require rewriting
Simple internal APIs where Express's throughput is sufficient—Fastify's plugin model adds learning overhead not justified by simple service requirements
Applications requiring NestJS-level structure—use NestJS with Fastify adapter rather than Fastify directly for large-scale structured applications
Teams new to Node.js where Express's simpler model and larger tutorial ecosystem are more appropriate for learning
Still Not Sure?
We're here to help you find the right solution. Let's have an honest conversation about your specific needs and determine if Fastify is the right fit for your business.
Why Choose Fastify for Your Node.js API?
Fastify 5.0's JSON schema validation (via ajv) rejects malformed requests 2-5x faster than Joi or Zod middleware. Response serialization from schemas bypasses JSON.stringify—50-300% faster than Express. The plugin system provides encapsulated scope: hooks and decorators visible only to routes registered within a plugin. For APIs where throughput is a business constraint—payment endpoints, IoT ingestion, real-time data—Fastify's architecture is the correct choice.
90K+ req/sec
Benchmark Throughput
Fastify benchmarks 202540-80% faster
vs Express Throughput
Fastify vs Express benchmarks 20257M+
Weekly npm Downloads
npm registry 202633K+
GitHub Stars
GitHub 202690,000+ req/sec in benchmarks—40-80% higher throughput than Express on identical hardware, making Fastify one of the fastest Node.js HTTP frameworks available
Schema-based JSON serialization bypasses JSON.stringify entirely—response serialization is 50-300% faster than Express, meaningful for APIs sending large JSON payloads at high volume
Fastify 5.0 requires Node.js 20+—aligning with Node.js LTS schedule and enabling modern V8 optimizations that improve throughput further
Plugin encapsulation provides true scope isolation: hooks, decorators, and route handlers registered within a plugin are invisible to routes outside it—preventing plugin namespace pollution
Built-in TypeScript support without @types packages—Fastify's type system is built in, providing typed request/response schemas that sync with JSON Schema validators
NestJS uses Fastify as an optional adapter, Microsoft uses Fastify in Azure SDK examples—production adoption at scale validates the framework's reliability
Lifecycle hooks (onRequest, preValidation, preHandler, onSend, onResponse) provide granular request pipeline control without Express's linear middleware model
Fastify in Practice
Payment and Transaction APIs
Payment endpoints receiving high burst traffic—checkout flows during sales, subscription billing events, refund processing—benefit from Fastify's throughput. Schema-based validation ensures request structure is correct before any business logic runs. We've built Fastify payment APIs processing 50,000+ transactions/hour with consistent sub-20ms response times.
Example: Payment gateway: Fastify 5.0 + Stripe webhooks, 50K transactions/hr, sub-20ms p95
IoT Telemetry Ingestion
IoT backends receiving sensor data from thousands of connected devices benefit from Fastify's throughput and schema validation. Each device message validates against a JSON Schema without Zod overhead. We've built Fastify IoT ingestion services handling 1M+ device events/day on two-instance deployments.
Example: IoT telemetry API: Fastify, 1M events/day, JSON Schema validation, InfluxDB write
Real-Time Analytics Endpoints
Analytics APIs receiving events from frontend clients (clicks, impressions, conversions) benefit from Fastify's high connection concurrency. Request validation ensures event schema compliance; async processing via queues keeps response times low. We've built Fastify analytics ingestion at 500,000+ events/hour on minimal infrastructure.
Example: Event ingestion: Fastify + Kafka write, 500K events/hr, schema validation, <5ms p99
GraphQL APIs with Mercurius
Mercurius is the high-performance GraphQL server built on Fastify. We've built Fastify + Mercurius GraphQL APIs where the combination outperforms Apollo Server on Express by 2-3x in throughput benchmarks. Mercurius integrates with Fastify's plugin system natively.
Example: GraphQL API: Fastify + Mercurius, 2x Apollo throughput, DataLoader batching, schema-first
NestJS Fastify Adapter
NestJS applications switching from Express to Fastify adapter gain significant throughput improvements while keeping NestJS's module/DI/decorator architecture. The adapter is production-stable and supported by the NestJS team. We've migrated NestJS applications to the Fastify adapter and measured 30-50% throughput improvement on identical hardware.
Example: NestJS API: Express → Fastify adapter, 40% throughput increase, zero application code changes
File Upload and Processing APIs
File upload APIs handling document processing, image optimization, or data import benefit from Fastify's @fastify/multipart plugin. Schema-based content-type validation ensures correct request format. We've built Fastify file processing APIs that handle concurrent uploads efficiently without blocking the event loop.
Example: Document upload API: Fastify + @fastify/multipart, concurrent processing, S3 upload
Fastify Pros and Cons
Every technology has its strengths and limitations. Here's an honest assessment to help you make an informed decision.
Advantages
Benchmark-Leading Node.js Throughput
90,000+ req/sec positions Fastify among the fastest Node.js HTTP frameworks. The 40-80% throughput advantage over Express is consistent across benchmark suites and real-world measurements. For APIs where Node.js is the bottleneck, Fastify is the highest-impact single change.
Schema Serialization Is Structurally Fast
Fastify generates optimized serialization code from JSON Schemas at startup—no runtime JSON.stringify path. For API endpoints sending large objects, the serialization improvement is substantial: 3-10x faster than Express JSON responses. This advantage compounds at high request volumes.
Plugin Encapsulation Prevents Namespace Pollution
Fastify plugins have isolated scope—hooks, decorators, and routes registered within a plugin are not visible to routes outside it. This encapsulation prevents the global middleware pollution that plagues large Express applications where middleware order and scope aren't obvious.
Built-In TypeScript Without @types
Fastify's TypeScript definitions are maintained in the main repository, not via DefinitelyTyped. Route handler types infer request/reply shapes from JSON Schema definitions. Generic type parameters on routes produce typed request bodies without manual assertions.
Limitations
Plugin Model Different From Express Middleware
Express's middleware model (req, res, next) is immediately intuitive to most Node.js developers. Fastify's plugin system (fastify.register(plugin)) with lifecycle hooks (onRequest, preHandler, onSend) requires learning a different request pipeline model. Migration from Express requires rewriting middleware as Fastify plugins.
We provide Fastify plugin architecture training for teams migrating from Express. Most common Express middleware (CORS, auth, logging) have well-maintained Fastify plugin equivalents in @fastify/*. We evaluate plugin availability before committing to Fastify for projects with specific middleware dependencies.
Smaller Ecosystem Than Express
Express has 55M+ weekly downloads vs Fastify's 7M—roughly 8x the community size. Some third-party integrations are Express-first with Fastify support added later or not at all.
The @fastify/* official plugin namespace covers the most common needs (cors, jwt, multipart, static, swagger). For Express-only libraries, we evaluate wrapping via fastify-plugin() and test compatibility before production use.
Fastify Alternatives & Comparisons
We use all of these in production — the right choice depends on your project's constraints, team familiarity, and scale requirements.
Fastify vs Express.js
Learn More About Express.jsExpress.js Advantages
- •55M+ weekly downloads—8x Fastify's community and ecosystem
- •Simpler mental model: req/res/next middleware is immediately intuitive
- •More tutorials, more Stack Overflow answers, more middleware packages
- •Express 5.0 adds native async error handling—closes the main Express gap
Express.js Limitations
- •40-80% lower throughput than Fastify on equivalent hardware
- •No built-in request validation—requires Joi, Zod, or express-validator middleware
- •JSON.stringify serialization is slower than Fastify's schema-based approach
- •No plugin encapsulation—middleware order and scope are global and implicit
Express.js is Best For:
- •Teams where Express ecosystem compatibility is critical
- •Simple APIs where throughput is not a constraint
- •Teams with strong existing Express expertise
When to Choose Express.js
Choose Express when ecosystem breadth, team familiarity, or existing middleware dependencies matter more than throughput. Choose Fastify when 40-80% more throughput is measurably valuable and the team can adopt Fastify's plugin model.
Fastify vs NestJS
Learn More About NestJSNestJS Advantages
- •Angular-style architecture scales to large teams—DI, modules, decorators
- •First-class microservices (Kafka, RabbitMQ, NATS) without custom integration
- •Built-in GraphQL, WebSockets, and OpenAPI generation
- •NestJS can use Fastify as its underlying adapter—combining both
NestJS Limitations
- •~10% overhead vs raw Express/Fastify from DI container
- •More boilerplate per feature than Fastify
- •Steeper learning curve than Fastify's focused API
- •Not needed for simple services that don't require NestJS's architecture
NestJS is Best For:
- •Large teams needing enforced architectural conventions
- •Applications requiring microservices transports
- •Teams with Angular background
When to Choose NestJS
Use NestJS with Fastify adapter when you need NestJS's architecture at Fastify's performance. Use Fastify directly for focused high-throughput services that don't need NestJS's module/DI system overhead.
Why Choose Code24x7 for Fastify Development?
We've built Fastify APIs from Fastify 3.x through Fastify 5.0—through the Node.js 20 requirement change, the TypeScript integration improvements, and the @fastify/* plugin ecosystem maturation. We know Fastify's performance model requires correct implementation: JSON Schemas must be defined correctly for serialization to be faster than JSON.stringify (a wrong schema falls back to generic serialization), plugin scoping must be intentional, and lifecycle hooks must be registered at the correct scope. We also implement Fastify with the observability infrastructure that Express projects often lack.
JSON Schema Design for Performance
We define JSON Schemas for every Fastify route's request body, query parameters, and response shapes. Correct schemas enable Fastify's serialization fast path. We use fluent-json-schema or TypeBox for type-safe schema generation that produces both JSON Schema and TypeScript types from one definition.
Plugin Architecture
Fastify plugins structured with fastify-plugin() for shared decorators and encapsulated plugins for scoped routes. Authentication hooks registered at the appropriate plugin scope—not globally. We design Fastify plugin trees that make clear which routes share which decorators and lifecycle hooks.
TypeScript Integration
TypeBox or JSON Schema with type provider for route handler TypeScript inference. Typed request/reply objects without manual assertions. We configure Fastify's @types setup and TypeBox schemas so route handlers have full TypeScript inference for request body, query, params, and response shapes.
Database Integration
Prisma ORM in a Fastify plugin with request-scoped database access. @fastify/postgres for PostgreSQL pools. Connection pool size configured for Fastify's concurrency profile. We monitor query times in Fastify's onResponse lifecycle hook and surface slow queries before they affect throughput.
Authentication and Rate Limiting
@fastify/jwt for JWT authentication in a preHandler hook. @fastify/rate-limit per-route and global rate limiting with Redis backend for distributed deployments. API key authentication via custom preValidation hooks. Authentication errors return consistent RFC 7807 problem detail responses.
Performance Benchmarking
We benchmark Fastify APIs before delivery—using autocannon or k6 to validate throughput claims against production-equivalent infrastructure. We configure pino logger (Fastify's built-in logger) with JSON output for structured logging without synchronous I/O overhead, which is Fastify's recommended logging approach.
Technologies That Pair With This in Production
Services That Use This Technology
Questions from Developers and Teams
Fastify 5.0 (October 2024) drops Node.js 18 support—Node.js 20+ is now required. This aligns Fastify with Node.js LTS support windows and enables V8 engine optimizations available in newer versions. TypeScript types improved, plugin type inference enhanced, and several internal performance improvements. For teams on Node.js 20+, upgrading to Fastify 5 is recommended.
Fastify achieves 90,000+ req/sec vs Express's approximately 55,000-60,000 req/sec in standard HTTP benchmarks—a 40-80% advantage depending on workload. The difference is most pronounced for JSON APIs where Fastify's schema serialization bypasses JSON.stringify. For large JSON responses, Fastify's serialization advantage can be 3-10x faster than Express.
Fastify plugins are encapsulated modules registered via fastify.register(plugin). Each plugin has its own scope—decorators, hooks, and routes registered within a plugin are invisible to routes outside it. fastify-plugin() breaks encapsulation when you need to share a decorator globally. This model prevents the global middleware pollution common in Express applications.
Yes—Fastify has built-in TypeScript support without @types. The recommended approach uses TypeBox or JSON Schema with a type provider to generate both JSON validation schemas and TypeScript types from the same definition. Route handlers infer request body, query, and params types from the schema—no manual type assertions needed.
Yes—NestJS supports Fastify as a drop-in adapter via NestFastifyApplication. Switching is a two-line change in the bootstrap file. The NestJS module/DI/decorator architecture stays identical; only the underlying HTTP layer changes. Teams typically see 30-50% throughput improvement after the switch with no application code changes.
Fastify development cost depends on API complexity, whether you're migrating from Express or starting fresh, plugin ecosystem requirements, and integration scope. Share your requirements for an accurate assessment. Starting new projects with Fastify vs Express has minimal cost difference; migrating Express applications requires rewriting middleware as Fastify plugins.
@fastify/jwt handles JWT token authentication via a preHandler hook. The hook validates the JWT signature, decodes the payload, and attaches the decoded user to request.user. @fastify/auth enables composing multiple authentication strategies. API key authentication is a custom preValidation hook that checks headers against a key store.
Mercurius is a high-performance GraphQL server built on Fastify. It integrates natively with Fastify's plugin system, achieving 2-3x higher throughput than Apollo Server on Express in benchmarks. Mercurius supports JIT compilation, subscriptions, federation, and batching. For teams building GraphQL APIs on Node.js where performance matters, Fastify + Mercurius is the highest-performance option.
Not via drop-in replacement—Fastify's plugin model is different from Express middleware. Migration requires rewriting Express middleware as Fastify plugins/hooks. For existing Express applications, evaluate whether the throughput improvement justifies the rewrite cost. For new service boundaries, start with Fastify directly.
Fastify version upgrades (Fastify 5 dropped Node.js 18; future versions may have similar requirements), @fastify/* plugin updates, performance profiling as API load grows, and feature additions following Fastify's plugin model.
Still have questions?
Contact Us
What Makes Code24x7 Different
Fastify's performance benefits require correct implementation—especially JSON Schema design for serialization. A Fastify application with incorrectly defined schemas or global hooks that should be scoped doesn't realize the framework's performance model. We implement Fastify with performance measurement from day one, validating throughput improvements against production-equivalent load before delivery.