Scheduled and Event-Driven Compute
Work that runs because of time or events
Not all compute runs on demand. Scheduled compute (cron in the cloud), event-driven trigger patterns, and instance scheduling save money and remove manual 'run the job' ops work.
What you will learn
- Explain scheduled vs event-driven compute
- Use Scheduler/EventBridge/Trigger to start work
- Design idempotent scheduled jobs
Cloud schedulers fire on cron (Cloud Scheduler, Azure Scheduler-like triggers) and event bus triggers react to resource changes (EventBridge, CloudEvents). The compute they start — VM, container, function — should be idempotent and bounded.
What is this?
Time-triggered: AWS EventBridge Scheduler, Azure Logic Apps/Scheduler triggers, GCP Cloud Scheduler (cron on UTC). Event-triggered: EventBridge CloudTrail/Service events, Azure Event Grid, GCP Pub/Sub → Cloud Functions/Workflows. Compute options ranged from stopping instances off-hours (a schedule) to rebuilding indexes when a file is dropped (an event). Also start/stop instance schedules to kill idle VM spend.
Why do you need it?
- Schedules make humans optional for recurring chores (backups, report gen, dusk starts).
- Event triggers react in milliseconds vs polling minute-level crons.
- Stopping dev instances off-hours is a free 60-70% compute saving.
- Distributed triggers decouple producers from consumers cleanly.
Mental model
Alarm clock vs answering a phone call
Scheduled vs event-driven compute
An alarm fires at a set time (schedule) whether or not anything's happening outside; the phone rings precisely when someone calls (event) — you react to what actually arrived.
How it works
- Scheduler: cron expression → message to a compute target (invoke function, run task, emit event).
- Cloud Scheduler/EventBridge hold timezone, retry and dead-letter config per schedule.
- Event bus: resources emit events (object create, instance state change, commit) that rules route to targets.
- EventGrid/PubSub deliver with at-least-once semantics → consumers must be idempotent.
- Instance schedules (AWS Instance Scheduler, Azure Auto-shutdown, GCP Cron stop) implement off-hour stop/start.
Time and event triggers.
Examples
Schedule and event triggers
# GCP: run a job at 2am UTC every daygcloud scheduler jobs create http nightly --schedule="0 2 * * *" \ --uri=https://us-central1-myproj.cloudfunctions.net/nightly \ --time-zone=UTC# AWS: react to an S3 object creationaws events put-rule --name on-upload --event-pattern \ '{"source":["aws.s3"],"detail-type":["Object Created"]}' \ --schedule-expression "rate(5 minutes)"Time-based jobs and event-driven jobs are configured declaratively and invoke compute automatically.
In production
- Nightly log-archive job runs 1am via Cloud Scheduler, purging 30-day logs and refreshing a dashboard.
- An object-creation event triggers a thumbnail ECS task when designers upload to the bucket.
- AWS Instance Scheduler stops 200 non-prod instances at 7pm and starts them 8am, saving most of the estate's dev bill.
Best practices
- Make scheduled jobs idempotent: a late run must not duplicate effects.
- Give every schedule a timezone (UTC) and a retry policy with DLQ.
- Watch event semantics: at-least-once means dedupe with object ids/keys.
- Put scheduled compute behind a budget alarm so a runaway cron bills loudly early.
Common mistakes
- Timezone confusion: a '9am' job fires at 9am UTC, not local.
- Non-idempotent jobs double-run after a retry (backups overwrite or duplicate).
- Polling instead of events: 60/s polls burning compute while events would react instantly.
- Forgetting to stop instance schedules in the same timezone/region — in-flight confusion.
Common issues
Nightly job ran twiceRetry + non-idempotent logic
Guard the job with a dedup key (run date), and make the payload a no-op when already executed.
Off-hour stop didn't fireScheduler timezone vs instance region mismatch
Standardize all schedules to UTC and apply stop/start in the instance's region.
Debugging tips
- Watch scheduler logs for 'triggered but target failed', not just target errors.
- Dead-letter queues capture events the rule couldn't route — check them first.
- For off-hour stop/start issues, verify the schedule matches the instance timezone and the region's utc offset.
- Add an execution-timestamp tag to scheduled jobs so a rerun is detectable.
Interview checkpoint
Quick quiz
Why must event-driven consumers be idempotent?