DEV Community

Farshad Khazaei Fard
Farshad Khazaei Fard

Posted on

🚀 Announcing Breeze: The Go HTTP Framework That Redefines Raw Speed

630k req/s. Zero allocations. Built-in SPA engine. This is Breeze.


Let me skip the humble intro. I built a Go HTTP framework that benchmarks 3× faster than Fiber on the same hardware, same payload. It's called Breeze, it's built on top of gnet's event loop, and it ships with features that most frameworks make you bolt on yourself.

Here's why I think it's worth your attention.

📊 The Numbers Don't Lie

Simple JSON endpoint. Same machine. Same payload.

Framework Requests/sec vs Breeze
Breeze ~630k 1.0×
goFiber ~210k 0.33×
Echo ~140k 0.22×
Gin ~120k 0.19×
net/http ~85k 0.13×

These are approximate numbers from my environment — run the benchmarks yourself for authoritative results.

🔍 How Is This Even Possible?

Breeze isn't another net/http wrapper. It's built on gnet, a non-blocking event-driven networking engine that makes direct epoll/kqueue syscalls. On top of that, I obsessed over every allocation in the hot path:

Stack-allocated router. Path segment matching uses a fixed [16]string array on the stack — no heap allocations. Parameter indexes are pre-computed at route registration, not at match time.

Zero-copy parsing. Raw bytes are converted to strings using unsafe.String — no copying. Header keys are lowercased in-place instead of creating new strings.

Smart worker pool. A fixed goroutine pool with a 16× buffered channel absorbs request bursts. When the queue is full, it spawns a goroutine instead of blocking the event loop. That's the critical difference — the event loop never stalls.

Response serialization without fmt.Sprintf. Status codes are mapped via array index. Buffers are pre-sized. Every nanosecond counts when you're serving 600k+ requests per second.

⚡ Show Me the Code

A complete working server in under 20 lines:

package main

import (
    "runtime"
    "github.com/nelthaarion/breeze"
    middleware "github.com/nelthaarion/breeze/middlewares"
)

func main() {
    router := breeze.NewRouter()
    router.Use(middleware.RecoveryMiddleware())
    router.Use(middleware.LoggingMiddleware())

    router.Handle(breeze.GET, "/", func(ctx *breeze.Context) {
        ctx.JSON(map[string]string{"status": "ok"})
    })

    router.Handle(breeze.GET, "/users/:id", func(ctx *breeze.Context) {
        ctx.JSON(map[string]string{"id": ctx.Param("id")})
    })

    pool := breeze.NewWorkerPool(runtime.NumCPU())
    app  := breeze.New(router, pool)
    app.Run(3000, true) // port, multiCore
}
Enter fullscreen mode Exit fullscreen mode

That's it. One event loop per CPU core, RoundRobin load balancing, TCP_NODELAY enabled by default. No tuning required.

🔌 Native WebSocket — No Goroutine Per Connection

This is the one that makes people do a double-take.

Most Go frameworks spawn a goroutine for every WebSocket connection. Breeze doesn't — the WebSocket handler runs inside the gnet event loop. Zero extra goroutines. Zero per-connection memory overhead.

app := breeze.New(router, pool)
hub := app.WebSocket("/ws", &breeze.WSHandlerFunc{
    Connect: func(conn *breeze.WSConn) {
        conn.SendText("welcome")
    },
    Message: func(conn *breeze.WSConn, opcode byte, payload []byte) {
        hub.BroadcastText(string(payload))
    },
    Close: func(conn *breeze.WSConn, code uint16, reason string) {
        hub.BroadcastText("a user left")
    },
})
Enter fullscreen mode Exit fullscreen mode

The built-in WSHub handles broadcast, room management, and graceful disconnects. RFC 6455 compliant, auto-reconnect on the client side with exponential backoff.

🎨 The Template Engine That Thinks It's an SPA

This is the feature I'm most excited about. Breeze ships a full server-side template engine that automatically turns your multi-page app into a single-page app. No React. No Vue. No build step.

Here's how it works:

1. You write normal server-rendered views with layouts and components:

<!-- views/layout.html -->
{{define "layout"}}
<!DOCTYPE html>
<html>
<body>
    {{component "nav" .}}
    <div id="breeze-app">
        {{template "content" .}}
    </div>
</body>
</html>
{{end}}
Enter fullscreen mode Exit fullscreen mode
<!-- views/home.html -->
{{define "content"}}
<h1>Hello, {{.Data.Name}}!</h1>
{{component "card" (map "title" "Welcome" "body" "Try clicking a link")}}
{{end}}
Enter fullscreen mode Exit fullscreen mode

