Use Cases
This boilerplate excels in scenarios where reliability, scalability, and maintainability are critical. Here are real-world use cases where this architecture shines.
User Management & Onboarding
Multi-Step User Registration
Scenario: A new user signs up and you need to:
- Create user in database
- Send welcome email
- Create profile in analytics system
- Provision user resources
- Send notification to admin
Without Temporal:
- If email service is down, user is created but never receives email
- Complex retry logic needed for each step
- State management across failures is manual
- Partial completions leave inconsistent state
With This Boilerplate:
// Workflow automatically handles retries, state, and failure recovery
export async function userOnboardingWorkflow(userData: UserData) {
// Each step retries automatically on failure
const user = await activities.createUser(userData);
await activities.sendWelcomeEmail(user.email);
await activities.createAnalyticsProfile(user.id);
await activities.provisionResources(user.id);
await activities.notifyAdmin(user.id);
return user;
}
Benefits:
- Guaranteed completion even with service failures
- Automatic retries with exponential backoff
- Visual monitoring in Temporal UI
- Easy to modify workflow steps
Payment Processing
Reliable Payment Workflows
Scenario: Process a payment that involves:
- Validate payment details
- Charge payment gateway
- Update order status
- Send receipt email
- Update inventory
- Notify fulfillment system
Challenge: Payment gateways can be slow, timeout, or return ambiguous results.
With This Boilerplate:
export async function paymentWorkflow(orderId: string, paymentDetails: PaymentDetails) {
// Validate first (fast failure)
await activities.validatePayment(paymentDetails);
// Charge with idempotency - safe to retry
const charge = await activities.chargePaymentGateway(orderId, paymentDetails);
// All subsequent steps guaranteed to complete
await activities.updateOrderStatus(orderId, 'paid');
await activities.sendReceipt(charge.receiptEmail);
await activities.updateInventory(orderId);
await activities.notifyFulfillment(orderId);
return charge;
}
Benefits:
- Idempotent payment charging (safe retries)
- Guaranteed order consistency
- Audit trail of all steps
- Handles slow or failing external APIs
Data Processing Pipelines
ETL and Data Migration
Scenario: Import large datasets from external sources:
- Fetch data from external API (paginated)
- Transform data format
- Validate each record
- Store in database
- Update search index
- Generate reports
With This Boilerplate:
export async function dataImportWorkflow(source: DataSource) {
const batches = await activities.fetchDataBatches(source);
for (const batch of batches) {
// Process each batch in parallel activities
await Promise.all([
activities.transformAndStore(batch),
activities.updateSearchIndex(batch),
activities.validateRecords(batch)
]);
}
await activities.generateReport(source);
}
Benefits:
- Resume from last successful batch on failure
- Parallel processing of batches
- Progress tracking in Temporal UI
- No data loss on crashes
Scheduled Tasks & Cron Jobs
Recurring Business Processes
Scenario: Daily/weekly/monthly automated tasks:
- Generate and email daily reports
- Clean up old records
- Sync data with external systems
- Send reminder emails
- Process subscriptions
With This Boilerplate:
// Schedule workflows using Temporal's cron support
export async function dailyReportWorkflow() {
const data = await activities.aggregateDailyStats();
const report = await activities.generateReport(data);
await activities.emailReport(report);
await activities.archiveOldReports();
}
// Worker registration with cron schedule
Worker.create({
workflowsPath: './workflows',
taskQueue: 'daily-tasks',
schedules: {
dailyReport: {
spec: { cronSchedule: '0 0 * * *' }, // Daily at midnight
workflow: dailyReportWorkflow
}
}
});
Benefits:
- Reliable execution even with server restarts
- Missed runs catch up automatically
- Easy schedule modifications
- Centralized monitoring
Microservices Orchestration
Complex Service Coordination
Scenario: Coordinate multiple microservices:
- Validate request across services
- Reserve resources in Service A
- Create record in Service B
- Update Service C
- Rollback if any step fails
With This Boilerplate:
export async function crossServiceWorkflow(request: OrderRequest) {
let reservation;
try {
// Validate across services
await activities.validateWithServiceA(request);
await activities.validateWithServiceB(request);
// Reserve resources
reservation = await activities.reserveResources(request);
// Create records
const recordB = await activities.createInServiceB(request);
await activities.updateServiceC(recordB.id);
return { success: true, recordId: recordB.id };
} catch (error) {
// Compensating actions (SAGA pattern)
if (reservation) {
await activities.releaseResources(reservation.id);
}
throw error;
}
}
Benefits:
- Built-in SAGA pattern support
- Automatic rollback handling
- Service failure isolation
- Complete audit trail
API Rate Limiting & Throttling
Managing External API Limits
Scenario: Integrate with external APIs that have rate limits:
- Third-party APIs: 100 requests/minute
- Need to process 10,000 items
- Must respect rate limits
- Handle API downtime gracefully
With This Boilerplate:
export async function bulkAPIWorkflow(items: Item[]) {
const batches = chunk(items, 90); // Stay under rate limit
for (const batch of batches) {
// Process batch
const results = await Promise.all(
batch.map(item => activities.processWithExternalAPI(item))
);
// Wait before next batch to respect rate limit
await sleep('1 minute');
}
return { processed: items.length };
}
Benefits:
- Automatic rate limit compliance
- Progress preserved across API failures
- Easy to adjust throttling
- No manual queue management
Long-Running Business Processes
Approval Workflows
Scenario: Multi-stage approval process:
- Submit request
- Wait for manager approval (hours/days)
- Wait for finance approval
- Wait for executive approval
- Execute approved action
- Send notifications
With This Boilerplate:
export async function approvalWorkflow(request: Request) {
// Submit request
await activities.createRequest(request);
// Wait for approvals (can take days)
const managerApproval = await signals.waitForManagerApproval();
if (!managerApproval.approved) {
return { status: 'rejected', reason: managerApproval.reason };
}
const financeApproval = await signals.waitForFinanceApproval();
if (!financeApproval.approved) {
return { status: 'rejected', reason: financeApproval.reason };
}
// Execute approved action
await activities.executeApprovedAction(request);
await activities.notifyAllParties(request);
return { status: 'approved' };
}
Benefits:
- Workflow can run for days/weeks/months
- State preserved across deployments
- Easy to add/modify approval stages
- Complete audit log
When to Use This Boilerplate
Ideal Scenarios
This boilerplate is perfect when you need:
-
Reliability is Critical
- Payment processing
- Financial transactions
- User onboarding
- Data migrations
-
Complex Orchestration
- Multiple external services
- Multi-step processes
- Saga patterns
- Long-running workflows
-
Scalability Required
- High traffic APIs
- Background job processing
- Microservices architecture
- Worker pools
-
Production-Ready from Day One
- Startup MVPs
- Enterprise applications
- SaaS platforms
- E-commerce backends
When to Consider Alternatives
This boilerplate might be overkill for:
- Simple CRUD applications with no background processing
- Static websites or content management
- Real-time chat applications (use WebSockets instead)
- Simple prototype/demo projects
Example Projects Built With This
Here are types of applications well-suited to this architecture:
-
E-commerce Platform
- Order processing workflows
- Payment handling
- Inventory management
- Email notifications
-
SaaS Application
- User onboarding
- Subscription management
- Billing workflows
- Feature provisioning
-
Financial Services
- Transaction processing
- Account reconciliation
- Fraud detection workflows
- Reporting pipelines
-
Healthcare Systems
- Patient onboarding
- Appointment workflows
- Insurance claim processing
- Compliance reporting
-
IoT Platforms
- Device provisioning
- Data collection workflows
- Alert processing
- Maintenance scheduling
Architecture Benefits
Why Temporal + Express?
Express.js: Handles HTTP requests synchronously
- Fast response times
- Traditional REST API
- Easy to understand
Temporal Workers: Handle background work asynchronously
- Durable execution
- Automatic retries
- Long-running processes
Best of Both Worlds:
- API responds immediately
- Work happens reliably in background
- Scale API and workers independently
Next Steps
- Quick Start - Build your first workflow
- Features - Explore all features