Skip to main content
The Restate Java/Kotlin SDK is open source and available on GitHub. The Restate SDK lets you implement handlers. Handlers can be part of a Basic Service, a Virtual Object, or a Workflow. This page shows how to define them with the Java/Kotlin SDK.

Prerequisites

Getting started

Get started quickly with the Java or Kotlin Quickstart.
To start building Restate services, you need two dependencies in your Maven/Gradle project manifest:
  • The SDK dependency.
  • The annotation processor dependency.
The SDK dependency comes in different flavors: Java or Kotlin API, HTTP or Lambda. Choose the one you need depending on the language you want to use and whether you want to deploy the service as an HTTP server or as AWS Lambda.
Make sure the annotation processor is correctly configured, as described above, and build the project at least once.
Make sure you have annotation processing enabled in the IntelliJ compiler, check the relevant documentation. An example setup is available here: compiler.xml

Basic Services

Basic Services group related handlers and expose them as callable endpoints:
  • Define a service using the @Service and @Handler annotations
  • Each handler can be called at <RESTATE_INGRESS>/MyService/myHandler. To override the service name (default is simple class name), use the annotation @Name.
  • Handlers take the Context (JavaDocs/KotlinDocs) as the first argument.
  • The input parameter (at most one) and return type are optional and can be of any type. See serialization for more details.
  • Create an endpoint to expose the service over HTTP (port 9080 by default).

Virtual Objects

Virtual Objects are services that are stateful and key-addressable — each object instance has a unique ID and persistent state.
  • Use the @VirtualObject annotation.
  • The first argument of the handler must be the ObjectContext parameter (JavaDocs/KotlinDocs).
  • Each instance is identified by a key (accessible via ctx.key()).
  • Virtual Objects can have exclusive and shared handlers.
  • Exclusive handlers receive an ObjectContext, allowing read/write access to object state.
  • Shared handlers use the @Shared annotation and the SharedObjectContext (JavaDocs/KotlinDocs).

Workflows

Workflows are long-lived processes with a defined lifecycle. They run once per key and are ideal for orchestrating multi-step operations, which require external interaction via signals and queries.
  • Create the workflow by using the @Workflow annotation.
  • Every workflow must include a run handler:
    • This is the main orchestration entry point
    • It runs exactly once per workflow execution and uses the WorkflowContext (JavaDocs/KotlinDocs)
    • Resubmission of the same workflow will fail with “Previously accepted”. The invocation ID can be found in the request header x-restate-id.
    • Use ctx.key() to access the workflow’s unique ID
  • Additional handlers must use the SharedWorkflowContext (JavaDocs/KotlinDocs) and can signal or query the workflow. They can run concurrently with the run handler and until the retention time expires.

Configuring services

Check out the service configuration docs to learn how to configure service behavior, including timeouts and retention policies.