Skip to main content

Serving

Restate services can run in two ways: as an HTTP endpoint or as AWS Lambda functions.

Creating an HTTP endpoint


import dev.restate.sdk.http.vertx.RestateHttpEndpointBuilder;
class MyApp {
public static void main(String[] args) {
RestateHttpEndpointBuilder.builder()
.bind(new MyService())
.bind(new MyVirtualObject())
.bind(new MyWorkflow())
.buildAndListen();
}
}

  1. Create a RestateHttpEndpointBuilder
  2. Bind one or multiple services to it
  3. Listen on the specified port (default 9080) for connections and requests.

Creating a Lambda handler


import dev.restate.sdk.lambda.BaseRestateLambdaHandler;
import dev.restate.sdk.lambda.RestateLambdaEndpointBuilder;
class MyLambdaHandler extends BaseRestateLambdaHandler {
@Override
public void register(RestateLambdaEndpointBuilder builder) {
builder
.bind(new MyService())
.bind(new MyVirtualObject());
}
}

  1. Add the dependency dev.restate:sdk-lambda:1.0.1.
  2. Extend the class BaseRestateLambdaHandler
  3. Override the register method
  4. Bind one or multiple services to the builder

Have a look at the deployment section for guidance on how to deploy your services on AWS Lambda.

Run on Lambda without handler changes

The implementation of your services and handlers remains the same for both deployment options.

Using Java 21 Virtual Threads

If you use a JVM >= 21, you can use virtual threads to run your services:


builder.bind(
// This is the class generated by the annotation processor
new GreeterServiceDefinitionFactory().create(new Greeter()),
new HandlerRunner.Options(Executors.newVirtualThreadPerTaskExecutor())
);