Skip to content

How to Structure a Single SSE Endpoint for Multiple Users With Per-User State #179

@SOG-web

Description

@SOG-web

I’m currently implementing an SSE (Server-Sent Events) workflow using the HTTP library, and I’m trying to design a pattern for handling many users subscribing to a single SSE endpoint, while still being able to treat each subscriber individually.

What I want to achieve

I want to expose one SSE endpoint, for example:

/tournaments/updates

But this single endpoint should be able to:

  1. Accept multiple users simultaneously
  2. Identify each user separately
  3. Maintain per-user state or metadata (e.g., what tournament they are interested in)
  4. Only send each user the events relevant to their context

Example use-case

Imagine a game platform where many users subscribe to the tournament updates SSE.
There can be hundreds of tournaments, but I don’t want to create an SSE endpoint per tournament.

Instead:

  • All users connect to one SSE endpoint
  • Each user sends (for example) a query parameter or header such as ?tournament_id=abc123
  • The server receives the SSE connection
  • The SSE handler stores some per-user info (user ID, tournament ID, permissions, etc.)
  • The library should allow me to route or target updates to the correct subscriber(s)

My question

What is the recommended way to structure this with your SSE implementation?

  • How do I keep per-connection state inside an SSE endpoint?
  • How do I distinguish users and send each of them only the events they subscribed to?
  • Is there a canonical pattern for fan-out to multiple users from a single endpoint using this library?

Any guidance or example code would help a lot.
Thanks so much

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions