Skip to main content

Overview

The III SDK provides a distributed function execution platform that connects multiple workers (services) through a central III Engine. Workers communicate with the Engine via WebSocket connections, enabling real-time function invocation, bidirectional streaming, and event-driven architectures.

System Components

1

III Engine (Central Hub)

The Engine acts as a message broker and coordinator that:
  • Routes function invocations between workers
  • Manages trigger registrations and event dispatching
  • Provides streaming channels for data transfer
  • Maintains worker registry and health status
  • Handles distributed tracing with OpenTelemetry
2

Workers (SDK Clients)

Workers are applications that connect to the Engine and:
  • Register functions they can execute
  • Subscribe to triggers (HTTP endpoints, events, schedules)
  • Invoke functions registered by other workers
  • Stream data through channels
  • Report metrics and telemetry
3

WebSocket Protocol

All communication uses a persistent WebSocket connection with:
  • Binary message framing for efficient data transfer
  • JSON-based message protocol with type discriminators
  • Automatic reconnection with exponential backoff
  • Distributed tracing context propagation (W3C Trace Context)

Communication Model

WebSocket Connection Lifecycle

The SDK manages WebSocket connections with automatic reconnection:
The SDK automatically reconnects with exponential backoff (default: 1s initial delay, 30s max delay, infinite retries). Functions and triggers are re-registered on reconnection.

Message Flow

Message Protocol

All messages follow a consistent structure with a type field:

Function Invocation Messages

InvokeFunction (Request):
InvocationResult (Response):

Reconnection Strategy

The SDK implements resilient reconnection with configurable backoff:
Reconnection behavior:
1

Connection Lost

WebSocket close event detected, state changes to reconnecting
2

Backoff Calculation

3

Re-registration

On successful reconnection:
  • All trigger types are re-registered
  • All services are re-registered
  • All functions (local and HTTP) are re-registered
  • All triggers are re-registered
  • Queued messages are sent
Monitor connection state changes with onConnectionStateChange() to implement custom reconnection logic or user notifications.

Worker Registration

Workers automatically register metadata on connection:
The Engine responds with WorkerRegistered message containing a unique worker_id.

Distributed Tracing

The architecture supports W3C Trace Context for end-to-end observability:
Every function invocation automatically propagates traceparent and baggage headers, enabling distributed tracing across workers without manual instrumentation.
Trace propagation flow:
  1. Caller injects trace context:
  2. Engine forwards context with invocation message
  3. Handler extracts context and creates child span:
  4. Response includes updated trace context from handler
See packages/node/iii/src/iii.ts:202-217 for implementation details.

Multi-Runtime Support

The III SDK is available in three runtimes with consistent APIs:
Location: packages/node/iii/src/iii.ts

Performance Considerations

Message Batching

The SDK queues messages when WebSocket is not ready and sends them in batch on connection:

Invocation Timeouts

All function calls have configurable timeouts (default 30s):
Timeouts prevent resource leaks from hanging invocations.

Connection State Management

Monitor and react to connection state changes:
See packages/node/iii/src/iii.ts:473-488 for implementation.

Graceful Shutdown

The SDK provides graceful shutdown that:
  • Stops accepting new invocations
  • Rejects pending invocations with error
  • Closes WebSocket connection
  • Flushes OpenTelemetry data
  • Clears all callbacks
Always call shutdown() before process termination to ensure telemetry data is flushed and in-flight requests are properly handled.

Next Steps

Functions

Learn how to register and invoke functions

Triggers

Understand trigger types and event handling

Channels

Implement bidirectional streaming

Streaming

Build real-time data operations