Skip to content

The @Fast Decorator

Modern web frameworks provide immense value through Abstraction. They handle parsing, validation, error catching, and dependency injection, allowing you to focus on business logic. However, this abstraction comes at a non-zero cost. Every layer of software—every Guard, every Pipe, every Interceptor—adds a tiny fraction of latency to the request lifecycle.

For 99% of endpoints, this overhead is negligible (microseconds). But for high-frequency systems—such as telemetry ingestion endpoints receiving millions of hits per second, or internal health checks polled by a load balancer every few milliseconds—even microseconds accumulate.

Karin provides a unique feature to handle these edge cases: the Fast Mode.

Concept: The Express Lane

Think of the standard request lifecycle as the Main Highway with:

  • Weigh Stations (Validation Pipes)
  • Security Checkpoints (Auth Guards)
  • Customs Inspections (Interceptors)

The @Fast mode is the HOV / Express Lane. It is a direct, paved road from the entrance ramp to your destination. It bypasses everything. You get there faster, but you are responsible for your own safety.


How It Works

When you decorate a controller method with @Fast(), you are instructing the Karin RouteHandlerFactory to discard the standard execution pipeline entirely.

Instead of wrapping your method in the standard KarinExecutionContext, passing it through the Guard Chain, resolving parameters via the ParamsResolver, and wrapping the result in Interceptors, the framework compiles a Raw Handler.

This raw handler is a direct function call. It invokes your controller method immediately when the underlying HTTP adapter (Hono, H3, or Node's http) receives a request.

The Bypass List

When @Fast() is active, the following components are completely ignored, even if they are globally registered or explicitly applied to the controller:

  1. Guards: No authentication or authorization checks run.
  2. Pipes: No arguments are passed to the handler. Dependency Injection still works for this.service, but @Body, @Query, and @Param will fail (or be undefined).
  3. Interceptors: No logging, caching, or response transformation occurs.
  4. Exception Filters: If your method throws an error, it bubbles up directly to the HTTP Adapter, bypassing Karin's standardized error handling.

When to Use It?

The Fast Mode is a sharp tool. Use it only when the overhead of the framework features outweighs their benefit.

1. Health Checks & Readiness Probes

Load Balancers (AWS ELB) and Orchestrators (Kubernetes) often poll your service every few seconds. These requests carry no data and need no security. They just need a 200 OK.

typescript
@Get('health')
@Fast()
health() {
  return "OK";
}

2. High-Frequency Telemetry/Webhooks

If your server receives a firehose of data (e.g., IoT sensor readings, pixel tracking events) where every millisecond of CPU time counts towards your cloud bill, @Fast() allows you to ingest the data with near-zero latency.

typescript
@Post('ingest')
@Fast()
async ingest() {
  // You cannot use @Body(). You must access the raw request if your Adapter allows, 
  // or simply acknowledge receipt.
  return { received: true };
}

3. Static Configuration

Endpoints that return hardcoded constant data (like a config.json for a frontend app) benefit from skipping the overhead.


Trade-offs

FeatureStandard RouteFast Route
Dependency Injection✅ Fully Supported✅ Fully Supported
Argument Decorators✅ Parsing & Validation❌ Ignored
Security✅ Automatic (Guards)❌ Manual Implementation
Error Handling✅ Global Filters❌ Unhandled (Crashing?)
LatencyLow (Framework Overhead)Ultra-Low (Raw)

WARNING

Because Exception Filters are bypassed, throwing an error in a Fast route might crash the main process in generic Node.js environments if not caught. In Serverless environments, it usually results in a generic 500 error from the host. Always wrap Fast route logic in your own try-catch block if reliability is a concern.

Released under the MIT License.