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

SDK:

Prerequisites
  • Python >= v3.11
1
Install Restate Server & CLI

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

Install Restate Server and CLI via:

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

Then run the Restate Server with:

restate-server

You can find the Restate UI running on port 9070 (http://localhost:9070) after starting the Restate Server.

2
Get the Greeter service template

restate example python-hello-world &&
cd python-hello-world

3
Run the Greeter service

Create a venv and install the requirements:

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Now, start developing your service in example.py. Run it with a Hypercorn server, and let it listen on port 9080 for requests:

python -m hypercorn --config hypercorn-config.toml example:app

4
Register the service

Tell Restate where the service is running, so Restate can discover and register the services and handlers behind this endpoint. You can do this via the UI (http://localhost:9070) or via:

restate deployments register http://localhost:9080

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

Invoke the service via the UI playground: click on your service and then on playground.

Or invoke via curl:

curl localhost:8080/Greeter/greet --json '{"name": "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.

greeter = Service("Greeter")
@greeter.handler()
async def greet(ctx: Context, req: GreetingRequest) -> Greeting:
# Durably execute a set of steps; resilient against failures
greeting_id = await ctx.run("generate UUID", lambda: str(uuid.uuid4()))
await ctx.run("send notification", lambda: send_notification(greeting_id, req.name))
await ctx.sleep(timedelta(seconds=1))
await ctx.run("send reminder", lambda: send_reminder(greeting_id))
# Respond to caller
return Greeting(message=f"You said hi to {req.name}!")
app = restate.app(services=[greeter])

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 steps