Introduction to Temporal
Lesson 1: Building the Foundation
by Vorrawut Judasri (Wut)
Why This Matters ๐ก
Before we dive in, think about this:
What happens when your backend job fails halfway? Who picks up the pieces?
This is where Temporal enters.
Objective ๐ฏ
By the end of this lesson, you will:
- โ Understand what Temporal is and why it exists
- โ See how it solves painful issues in distributed systems
- โ Build the foundation to use it in real projects
๐ง What is Temporal?
A workflow orchestration platform for reliable, scalable applications.
Think of it as an operating system for distributed systems.
It manages workflows, retries, failures, and state so you don't have to.
Temporal in Real Life ๐ณ
If your app is a restaurant, Temporal is the head chef:
- ๐จโ๐ณ Makes sure orders are cooked correctly
- ๐ ๏ธ Handles problems (like running out of ingredients)
- ๐ Tracks what's done and what's not
- ๐ Coordinates the entire kitchen workflow
๐ What Problems Does It Solve?
Without Temporal:
- ๐ฅ Scattered retry logic
- ๐ฅ Manual error handling
- ๐ฅ Hard to track long-running processes
- ๐ฅ Lost messages & race conditions
- ๐ฅ Difficult testing
- ๐ฅ No visibility
Example: Without Temporal
fun processOrder(order: Order) {
try {
val payment = paymentService.charge(order.amount)
val inventory = inventoryService.reserve(order.items)
val shipping = shippingService.arrange(order)
} catch (e: Exception) {
// Uh-oh. Now what?
// How do we recover?
// What state are we in?
// Should we retry everything?
}
}
Problem: No coordination, no recovery, no visibility!
๐ช How Temporal Helps
With Temporal:
- โ Reliable execution (even after failure)
- โ Built-in state management
- โ Automatic retries
- โ Full visibility
- โ Easy local testing
- โ Workflow versioning
Example: With Temporal
@WorkflowInterface
interface OrderWorkflow {
@WorkflowMethod
fun processOrder(order: Order): OrderResult
}
class OrderWorkflowImpl : OrderWorkflow {
override fun processOrder(order: Order): OrderResult {
val payment = paymentActivity.charge(order.amount)
val inventory = inventoryActivity.reserve(order.items)
val shipping = shippingActivity.arrange(order)
return OrderResult(payment, inventory, shipping)
}
}
Result: Clean, reliable, observable workflow!
๐งฉ Temporal Components
Workflows ๐ผ
- Define business logic (orchestration)
- Deterministic & replayable
- Control the flow of execution
Activities ๐ธ
- Perform actual work (API, DB, etc.)
- Can fail, retry, and run long
- Handle non-deterministic operations
Components Continued
Workers ๐ญ
- Execute workflows and activities
- Scalable, fault-tolerant
- Run your business logic
Temporal Server ๐ข
- Schedules, persists, coordinates everything
- Manages state and execution
- The brain of the operation
โ When to Use Temporal
Perfect for:
- โ Multi-step business processes
- โ Long-running jobs
- โ Processes across services
- โ Anything that needs reliability
Not ideal for:
- โ Simple request/response APIs
- โ Real-time (<ms latency) systems
- โ Basic CRUD operations
โ๏ธ Temporal vs Other Approaches
Approach | Pros | Cons |
---|---|---|
Manual Coordination | Simple, flexible | Hard to scale & maintain |
Message Queues | Async communication | No orchestration built-in |
State Machines | Clear state tracking | Poor error handling |
Temporal | Scalable, fault-tolerant | Learning curve |
๐ก Best Practices
Mindset Shifts ๐ง
- โ Design in workflows, not service chains
- โ Keep non-determinism out of workflows
- โ Assume failures happen
- โ Start simple, evolve with use
Common Misconceptions ๐ซ
Wrong Assumptions:
- โ "It's just a message queue"
- โ "Workflows are just functions"
- โ "Too much complexity"
- โ "Need to understand everything first"
Reality:
- โ It's a durable execution platform
- โ Start simple, learn by doing
Mental Model ๐ง
Temporal is your app's:
- ๐ง Memory - Never forgets where you left off
- ๐พ State manager - Handles complex state transitions
- ๐งโ๐ซ Coordinator - Orchestrates distributed processes
- ๐๏ธ Observer - Provides complete visibility
๐ฃ Next Steps
Time to build!
In the next lesson, we'll set up a Kotlin + Spring Boot project with Temporal SDK.
You're ready to:
- Start building real workflows
- See Temporal in action
- Experience the power of durable execution
Let's start coding! ๐