Prerequisites
1
Create an Encore app
Follow the Encore quickstart to install the CLI,
then create a new app:
2
Install the Restate SDK
Add the Restate TypeScript SDK to your Encore project:
3
Define your Restate service handlers
Create a Restate service with your handler logic. This is standard Restate code:Each
order-processor/restate.ts
ctx.run() call is journaled by Restate. If the process crashes mid-execution, Restate replays completed
steps and resumes where it left off.4
Expose the handler via an Encore raw endpoint
Create the Encore service and wire the Restate endpoint handler to a raw endpoint.Since Encore’s raw endpoints use Node.js HTTP types while the Restate SDK provides a Fetch API handler,
we need a small adapter to bridge between the two:Encore now serves the Restate handler at
order-processor/encore.restate.ts
order-processor/api.ts
/restate/*. The Restate Server will call this
endpoint to discover and invoke your handlers.5
Start Restate Server and Encore
In one terminal, start the Restate Server:In another terminal, start your Encore app:
6
Register your service with Restate
Tell the Restate Server where to find your handlers:You should see the discovered
OrderProcessor service printed out.The
--use-http1.1 flag is needed because Encore’s raw endpoints serve HTTP/1.1.7
Invoke your handler
Send a request to Restate Server’s ingress (port 8080), which routes it to your Encore-hosted handler:You can also invoke the handler from other Encore API endpoints using the Restate client:
order-processor/orders.ts
8
You're running Restate handlers inside Encore!
Related resources
- Encore documentation
- Encore raw endpoints
encore-restate-gen: a CLI tool that auto-generates Restate service definitions and typed clients from your Encore project- Microservice orchestration use cases
- Sagas guide