Handlers are the core building blocks of Restate services. Each service has a list of handlers: durable functions that can be invoked over HTTP, Kafka, or using typed clients.

Writing handlers

Handlers receive a Restate context object (ctx) and a single, optional input:
async function myHandler(ctx: restate.Context, input: MyInput) {
  const result = await ctx.run("process", () => processData(input));
  return { success: true, result };
}
The input and output can be any JSON-serializable type. For other types, consult the serialization documentation of your SDK.

Context types

The context type you use depends on your service type:
  • Context - Basic Services (stateless handlers)
  • ObjectContext - Virtual Objects (exclusive handlers with state access)
  • ObjectSharedContext - Virtual Objects (concurrent read-only handlers)
  • WorkflowContext - Workflows (main run handler)
  • WorkflowSharedContext - Workflows (signal/query handlers)

Handler behavior

Virtual Objects and Workflows support two handler types: Exclusive handlers (ObjectContext, WorkflowContext) can read and write state but only one runs at a time per key to prevent conflicts. Shared handlers (ObjectSharedContext, WorkflowSharedContext) can only read state but run concurrently without blocking—useful for querying status during long-running operations.