Skip to content

Proposal: Add SSE (Server-Sent Events) package #4194

@vinod-morya

Description

@vinod-morya

Summary

I've built fibersse — a production-grade SSE library built natively for Fiber v3. I'd like to propose adding it (or a version of it) to gofiber/contrib as the official SSE package.

The Problem

There is no SSE package in gofiber/contrib today. Every Fiber project that needs Server-Sent Events hand-rolls the same SendStreamWriter + w.Flush() pattern. Existing Go SSE libraries (r3labs/sse, tmaxmax/go-sse) are built on net/http and break on Fiber because:

What fibersse Provides

Feature Status
Fiber v3 native (SendStreamWriter)
Client disconnect via w.Flush() error + heartbeat
Hub pattern (single goroutine, topic-based routing)
Event coalescing (last-writer-wins per key)
3 priority lanes (Instant / Batched / Coalesced)
NATS-style topic wildcards (* and >)
Adaptive per-connection throttling
Connection groups (publish by metadata)
Built-in JWT + ticket auth helpers
Prometheus metrics endpoint
Last-Event-ID replay (pluggable)
Graceful Kubernetes-style drain
Event TTL
Auto fan-out from Redis/NATS
Zero deps beyond Fiber v3
29 tests, MIT license

Links

Usage Example

hub := fibersse.New(fibersse.HubConfig{
    FlushInterval: 2 * time.Second,
    OnConnect: func(c fiber.Ctx, conn *fibersse.Connection) error {
        conn.Topics = []string{"notifications", "live"}
        return nil
    },
})
app.Get("/events", hub.Handler())

hub.Publish(fibersse.Event{
    Type:   "notification",
    Data:   map[string]string{"title": "Hello"},
    Topics: []string{"notifications"},
})

Proposal

I'm happy to:

  1. Contribute fibersse directly to gofiber/contrib as a new sse package
  2. Adapt the API to match contrib conventions
  3. Maintain it as part of the contrib ecosystem

Would love to hear from the maintainers on whether this fits the contrib vision and what changes would be needed.

cc @efectn @ReneWerner87

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions