temporal.io 一个持久化分布式工作流引擎

Temporal 是一个开源的系统,开源代码

https://github.com/temporalio/temporal

文档

https://docs.temporal.io/

核心解决的问题

Temporal solves many problems that developers face while building distributed applications. But most of them revolve around these three themes:

  • Reliable distributed applications
  • Productive development paradigms and code structure
  • Visible distributed application state

How does Temporal make applications reliable?

Temporal makes it easier for developers to build and operate reliable, scalable applications without sacrificing productivity. The design of the system ensures that, once started, an application's main function executes to completion, whether that takes minutes, hours, days, weeks, or even years. Temporal calls this Durable Execution.

Temporal 使开发者能够在不牺牲生产力的情况下,更轻松地构建和运行可靠、可扩展的应用程序。该系统的设计确保一旦启动,应用程序的主函数将执行至完成状态,无论这一过程需要几分钟、几小时、几天、几周甚至数年。Temporal 将此称为"持久化执行"。

How does Temporal simplify application code for software developers?

By shifting the burden of failure handling from the application to the platform, there is less code for application developers to write, test, and maintain. Temporal's programming model offers developers a way to express their business logic into coherent Workflows that are much easier to develop than distributed code bases.

通过将故障处理的负担从应用程序转移到平台,应用开发者需要编写、测试和维护的代码量得以减少。Temporal的编程模型为开发者提供了一种方式,将业务逻辑表达为连贯的工作流,这比开发分布式代码库要简单得多。

Choose the SDK that best suits your preferred programming language and start writing your business logic. Integrate your favorite IDE, libraries, and tools into your development process. Temporal also supports polyglot and idiomatic programming - which enables developers to leverage the strengths of various programming languages and integrate Temporal into existing codebases. Developers achieve all of this without having to manage queues or complex state machines.

选择最适合您编程语言的SDK,开始编写业务逻辑。将您喜欢的IDE、库和工具集成到开发流程中。Temporal还支持多语言和惯用编程——使开发者能够利用各种编程语言的优势,并将Temporal集成到现有代码库中。开发者无需管理队列或复杂的状态机即可实现这一切。

How does Temporal make it easier to view the state of the application?

Temporal provides out-of-the-box tooling that enables developers to see the state of their applications whenever they need to. The Temporal CLI allows developers to manage, monitor, and debug Temporal applications effectively. The browser-based Web UI lets you quickly isolate, debug, and resolve production problems.

Temporal 提供了开箱即用的工具,让开发者能够随时查看应用程序的状态。Temporal CLI 使开发者可以有效管理、监控和调试 Temporal 应用。基于浏览器的 Web 界面可帮助您快速隔离、调试并解决生产环境问题。

Build Invincible Apps

In any complex system, failures are bound to happen. Software engineers spend a lot of time ensuring that what they build can withstand potential failures. Temporal makes your code execution reliable and durable by default.

在任何复杂的系统中,故障都不可避免。软件工程师花费大量时间确保他们构建的系统能够承受潜在的故障。Temporal 默认情况下使您的代码执行可靠且持久。

Normally, if a crash occurs then the state of your application's execution is lost. The application has no memory of what happened before the failure, requiring extensive error handling logic and complex recovery code to resume. The process is time-consuming and error-prone, making it difficult to ensure reliability.

通常,如果发生崩溃,应用程序的执行状态就会丢失。应用程序对故障前的情况毫无记忆,需要大量错误处理逻辑和复杂的恢复代码才能继续运行。这个过程既耗时又容易出错,难以确保可靠性。

Temporal tracks the progress of your application. If something goes wrong, like a power outage, it guarantees that your application can pick up right where it left off — it’s like having the ultimate autosave. Offloading the responsibility of failure management from the application to the platform removes the need for extensive recovery coding, testing, and maintenance tasks.

Temporal追踪应用程序的进度。如果出现问题,比如停电,它能确保您的应用程序可以从中断处继续运行——就像拥有终极自动保存功能。将故障管理的责任从应用程序转移到平台,省去了大量恢复编码、测试和维护工作的需求。

Durable Execution

Temporal is a Durable Execution Platform. Durable Execution ensures that your application behaves correctly despite adverse conditions by guaranteeing that it will run to completion. This shift simplifies the development process. If a failure or a crash happens, your business processes keep running seamlessly without interruptions. Developers shift their focus on business logic rather than infrastructure concerns and create applications that are inherently scalable and maintainable.

