Kobolds

Concepts#

Kobolds is a messaging system built around a broker that coordinates communication between connected clients.

Clients connect to a broker to publish messages, receive subscriptions, send requests, receive replies, and manage broker-owned resources. The broker validates operations, enforces access controls, and routes messages to the appropriate connected clients.

This page introduces the core concepts used throughout the Kobolds documentation. For protocol operations, wire formats, and message structures, see the protocol reference. For the broker runtime model, see architecture.

At a glance#

Application
    │
    ▼
Kobolds client
    │
    ▼
Connection and transport
    │
    ▼
Kobolds broker
    │
    ├─ Authentication and authorization
    ├─ Sessions and entities
    ├─ Topic and service routing
    └─ Message delivery
Term Summary
Broker The server that accepts client connections and routes messages
Client The application-side library or runtime that communicates with a broker
Connection An active transport-level communication path
Session Broker-side state associated with a connected and authenticated peer
Entity A broker-managed resource associated with a session
Message A logical unit of data exchanged through the broker
Transport The byte transport used to carry protocol frames
Topic A named destination for published messages
Service A named destination for requests and replies
Pattern An expression that matches one or more topic or service names

Broker#

The broker is the central Kobolds server. It accepts client connections, authenticates peers, authorizes operations, maintains broker state, and routes messages between connected clients.

A broker can run alongside clients on the same machine or independently as a shared messaging service for many processes or machines. Clustered operation is only available when explicitly configured and supported by the deployed Kobolds version.

The broker is responsible for:

  • Accepting and managing client connections
  • Authenticating connections
  • Authorizing client operations
  • Managing sessions and broker-owned entities
  • Matching topic and service names against patterns
  • Routing published messages to subscribers
  • Routing requests to repliers and replies to requestors
  • Returning protocol-level success and error responses

Router#

The router coordinates operations that require a consistent view of broker state.

It handles work such as:

  • Authentication and authorization decisions
  • Session and entity lifecycle management
  • Topic, subscription, and service routing
  • Request validation
  • Protocol-level error responses
  • Persistence coordination, when enabled

The router is single-threaded. Keeping stateful coordination on one thread avoids shared-state locking in the routing path and gives broker operations a consistent ordering.

For example, when a client requests a new topic, the router validates the request, checks the session’s permission, updates broker state, and returns a success or error response.

Worker#

A worker manages active connections and performs transport-facing work. Workers run independently from the router and may each own multiple connections.

A worker is responsible for:

  • Reading bytes from client connections
  • Parsing frames and decoding messages
  • Encoding messages and serializing outbound frames
  • Buffering and batching network I/O
  • Detecting transport errors and disconnects
  • Passing inbound messages to the router
  • Sending router-directed messages through the correct connection

Workers and the router communicate through non-blocking single-producer, single-consumer queues. This allows a message to move between a worker and the router without unnecessarily copying its payload.

The broker worker count depends on its configuration and available host resources.

Client#

A client is the application-side component that communicates with a Kobolds broker. A client may be a library embedded in an application, a native binding, a command-line tool, or another broker peer.

Application → Kobolds client library → connection → Kobolds broker

A client generally provides APIs for:

  • Connecting to and disconnecting from a broker
  • Completing authentication
  • Creating and managing entities
  • Publishing messages
  • Receiving subscription deliveries
  • Sending requests
  • Receiving replies
  • Handling errors, disconnects, and other connection events

For example, an IoT sensor application can use a client to publish temperature telemetry, while a controller application uses another client to subscribe to that telemetry and send commands to the device.

Message#

A message is a logical unit of data exchanged between a client and broker.

Messages carry a payload and the metadata required to identify the operation, route it, deliver it, or return a result. A message can represent an application publish, subscription delivery, request, reply, entity operation, authentication operation, or protocol error.

Messages are encoded into one or more protocol frames before being sent across a transport.

Message → frame or frames → bytes → transport

Topic and publish/subscribe#

A topic is a named destination for published messages.

A publisher sends a message to a topic. The broker matches the topic against active subscriber patterns and delivers the message to every matching subscriber.

Publisher
    │
    │ publish /devices/a/telemetry
    ▼
Broker
    │
    │ matches subscriber pattern /devices/*/telemetry
    ▼
Subscriber

For example, a publisher can send telemetry to:

/devices/a/telemetry

A subscriber using the pattern below receives matching telemetry from every device one path segment beneath /devices:

/devices/*/telemetry

Service and request/reply#

A service is a named destination for request/reply communication.

A requestor sends a request to a service. The broker routes it to an eligible replier. The replier sends a reply, and the broker routes that reply back to the requestor that initiated the operation.

Requestor
    │
    │ request /devices/a/command
    ▼
Broker
    │
    │ route to a matching replier
    ▼
Replier
    │
    │ reply
    ▼
Broker
    │
    ▼
Requestor

For example, a controller can request a command from:

/devices/a/command

The connected device can process the request and return a reply through the broker.

Pattern#

A pattern matches one or more named resources, such as topics or services. Kobolds names are slash-separated paths.

Pattern element Meaning
Literal text Matches the exact path segment
* Matches exactly one path segment
** Matches zero or more path segments

Examples:

Pattern Matches
/devices/a/telemetry Only /devices/a/telemetry
/devices/*/telemetry /devices/a/telemetry, /devices/b/telemetry
/devices/** Every path beneath /devices
/** Every path

Patterns are used for routing and authorization. A subscription pattern determines which published messages a subscriber receives, while an authorization pattern determines which resources a session may access.

Session#

A session is the broker-side record associated with a connected and authenticated client or peer.

The session tracks information required to process later operations, including authentication state, authorization context, connection associations, and session-owned entities.

Entity#

An entity is a broker-managed resource associated with a session or globally available within the broker. When a client creates an entity, the broker assigns an entity_id. The client uses that identifier in later operations to refer to the same broker-side resource. Once an entity is created that is broker-owned, it will persist for the lifetime of the broker (until durable storage is implemented). Session-owned entities are destroyed when the session is destroyed.

Common entity types include:

  • Publisher (session owned)
  • Subscriber (session owned)
  • Requestor (session owned)
  • Replier (session owned)
  • Topic (broker owned)
  • Service (broker owned)

The exact available entity types and actions are defined by the protocol reference.

Connection and transport#

A connection is an active communication path between a client and broker. The broker assigns each connection to a worker, which performs the transport-facing I/O.

Connections handle the mechanics of communication:

  • Receiving bytes from the remote peer
  • Parsing frames and decoding messages
  • Queueing outbound messages and frames
  • Writing bytes through the active transport
  • Detecting disconnects and transport errors

A connection and session are related but different:

Concept Meaning
Connection The active bidirectional transport-level communication path
Session The logical broker-side state and resource ownership for a peer

A transport carries bytes between the client and broker. TCP is currently the supported transport. It provides a reliable, ordered, bidirectional byte stream for Kobolds protocol frames.

Future transport support must be treated as unavailable until it is explicitly documented for the Kobolds version being used.