Skip to content

Architecture Diagrams

High-level architecture, data flow, and sub-socket layout for the Micro Socket gateway.


High-Level Architecture

The gateway authenticates clients, checks ACL, deduplicates by messageId, and forwards published messages to the backbone. Subscribers are grouped by topic (sub-sockets); the backbone (or gateway) fans out to those sub-sockets.


Data Flow: PUBLISH → Backbone → Subscribers


Sub-Socket Layout (Inside Gateway)

Each topic has one sub-socket (a set of connections). Incoming messages for a topic are sent only to that set. Scale is per sub-socket count, not per connection.


Resume and Replay Flow

After reconnect, the client sends RESUME with sessionId and lastSeq per topic; the gateway replays missing messages then continues live delivery.


Scaling to Millions of Sub-Sockets

  • Single gateway: Map<topic, Set<connection>> keeps memory per subscription bounded; broadcast is O(subscribers of that topic).
  • Multiple gateways: Backbone (NATS/Kafka) fans out to all gateway instances; each instance maintains its own sub-socket map for its connections. No shared in-memory state between gateways except via the backbone.
  • Backbone choice: NATS for low latency and subject-based routing; Kafka for ordered, durable streams per topic/partition.

See Elysia Example for a single-node implementation that can be extended with a backbone for horizontal scaling.

Star the repo on GitHub if this documentation is useful — link in the navbar above.