Skip to main content

Overview

Functions are the core building blocks of the III SDK. They are named, remotely-invocable units of work that can be called by any worker connected to the Engine. Functions support typed inputs/outputs, automatic tracing, and both synchronous and asynchronous invocation patterns.

Function Registration

Local Functions

Register a function with a handler that executes in your worker:
Function registration message structure:
Function IDs use :: as namespace separator (e.g., service::resource::action). This convention helps organize functions and avoid naming conflicts.

Function Naming Best Practices

1

Use Namespaces

Prefix functions with service name:
2

Action-Oriented Names

Use verbs that describe the operation:
3

Reserved Prefixes

Avoid these Engine-reserved prefixes:
  • engine::* - Internal Engine functions
  • stream::* - Stream API functions
  • log::* - Logging functions

HTTP Functions

Register external HTTP endpoints (Lambda, Cloudflare Workers, etc.) as functions:
HTTP authentication types:
HTTP functions are invoked by the Engine, not the worker. The Engine handles authentication, retries, and timeout enforcement.

Function Handlers

Handler Signature

Handlers are async functions that receive input and return output:

Context Access

Access request context (logger, trace) using getContext():
Context structure:
See packages/node/iii/src/context.ts for implementation.

Automatic Tracing

All function handlers are automatically wrapped in OpenTelemetry spans:
No manual span creation needed! Every function call gets a server span with trace correlation, parent/child relationships, and automatic context propagation.

Function Invocation

Synchronous Call (await response)

Wait for function result with optional timeout:
Implementation:

Asynchronous Call (fire-and-forget)

Invoke without waiting for response:
Key differences:
callVoid() provides no delivery confirmation or error handling. Use for non-critical operations only.

Invocation Errors

Functions can fail in several ways:
1

Function Not Found

2

Handler Exception

3

Timeout

Rejected locally by SDK after timeout expires:

Function Discovery

List Available Functions

Query all registered functions across workers:
FunctionInfo structure:

React to Function Changes

Subscribe to function availability events:
Implementation:

Unregistering Functions

Functions can be unregistered dynamically:
Unregister message:

Channel Arguments

Functions can accept streaming channels as arguments:
The Engine automatically resolves channel references:
See Channels for complete channel API.

Multi-Language Examples

Next Steps

Triggers

Learn how to invoke functions from HTTP, events, and schedules

Channels

Stream data between functions with channels