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

  1. Create a RestateHttpEndpointBuilder
  2. Bind one or multiple services to it
  3. Listen on the specified port (default 9080) for connections and requests.
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();
}
}

Creating a Lambda handler

  1. Add the dependency dev.restate:sdk-lambda:1.2.0.
  2. Extend the class BaseRestateLambdaHandler
  3. Override the register method
  4. Bind one or multiple services to the builder
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());
}
}

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()));

Validating request identity

SDKs can validate that incoming requests come from a particular Restate instance. You can find out more about request identity in the Security docs. You will need to use the request identity dependency, for example in Gradle:

implementation("dev.restate:sdk-request-identity:1.2.0")
import dev.restate.sdk.auth.signing.RestateRequestIdentityVerifier;
import dev.restate.sdk.http.vertx.RestateHttpEndpointBuilder;
class MySecureApp {
public static void main(String[] args) {
RestateHttpEndpointBuilder.builder()
.bind(new MyService())
.withRequestIdentityVerifier(
RestateRequestIdentityVerifier.fromKeys(
"publickeyv1_w7YHemBctH5Ck2nQRQ47iBBqhNHy4FV7t2Usbye2A6f"))
.buildAndListen();
}
}