2. You register routes the simple way:

engine := breeze.NewTemplateEngine(breeze.TemplateConfig{
    ViewsDir:      "views",
    ComponentsDir: "components",
    LayoutFile:    "views/layout.html",
})

router.View("/", engine, "home", func(ctx *breeze.Context) any {
    return map[string]any{"Name": "World"}
})
Enter fullscreen mode Exit fullscreen mode

3. The magic happens automatically. On every full-page render, Breeze injects a JavaScript runtime before </body>. When a user clicks an internal link, the runtime intercepts it, fetches only the content block (via X-Breeze-Partial: true header), and swaps #breeze-app innerHTML. No full page reload. pushState handles the URL. popstate handles back/forward.

Your multi-page app just became a SPA. You didn't write a single line of JavaScript.

But wait — there's more. The template engine also gives you:

  • Reactive data store — page data is embedded as JSON, accessible via breeze.data(), watchable via breeze.watch()
  • Client-side re-renderingbreeze.render('card', newData, '#target') re-renders a component without hitting the server (it uses an embedded Go-template subset interpreter)
  • Fragment routesrouter.Fragment('/fragments/stats', engine, "stats", dataFn) serves bare HTML fragments for polling or partial updates
  • SPA form handling — POST forms are intercepted and submitted via fetch(), response HTML is swapped in. Progressive enhancement means forms still work without JS
  • Polling built inbreeze.poll('/fragments/stats', '#stats-box', 2000) auto-refreshes a fragment every 2 seconds
  • Dev mode hot reload — set DevMode: true and template changes are reflected instantly without restarting

🛡️ 9 Middleware, Zero External Dependencies

Everything you need for production, shipped with the framework:

// JWT with access + refresh tokens, role-based auth, custom claims validator
router.Use(middleware.JWTAuthMiddleware(middleware.JWTOptions{
    AccessSecret:  "secret",
    RefreshSecret: "refresh-secret",
    RequiredRoles: []string{"admin"},
}))

// CORS with automatic OPTIONS preflight
router.Use(middleware.CORSMiddleware(middleware.CORSOptions{
    AllowOrigins: "https://myapp.com",
    AllowMethods: "GET,POST,PUT,DELETE,OPTIONS",
}))

// Per-route rate limiting
router.Handle(breeze.POST, "/login", loginHandler,
    middleware.NewRateLimiter(middleware.RateLimiterOptions{
        Requests: 5,
        Per:      time.Minute,
    }),
)

// Auto Brotli → Gzip → Deflate compression
router.Use(middleware.CompressionMiddleware())

// Security headers (CSP, HSTS, X-Frame-Options, etc.)
router.Use(middleware.DefaultSecurityMiddleware())

// Swagger docs from Go struct annotations
router.Use(middleware.SwaggerMiddleware(router, middleware.SwaggerOptions{
    Title: "My API", Version: "1.0.0",
}))
Enter fullscreen mode Exit fullscreen mode

Also included: Logger, Panic Recovery, and ETag Cache.

🆚 How It Compares

Breeze Fiber Gin Echo
Engine gnet event loop fasthttp net/http net/http
Hot path allocs ~0 Low Moderate Moderate
WebSocket Native, zero-goroutine fasthttp-based gorilla/websocket gorilla/websocket
Template + SPA Built-in Separate Separate Separate
Swagger/OpenAPI Built-in Third-party Third-party Third-party
Middleware 9 built-in Growing Largest ecosystem Good built-in set
net/http compat No No Yes Yes

Honest take: If you need deep net/http ecosystem compatibility, Gin or Echo are still the safe choices. But if you're starting fresh and want maximum performance with modern features baked in — Breeze is worth a serious look.

📦 Install and Run

go get github.com/nelthaarion/breeze
Enter fullscreen mode Exit fullscreen mode

Requires Go 1.24.3+. Pulls in gnet v2, go-json, brotli, and golang-jwt/jwt.

🔮 What's Next

  • Real-time Dashboard — live route explorer, request monitor, ORM query monitor (already in progress)
  • gRPC support — leveraging gnet for high-performance gRPC
  • More middleware — OAuth2, OpenTelemetry
  • Template engine enhancements — hot-reload improvements, more built-in functions

Links:

I built Breeze because I was tired of choosing between speed and features. If that resonates with you, try it out and let me know what you think. I'm active on GitHub issues and open to contributions.

What's your current Go framework of choice, and what would make you switch? Let's talk in the comments. 👇


Tags: #go #golang #webframework #performance #breeze #open_source

Top comments (0)