As engineers, we’re used to relying on cron jobs.
On a Linux VM, it’s simple you set your schedule, and it just works.
No surprises. No downtime.
But when you move to container-based or managed platforms like Azure App Service, that assumption breaks.
And I learned that the hard way.
⚙️ The Setup
I had a production app hosted on Azure App Service that performs periodic data scraping and stores results in a database.
To keep things clean, I wrote a simple job to delete old records every 24 hours.
Locally, everything worked perfectly.
The script executed on schedule and data cleanup was smooth.
But once I deployed it to Azure the cleanup stopped running entirely.
No errors. No logs. Nothing.
🔍 The Realization
After some debugging and reading through Microsoft docs, I realized what was happening under the hood.
Azure App Service is not a full-time virtual machine.
It’s a managed environment that runs web requests, not background processes.
When your app:
- doesn’t receive traffic for a while, or
- gets restarted for maintenance/scaling,
the process sleeps or restarts, killing any background loops or cron-like code inside the container.
So my cleanup logic, which relied on an infinite loop or scheduled timer inside the app, was silently dying.
🧩 Why Traditional Cron Doesn’t Work Here
On a VM or bare metal:
- The OS runs your cron jobs independently of your application process.
On Azure App Service:
- Your app container is the runtime.
- When it sleeps or recycles, anything “in-memory” (like a running thread) vanishes.
- There’s no system-level cron to rely on.
This is why background jobs inside App Service cannot be trusted for production-grade scheduling.
🚀 The Solution: Offload Scheduling to Logic Apps
Instead of forcing a “fake cron” in code, I decided to delegate scheduling to Azure itself.
Here’s what I did:
- Created a Logic App in the Azure Portal.
- Set a Recurrence trigger to run every 24 hours (in my time zone).
- Added an HTTP Action that calls my cleanup endpoint (
/cleanup) in the App Service. - Optionally, added a retry policy and an alert in case of failure.
Now Azure’s Logic App acts as a serverless scheduler, triggering cleanup on time even when my App Service instance is idle.
No infrastructure changes. No extra containers.
And most importantly, 100% reliability.
🧠 What I Learned
- Cron jobs inside containers or App Service apps aren’t reliable they depend on the runtime staying active.
- Azure App Service is great for web apps, not background daemons.
- Use Logic Apps, WebJobs, or Azure Functions (Timer Triggers) for anything time-based or recurring.
- In cloud-native systems, separation of concerns is key let your app handle business logic, and the platform handle scheduling.
🔄 If You’re on AWS…
The equivalent solution would be:
- AWS Lambda for your cleanup logic
- EventBridge (Scheduled Rule) for the recurring trigger
Both achieve the same goal: reliable, event-driven cleanup outside the main app runtime.
✅ Final Thoughts
This small incident was a great reminder that “cloud ≠ VM.”
Just because something runs perfectly on a local Linux cron doesn’t mean it’ll behave the same in a managed platform.
Understanding how your platform schedules, scales, and sleeps is just as important as writing the logic itself.
In my case, switching to a Logic App made the system simpler, cheaper, and more reliable a true cloud-native win. 🌩️
Top comments (2)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.