Temporal是一个持久化执行平台。持久化执行通过确保应用程序运行至完成,保障其在不利条件下仍能正确运作。这一转变简化了开发流程——当故障或崩溃发生时,业务流程仍能无缝持续运行。开发者得以将重心转向业务逻辑而非基础设施问题,从而构建出天生具备可扩展性和可维护性的应用程序。

Thousands of developers trust Temporal for use cases like order processing, customer onboarding, and payment handling because it enables them to build invincible applications that are resilient, durable, and just work. With Temporal, your applications keep running, no matter what happens.

数千名开发者信赖 Temporal 来处理订单处理、客户注册和支付处理等用例,因为它能帮助他们构建坚不可摧的应用程序,这些应用程序具有弹性、持久性并能正常工作。使用 Temporal,无论发生什么情况,您的应用程序都能持续运行。

Temporal Application: The Building Blocks

Workflow

Conceptually, a Workflow is a sequence of steps. You've likely encountered Workflows in your daily life, whether it's:

  • Using a mobile app to transfer money
  • Booking a vacation
  • Filing an expense report
  • Creating a new employee onboarding process
  • Deploying cloud infrastructure
  • Training an AI model

A Temporal Workflow is your business logic, defined in code, outlining each step in your process.

Temporal isn’t a no-code Workflow engine — it is Workflows-as-Code. Instead of dragging and dropping steps in a visual interface, you write your Workflows in code in your favorite programming language, code editor, and other tools. No-code engines eventually hit their limitations however, Temporal gives you full control and flexibility over your business processes. This allows you to build exactly what you need.

Temporal并非无代码工作流引擎,而是采用“代码化工作流”理念。不同于在可视化界面中拖拽步骤,您可以用熟悉的编程语言、代码编辑器及其他工具直接编写工作流程代码。无代码引擎终将遇到功能局限,而Temporal让您对业务流程拥有完全掌控与灵活调整能力,从而精准构建所需解决方案。

Activities

Activities are the individual units of work in your Workflow. Activities are defined as either functions or methods, depending on the programming language. Activities often involve interacting with the outside world, such as sending emails, making network requests, writing to a database, or calling an API, which are prone to failure. You can call Activities directly from your Workflow code.

活动是工作流中的独立工作单元。根据编程语言的不同,活动被定义为函数或方法。活动通常涉及与外部世界的交互,例如发送电子邮件、发出网络请求、写入数据库或调用 API,这些操作容易失败。您可以直接从工作流代码中调用活动。

If an Activity fails, Temporal automatically retries it based on your configuration. Since Activities often rely on external systems, transient issues can occur. These include temporary but critical problems like network failures, timeouts, or service outages. You have full control over how often and how many times these retries should happen for each Activity.

如果Activity失败,Temporal会根据您的配置自动重试。由于Activity通常依赖外部系统,可能会出现临时性问题。这些问题包括网络故障、超时或服务中断等短暂但关键的问题。您可以完全控制每个Activity的重试频率和次数。

SDK

Developers create Temporal applications by writing code, just like you would to create any other software.

A Temporal SDK (software development kit) is an open-source library that developers add to their application to use Temporal. It provides everything needed to build Workflows, Activities, and various other Temporal features in a specific programming language.

开发者通过编写代码来创建Temporal应用程序,就像创建其他任何软件一样。

Temporal SDK(软件开发工具包)是一个开源库,开发者将其添加到应用程序中以使用Temporal。它提供了在特定编程语言中构建工作流、活动以及各种其他Temporal功能所需的一切。

Temporal offers seven SDKs: .NET, Go, Java, PHP, Python, Ruby, TypeScript. Since Temporal supports multiple programming languages, you can mix-and-match between languages for polyglot teams. You can easily add any Temporal SDK to your current projects without changing the tools you're already using to build and deploy. Temporal fits right into your existing tech stack.

Temporal提供七种SDK:.NET、Go、Java、PHP、Python、Ruby和TypeScript。由于Temporal支持多种编程语言,多语言团队可以灵活混搭使用不同语言。您无需更改现有构建部署工具,即可轻松将任意Temporal SDK添加到当前项目中。Temporal能完美融入您现有的技术栈。

Temporal Service

Temporal has two main parts:

  1. Your application
  2. The Temporal Service (a set of services and components)

At the heart of Temporal architecture is the Temporal Service, which provides durability, scalability, and reliability for your application. Your application communicates with the Temporal Service and the Temporal Service oversees the execution of critical tasks such as making an API call, then records their completion. It maintains a detailed history of each event, which it reliably persists to a database.

