building-restate-services
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRestate
Restate
Restate is a durable execution runtime. It records every step of a handler in a journal, so if the process crashes, the handler replays from the journal and resumes exactly where it left off. Services are regular applications using the Restate SDK (TypeScript, Python, Java, Go) that run behind a Restate Server (a single Rust binary on ports 8080 for ingress and 9070 for admin UI).
Restate是一个持久化执行运行时。它会将处理器的每一步操作记录在日志中,因此如果进程崩溃,处理器会从日志中重放操作,并精确地从中断处恢复执行。服务是使用Restate SDK(支持TypeScript、Python、Java、Go)开发的常规应用,运行在Restate Server(一个单独的Rust二进制程序,8080端口用于入口,9070端口用于管理UI)之后。
Detect context
检测上下文
Scan the project to determine the SDK and context:
-
Detect SDK:
- with
package.json-> TypeScript@restatedev/restate-sdk - or
requirements.txtwithpyproject.toml-> Pythonrestate-sdk - or
pom.xmlwithbuild.gradle-> Javadev.restate - with
go.mod-> Gogithub.com/restatedev/sdk-go - If no SDK detected, check for project files to determine language, then ask the user
-
Detect existing Restate code: Grep for,
@restatedev,restate-sdk,dev.restate.sdkgithub.com/restatedev -
Detect AI frameworks:,
@ai-sdk/,openai-agents,google-adkpydantic-ai -
Detect workflow orchestrators:,
temporalio,@temporalio, etc.aws-cdk/aws-stepfunctions
扫描项目以确定SDK和上下文:
-
检测SDK:
- with
package.json-> TypeScript@restatedev/restate-sdk - or
requirements.txtwithpyproject.toml-> Pythonrestate-sdk - or
pom.xmlwithbuild.gradle-> Javadev.restate - with
go.mod-> Gogithub.com/restatedev/sdk-go - 如果未检测到SDK,检查项目文件以确定语言,然后询问用户
-
检测现有Restate代码: 搜索,
@restatedev,restate-sdk,dev.restate.sdkgithub.com/restatedev -
检测AI框架:,
@ai-sdk/,openai-agents,google-adkpydantic-ai -
检测工作流编排器:,
temporalio,@temporalio, etc.aws-cdk/aws-stepfunctions
Core reference (always load)
核心参考(始终加载)
After detecting the SDK, always load the SDK reference:
- - Setup, API patterns, determinism rules, error handling, and pitfalls for the detected SDK
references/<sdk>/api-and-pitfalls.md
检测到SDK后,始终加载对应的SDK参考文档:
- - 针对检测到的SDK的设置、API模式、确定性规则、错误处理以及常见陷阱
references/<sdk>/api-and-pitfalls.md
Context-based references (load when relevant)
基于上下文的参考(相关时加载)
| Context | Reference |
|---|---|
| Design a new application, choose service types | |
| Convert from a workflow orchestrator or existing app | |
| Invoking services, interacting with invocations (cancel, attach, idempotency, sends, Kafka) | |
| Build AI agent with Vercel AI SDK | |
| Build AI agent with OpenAI Agents SDK | |
| Build AI agent with Google ADK | |
| Build AI agent with Pydantic AI | |
| Debug errors, stuck invocations, journal mismatches | |
| Testing, deployment, server config, Kafka, advanced topics | Use the bundled restate-docs MCP server |
| Code examples and templates | |
| 上下文 | 参考文档 |
|---|---|
| 设计新应用,选择服务类型 | |
| 从工作流编排器或现有应用迁移至Restate | |
| 调用服务、与调用交互(取消、附加、幂等性、发送、Kafka) | |
| 使用Vercel AI SDK构建AI Agent | |
| 使用OpenAI Agents SDK构建AI Agent | |
| 使用Google ADK构建AI Agent | |
| 使用Pydantic AI构建AI Agent | |
| 调试错误、卡住的调用、日志不匹配 | |
| 测试、部署、服务器配置、Kafka、高级主题 | 使用内置的restate-docs MCP服务器 |
| 代码示例和模板 | |
Before-you-design checklist
设计前检查清单
Before designing any Restate service architecture, check:
| Question | Consult |
|---|---|
| Restate service types, stateful entities, keying, concurrency? | |
| Non-Restate orchestrator in the project? | |
| Invoking, cancelling, deduplicating, or attaching to invocations? | |
| Error handling, compensation, sagas? | Error handling guide, Sagas guide |
| AI agent or LLM calls? | The relevant agent integration reference |
在设计任何Restate服务架构之前,请检查以下内容:
| 问题 | 参考文档 |
|---|---|
| Restate服务类型、有状态实体、键控、并发? | |
| 项目中存在非Restate编排器? | |
| 调用、取消、去重或附加到调用? | |
| 错误处理、补偿、Sagas? | Error handling guide, Sagas guide |
| AI Agent或LLM调用? | 对应的Agent集成参考文档 |
Always verify before finishing
完成前必须验证
All checks below are mandatory.
- All side effects, external I/O, and DB calls wrapped in
ctx.run() - No native random, time, sleep, or UUID -- use ctx helpers
- Restate concurrency combinators only (no ,
Promise.all/asyncio.gather,wait, goroutines + channels,CompletableFuture)select - No ctx operations inside
ctx.run() - raised for non-retryable failures
TerminalError - Python: no bare
except: - AI agents: set a retry policy for LLM calls
- Virtual Objects: no deadlock cycles
- Service registered and invoked via curl or the UI
以下所有检查均为必填项.
- 所有副作用、外部I/O和数据库调用都包裹在中
ctx.run() - 不使用原生随机数、时间、睡眠或UUID——使用ctx助手函数
- 仅使用Restate并发组合器(不使用,
Promise.all/asyncio.gather,wait, goroutines + channels,CompletableFuture)select - 内部不包含ctx操作
ctx.run() - 针对不可重试的失败抛出
TerminalError - Python:不使用裸
except: - AI Agent:为LLM调用设置重试策略
- 虚拟对象:无死锁循环
- 服务已注册并通过curl或UI调用
Replay test - required on any handler logic change
重放测试 - 处理器逻辑变更时必填
Any change to handler business logic (new operations, reordered steps, new blocks, new branches) must be covered by a Testcontainers test with always-replay enabled, and that test must pass before declaring the work done. Always-replay forces every journaled step to replay on every invocation, so non-determinism fails the test instead of failing in production on retry.
ctxctx.run()- TypeScript: in
alwaysReplay: trueRestateTestEnvironment.start - Python: in
always_replay=Truerestate.test_harness - Java / Go: on the Restate container
RESTATE_WORKER__INVOKER__INACTIVITY_TIMEOUT=0m
See the Testing section of for the working scaffold.
references/<sdk>/api-and-pitfalls.md任何对处理器业务逻辑的变更(新增操作、调整步骤顺序、新增块、新增分支)都必须通过启用always-replay的Testcontainers测试,且测试通过后才能宣告工作完成。Always-replay会强制每次调用都重放所有已记录的步骤,这样非确定性问题会在测试阶段暴露,而非在生产环境重试时失败。
ctxctx.run()- TypeScript: in
alwaysReplay: trueRestateTestEnvironment.start - Python: in
always_replay=Truerestate.test_harness - Java / Go: on the Restate container
RESTATE_WORKER__INVOKER__INACTIVITY_TIMEOUT=0m
有关可用的测试框架,请查看的测试部分。
references/<sdk>/api-and-pitfalls.md