Prerequisites
- JDK >= 17 (JDK >= 23 recommended, required for the latest Restate features)
Getting started
To start building Restate services, add the SDK dependency to your Maven/Gradle project manifest. The SDK 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.The SDK uses a native library on JDK 23+. To silence the native-access warning printed at startup, enable native access by passing
--enable-native-access=ALL-UNNAMED as a JVM argument, or by setting Enable-Native-Access: ALL-UNNAMED in your JAR manifest.Kotlin: apply the all-open compiler plugin
Kotlin: apply the all-open compiler plugin
The SDK creates proxies for your services, which requires non-final classes. Kotlin classes are Alternatively, use on each Restate annotated class
final by default, so apply the Kotlin all-open compiler plugin for the Restate annotations. The Spring Boot Kotlin starter applies this automatically; for a plain Gradle project add:Kotlin/Gradle
open.Basic Services
Basic Services group related handlers and expose them as callable endpoints:- Define a service using the
@Serviceand@Handlerannotations - Each handler can be called at
<RESTATE_INGRESS>/MyService/myHandler. To override the service name (default is simple class name), use the annotation@Name. - Access Restate’s capabilities (state, calls, side effects, timers, …) through the static methods on the
Restateclass (Java), or the top-level functions in thedev.restate.sdk.kotlinpackage (Kotlin). - 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
9080by 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
@VirtualObjectannotation. - Each instance is identified by a key, accessible via
Restate.key()(Java) orobjectKey()(Kotlin). - Access the object’s persistent state via
Restate.state()(Java) orstate()(Kotlin). - Virtual Objects can have exclusive and shared handlers.
- Exclusive handlers (the default) have read/write access to the object state.
- Shared handlers use the
@Sharedannotation and have read-only access to the state.
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
@Workflowannotation. - Every workflow must include a
runhandler:- This is the main orchestration entry point
- It runs exactly once per workflow execution
- Resubmission of the same workflow will fail with “Previously accepted”. The invocation ID can be found in the request header
x-restate-id. - Use
Restate.key()(Java) orworkflowKey()(Kotlin) to access the workflow’s unique ID
- Additional handlers use the
@Sharedannotation and can signal or query the workflow. They can run concurrently with therunhandler and until the retention time expires.