Skip to main content

Serving

The Restate SDK is served as a HTTP handler. You can choose to run this in a standalone HTTP2 server, or connect the handler into a FaaS system like Lambda.

Creating a HTTP2 server

  1. Create the Restate Server
  2. Bind one or multiple services to it.
  3. Listen on the specified port for connections and requests.

if err := server.NewRestate().
Bind(restate.Reflect(MyService{})).
Bind(restate.Reflect(MyVirtualObject{})).
Start(context.Background(), ":9080"); err != nil {
log.Fatal(err)
}

Customizing the HTTP2 server

If you need to customize the HTTP2 server, or serve over HTTP1.1 you can call .Handler() instead of Start(), and then use the handler as normal. To discover services over HTTP1.1 you must provide the --use-http1.1 CLI flag.


handler, err := server.NewRestate().
Bind(restate.Reflect(MyService{})).
Bind(restate.Reflect(MyVirtualObject{})).
Handler()
if err != nil {
log.Fatal(err)
}

By default, this handler will advertise itself as working bidirectionally; the SDK will try to get completions from the runtime during execution.

However, you can use the method .Bidirectional(false) on the endpoint builder to change this on platforms that do not support bidirectional communication, such as Lambda. If you don't do this your handler may get stuck.

Creating a Lambda handler

To register your service as a Lambda function change the endpoint into a Lambda handler, setting .Bidirectional(false) as Lambda does not support bidirectional streaming of request data.


handler, err := server.NewRestate().
Bind(restate.Reflect(MyService{})).
Bind(restate.Reflect(MyVirtualObject{})).
Bidirectional(false).
Handler()
if err != nil {
log.Fatal(err)
}
lambda.Start(httpadapter.New(handler).ProxyWithContext)

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.

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


if err := server.NewRestate().
Bind(restate.Reflect(MyService{})).
WithIdentityV1("publickeyv1_w7YHemBctH5Ck2nQRQ47iBBqhNHy4FV7t2Usbye2A6f").
Start(context.Background(), ":9080"); err != nil {
log.Fatal(err)
}