
About this example
- About this example
- Code walkthrough
During the previous exercise, you executed a Workflow that included two Activities, both of which made a call to a microservice that provided a customized message in Spanish. That exercise demonstrates many of the key concepts you've learned during this course. Although you now have first-hand experience with developing and running applications on the Temporal Platform, you'll gain a deeper understanding of how Temporal works by looking at what happens during Workflow Execution.
Actors in the scenario
Let's begin by identifying the actors in this scenario, which will help to reiterate some important concepts.
First, the example includes a Worker, which executes the Workflow and Activity code, and uses a Client to communicate with the Cluster.
Next, the Temporal Cluster orchestrates the execution of that code by coordinating with the Worker, using a shared task queue.
Finally, the program that starts the Workflow, which will be referred to as a Client application because it requests Workflow Execution as well as the result from the Temporal Cluster, uses a Client to do this.

How work gets assigned
The assignment of work is indirect. The Temporal Cluster does not assign tasks to a Worker (in fact, the Temporal Cluster does not maintain a list of Workers).
Instead, the Workers continually poll the Temporal Cluster's Task Queue and accept tasks when they have spare capacity to process them. There are several benefits to this approach, but one of them is that tasks will just sit in the queue if there aren't enough Workers, which means that you can increase throughput and scalability by adding more Workers.

As you learned earlier, Temporal applications in production will typically have multiple Workers; however, this example uses a single Worker for the sake of simplicity.
The role of Commands
Another thing that will help you understand Temporal is the role of Commands. When the Worker encounters certain API calls during a Workflow Execution, such as a call of an Activity function's proxy, it sends a Command to the Temporal Cluster. The Cluster acts on these Commands, for example, by creating an Activity Task, but also stores them in case of failure.
For example, if the Worker crashes, the Temporal Service sends the stored information to another Worker to recreate the state of the Workflow to what it was immediately before the crash, and the new Worker resumes progress from that point. This allows you, as a developer, to code as if this type of failure wasn't even a possibility.

The Activity Definitions
The application defines two Activities: getSpanishGreeting and getSpanishFarewell.
import axios from 'axios';
const url = 'http://localhost:9999';
export async function getSpanishGreeting(name: string): Promise<string> {
const response = await axios.get(`${url}/get-spanish-greeting?name=${name}`);
return response.data;
}
export async function getSpanishFarewell(name: string): Promise<string> {
const response = await axios.get(`${url}/get-spanish-farwell?name=${name}`);
return response.data;
}
The Workflow Definition
The Workflow Definition executes those two Activities and returns a string created from their output.
import { proxyActivities } from '@temporalio/workflow';
import type * as activities from './activities';
const { getSpanishGreeting, getSpanishFarewell } = proxyActivities<
typeof activities
>({
startToCloseTimeout: '10 seconds',
});
export async function greeting(name: string): Promise<string> {
const response = await getSpanishGreeting(name);
return response;
}
export async function farewell(name: string): Promise<string> {
const response = await getSpanishFarewell(name);
return response;
}
The Worker
Here's the Worker initialization code, which registers the Workflow and Activity Definitions.
import { Worker } from '@temporalio/worker';
import * as activities from './activities';
async function run() {
const worker = await Worker.create({
workflowsPath: require.resolve('./workflows'),
activities,
taskQueue: 'translation-tasks',
});
await worker.run();
}
run().catch((err) => {
console.error(err);
process.exit(1);
});
Summary
In this course, you saw how the parts of a Temporal Application - a Worker, the Temporal Cluster and the Client Application - work together during a Workflow Execution.
In the next video, you will see how all the parts work together via a code walkthrough.
Get notified when we launch new educational content
New courses, tutorials, and learning resources - straight to your inbox.