Skip to main content

How Temporal Works

Temporal offers an entirely new way to build scalable and reliable applications.

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 applications reliable and durable by default.

In a non-Temporal application, if a crash occurs, the progress of your application is lost. The application has no memory of what happened before the failure, requiring extensive error-handling logic and complex recovery code to resume. This process is time-consuming and error-prone, making it difficult to ensure reliability.

Temporal keeps track of 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. By offloading the responsibility of failure management from the application to the platform, this removes the need for extensive recovery coding, testing, and maintenance tasks.

This shift simplifies the development process. If a failure or a crash happens, your business processes keep running seamlessly without interruptions. This allows for developers to focus on business logic rather than infrastructure concerns and create applications that are inherently scalable and maintainable.

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.

Temporal Application: The Building Blocks

In a Temporal application, the code you write is made up of Workflows and Activities.

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
  • Purchasing concert tickets
  • Booking a vacation
  • Ordering a meal delivery
  • Filing an expense report
  • Creating a new employee onboarding process

In Temporal, a Workflow defines the steps your application takes to complete a task, much like a blueprint for your application. It’s your business logic, written in code, outlining each step in your process. This could be moving money between bank accounts, processing orders, deploying cloud infrastructure, or training an AI model.

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. This gives you full control and flexibility over your business processes, allowing you to build exactly what you need.

Activities

Activities are the individual tasks in your Workflow. These are defined as either functions or methods depending on the programming language. Activity tasks often interact with the outside world and are prone to failure such as sending emails, making network requests, writing to a database, or calling an API.

Activities are called directly from within your Workflow code.

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.

SDK

Developers create Temporal applications by writing code, just like you would to create any other software. To do this, you use an Temporal SDK, which stands for software development kit.

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

Temporal offers six SDKs: Java, Go, TypeScript, .NET, Python, and PHP. Installing the SDK allows you to easily add Temporal to your current projects without changing the tools you're already using. Temporal fits right into your existing tech stack.

The Temporal SDK also makes it easier to implement complex tasks such as sync/async execution, automatically retrying failed tasks, scheduling tasks to run regularly, managing complex workflows such as Saga compensation, and managing errors.

Temporal Service

Temporal has two main parts:

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

At the heart of Temporal's architecture is the Temporal Service, which provides durability, scalability, and reliability for your application. It communicates with the application, manages tasks, and maintains a detailed history of each event, which it durably persists to a database. The Temporal Service manages critical tasks like making an API call or updating a database, by making sure they get executed, and then recording their completion.

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.

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.

Describing a Temporal Application and Temporal Service - How It Works

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 creates a clear, organized list of what needs to be done.

Workers, which are part of your application and provided by the Temporal SDK, then carry out the tasks and run your code.

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. Overall, Workers execute the actual tasks defined in your Workflows. The Temporal Service orchestrates tasks to be done for the Workers.

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.

Describing a Temporal Application and Temporal Service and Workers - How It Works

Observability

To recap, the Temporal SDK is used to build your Temporal applications. The Temporal Service maintains the state of the applications.

We have two other major components: The Temporal Web UI and the Temporal CLI.

These are two ways you can see behind the scenes and track your Workflows. Both tools 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 and state of the your application. Also, known as the Web UI, it can also help you to quickly isolate, debug, and resolve production problems.

Recent Workflows page

Temporal CLI

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

  • Start your applications
  • Send messages to running applications
  • Cancel specific steps or tasks within your applications
  • And perform other management tasks

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

Reliable as Gravity

In conclusion, Temporal provides effortless durability, allowing applications to run for days, weeks, or even years without interruption. 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 supports multiple programming languages which you can mix-and-match between languages for polyglot teams. It simplifies state management and you 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.

In summary, Workflows handle the overall code structure and Activities are retryable pieces that could potentially fail. Temporal covers everything from minor network outages to significant issues like unexpected reboots or hardware failures. If your Workflow crashes, it automatically recreates its pre-crash state and continues as if the failure never happened using data from the Event History. The Event History is a detailed record that holds every significant action or decision made by the Workflow. Temporal automatically saves and restores your application's state, so you don't have to juggle that yourself or undertake manual state management. This means your application can keep running for days, weeks, or years, even if the underlying infrastructure fails.

tip

Follow one of our tutorials to Get Started learning how to use a Temporal SDK.

Or jump straight into the SDK docs for your preferred language:

For a deep dive into how Temporal works, visit the Temporal Encyclopedia page.