Prerequisites
- JDK >= 17
Getting started
To start building Restate services, you need two dependencies in your Maven/Gradle project manifest:- The SDK dependency.
- The annotation processor dependency.
Troubleshooting: Cannot resolve symbol '<MyServiceName>Client'
Troubleshooting: Cannot resolve symbol '<MyServiceName>Client'
Make sure the annotation processor is correctly configured, as described above, and build the project at least once.
IntelliJ won't update the Client classes when building
IntelliJ won't update the Client classes when building
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
@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. - 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
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. - The first argument of the handler must be the
ObjectContextparameter (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
@Sharedannotation and theSharedObjectContext(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
@Workflowannotation. - Every workflow must include a
runhandler:- 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 therunhandler and until the retention time expires.