Skip to main content

Quickstart

This guide takes you through your first steps with Restate.

We will run a simple Restate Greeter service that listens on port 9080 and responds with You said hi to <name>! to a greet request.

Quickstart

Select your favorite runtime:

Prerequisites
1
Install Restate Server & CLI

Restate is a single self-contained binary. No external dependencies needed.

Install Restate Server and CLI.

brew install restatedev/tap/restate-server &&
brew install restatedev/tap/restate

Then run the Restate Server with:

restate-server

2
Get the Greeter service template

restate example typescript-hello-world &&
cd typescript-hello-world &&
npm install

3
Run the Greeter service

Run it and let it listen on port 9080 for requests:

npm run app-dev
> restate-ts-template@0.0.1 app-dev
> ts-node-dev --watch ./src --respawn --transpile-only ./src/app.ts
[INFO] 00:44:54 ts-node-dev ver. 2.0.0 (using ts-node ver. 10.9.2, typescript ver. 5.6.3)
[restate] [2024-11-12T23:44:54.955Z] INFO: Listening on 9080...

4
Register the service

Tell Restate where the service is running, so Restate can discover and register the services and handlers behind this endpoint:

restate deployments register http://localhost:9080
SERVICES THAT WILL BE ADDED:
- Greeter
Type: Service
HANDLER INPUT OUTPUT
greet value of content-type 'application/json' value of content-type 'application/json'
Are you sure you want to apply those changes? · yes
DEPLOYMENT:
SERVICE REV
Greeter 1

If you run Restate with Docker, use http://host.docker.internal:9080 instead of http://localhost:9080.

5
Send a request to the Greeter service

curl localhost:8080/Greeter/greet -H 'content-type: application/json' -d '"Sarah"'
You said hi to Sarah!

🎉
Congratulations, you just ran Durable Execution!

The invocation you just sent used Durable Execution to make sure the request ran till completion. For each request, it sent a notification, slept for a second, and then sent a reminder.

import * as restate from "@restatedev/restate-sdk";
import { sendNotification, sendReminder } from "./utils";
restate
.endpoint()
.bind(
restate.service({
name: "Greeter",
handlers: {
greet: async (ctx: restate.Context, name: string) => {
// Durably execute a set of steps; resilient against failures
const greetingId = ctx.rand.uuidv4();
await ctx.run(() => sendNotification(greetingId, name));
await ctx.sleep(1000);
await ctx.run(() => sendReminder(greetingId));
// Respond to caller
return `You said hi to ${name}!`;
},
},
}),
)
.listen(9080);

It sometimes failed to send the notification and the reminder. You can see in the log how Restate retried the request. On a retry, it skipped the steps that already succeeded. Even the sleep is durable and tracked by Restate. If you kill/restart the service halfway through, the sleep will only last for what remained.

Restate does this by persisting the progress of the handler. Letting you write code that is resilient to failures out of the box.

Next: Build and run the app

Once you have implemented your service, build the app and run it with:

npm run build
npm run app

Next steps