← Back to articles

Building Bulletproof Periodic Tasks

Most modern software systems require execution of periodic tasks.

For example, “Trigger generation of customer monthly invoices each 1st of month at 9AM”.

One venerable tool for handling that on Unix-like operating systems is cron, software that’s now 50 years old.

But these tasks can also be scheduled by Celery beat on Python stacks, Dagster orchestration jobs, or plenty of other solutions.

Here are two critical principles for creating reliable scheduled tasks.

Idempotency ♻️

Any periodic task should be designed to be relaunched multiple times without undesirable behaviour.

It implies enforcing these kinds of rules when interacting with external systems:

Most importantly, ensure the code does not crash or create multiple data records if executed multiple times.

Why is it useful? 🤔

Increased Execution Frequency 🚤

Any periodic task should be scheduled more frequently than necessary.

Of course it requires idempotency on these tasks.

For example, the task in charge of sending customer’s invoices could be run every day at 9AM instead of only the 1st of month.

Then, in normal circumstances, nothing will be done by the task except the 1st of month.

So, why do such a thing? 🤔

In practice, make sure these frequent executions do not involve a significant load of your system, nor create tons of unwanted logs.

Conclusion

By embracing both idempotency and increased execution frequency, you transform fragile scheduled tasks into resilient system components. These principles not only protect against infrastructure failures but also improve maintainability and reduce operational stress. Remember: the most reliable periodic tasks are those designed to gracefully handle the unexpected.