Process a queue of items on a recurring schedule — daily reconciliation, weekly reports, hourly sync jobs. The workhorse pattern for routine data processing.
Rendering diagram…
Use a scheduled batch processor when:
| Phase | Description |
|---|---|
| Trigger | Schedule fires (e.g., daily at 6 AM) |
| Fetch | Query for unprocessed items (status = "pending") |
| Process | Loop through items, applying business logic to each |
| Update | Mark each item as processed/failed |
| Report | Generate a summary of what was processed |
| Parameter | Example | Notes |
|---|---|---|
| Frequency | Daily at 6:00 AM UTC | Use UTC to avoid DST issues |
| Batch size | 100 items per run | Prevents timeout on large queues |
| Scope query | WHERE status = 'pending' AND created_on < NOW() - INTERVAL 1 HOUR | Only process items older than 1 hour (avoids race conditions) |
Query your data source for items to process:
For each item in the batch:
After the loop completes:
At the end of each run, produce a report:
| Metric | Value |
|---|---|
| Total processed | 95 |
| Successful | 90 |
| Failed | 3 |
| Skipped (already done) | 2 |
| Duration | 4m 32s |
| Next scheduled run | Tomorrow 6:00 AM |
Send this summary to the operations team or write it to a log.
Never let two instances of the same batch job run simultaneously. Use a lock mechanism: check for a running instance before starting, and always release the lock when done (even on failure).
Split a workload into parallel branches, process them simultaneously, then aggregate the results. Dramatically reduces processing time for batch operations.