Scheduled Job Pattern
What you'll learn: How to automatically trigger serverless functions at regular intervals to perform routine tasks without provisioning or managing servers.
The Core Idea
The Scheduled Job Pattern uses time-based triggers (cron expressions or rate intervals) to invoke serverless functions automatically. Think of it like setting an alarm clock for your cloud infrastructure—instead of servers running continuously waiting for work, functions "wake up" only when scheduled, execute their task, then shut down.
This pattern is ideal for:
- Batch processing: Nightly report generation or data exports
- Cleanup tasks: Deleting expired records, archiving logs, or purging temp files
- Data aggregation: Hourly metrics rollup or daily analytics summaries
- Health checks: Periodic validation of system state or external dependencies
How It Works
Cloud providers offer scheduling services that integrate with serverless functions. You define a schedule (e.g., "every hour" or "daily at 2 AM"), and the platform automatically invokes your function at those times. The function runs, performs its work, and terminates—you pay only for execution time.
Unlike traditional cron jobs running on dedicated servers that consume resources 24/7, scheduled serverless functions are truly ephemeral. There's no server to patch, no capacity to plan for off-peak hours.
Example Use Cases
A cleanup function might run nightly to delete user sessions older than 30 days. A data aggregation function could execute every 15 minutes to compute rolling averages from streaming data and write summaries to a database. A backup validation function might trigger weekly to verify backup integrity.
Key Takeaway: The Scheduled Job Pattern enables time-based automation in serverless architectures, executing functions on a predictable schedule for batch work, maintenance, and periodic processing without any always-on infrastructure.