Temporal架构的核心是Temporal服务,它为您的应用程序提供持久性、可扩展性和可靠性。您的应用程序与Temporal服务通信,而Temporal服务则监督诸如发起API调用等关键任务的执行,并记录其完成情况。它维护每个事件的详细历史记录,并可靠地将其持久化到数据库中。

One of the biggest advantages of the Temporal Service is how it handles failures. The Temporal Service maintains a meticulous record of every step in your Workflows. By keeping a history of every step in your Workflow, it ensures that even if something goes wrong your Workflow can continue from the last successful point. The Temporal Service knows exactly where to resume without losing any work. This saves you from having to write complex error handling code or painstaking recovery mechanisms yourself.

Temporal Service 的最大优势之一在于其处理故障的方式。该服务会细致记录工作流中的每个步骤,通过保留完整的历史记录,即使出现故障也能确保工作流能从最后一个成功点继续执行。Temporal Service 能精准定位恢复位置,避免任何工作丢失。这让开发者无需自行编写复杂的错误处理代码或繁琐的恢复机制。

You can run the Temporal Service on your own infrastructure or use Temporal Cloud, a managed service that handles operational overhead and offers scalability and expert support.

Workers

The real strength of Temporal comes from the combination of your application and the Temporal Service. Whenever your application needs to perform a task, like sending a notification or processing a payment, the Temporal Service orchestrates what needs to be done. Workers, which are part of your application and provided by the Temporal SDK, then carry out the tasks defined in your Workflow.

The Worker polls the Temporal Service to see if there are tasks available and the Temporal Service matches the task with the Worker. The Worker runs the Workflow code based on the details specified in the task.

This collaboration is crucial for building reliable, scalable, and durable applications. You can run multiple Workers — often dozens, hundreds, or even thousands — to improve application performance and scalability.

A common misconception is that the Temporal Service runs your code. In fact, the Worker runs your code and works with your data directly. Temporal applications are secure by design. Workflows and Activities are seamlessly deployed within your infrastructure, fully integrated into your application. Your data is also protected with your encryption libraries and keys. You maintain full control over the security of your application from end to end.

Visibility

There are two tools provided by Temporal that allow you to see behind the scenes and interact with your Workflows. These are powerful for debugging uses and provide real-time monitoring of your applications.

Temporal UI

The Temporal UI is a browser-based user interface that allows you to see the progress of your application. Also, known as the Web UI, it can also help you to quickly isolate, debug, and resolve production problems.

Temporal CLI

The Temporal CLI is a command-line interface tool for managing, monitoring, and debugging Temporal Applications. Through your terminal, you can:

  • Start a Workflow
  • Trace the progress of a Workflow
  • Cancel or terminate a Workflow
  • And perform other operations

The Temporal CLI provides developers with direct access to a Temporal Service for local development purposes.

Event History

With Temporal, your Workflows can seamlessly recover from crashes. This is made possible by the Event History, a complete and durable log of everything that has happened in the lifecycle of a Workflow Execution, as well as the ability of the Temporal Service to durably persist the Events during Replay.

Temporal uses the Event History to record every step taken along the way. Each time your Workflow Definition makes an API call to execute an Activity or start a Timer for instance, it doesn’t perform the action directly. Instead, it sends a Command to the Temporal Service.

A Command is a requested action issued by a Worker to the Temporal Service after a Workflow Task Execution completes. The Temporal Service will act on these Commands such as scheduling an Activity or scheduling a timer. These Commands are then mapped to Events which are persisted in case of failure. For example, if the Worker crashes, the Worker uses the Event History to replay the code and recreate the state of the Workflow Execution to what it was immediately before the crash. It then resumes progress from the point of failure as if the failure never occurred.

For a deep dive into the Event History or Commands, visit the Temporal Encyclopedia page or enroll in one of our courses.

Reliable as Gravity

Temporal provides effortless durability, allowing applications to run for days, weeks, or even years without interruption even if the underlying infrastructure fails. This is what we call Durable Execution. Temporal also represents a paradigm shift in software development. It's not just about making existing patterns more reliable; it's about enabling entirely new approaches to building complex, distributed systems.

Temporal simplifies state management and developers don't have to write tons of extra code to handle every possible thing that could go wrong. With built-in scalability, Temporal ensures that your application runs smoothly, no matter its size or complexity.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值