5 ms·
I agree with most of that list - except for cron. Cron jobs are the definition of the anti pattern of treating servers like pets and not cattle. You have to wo
by scarface74 8y ago
I agree with most of that list - except for cron.
Cron jobs are the definition of the anti pattern of treating servers like pets and not cattle. You have to worry about that one non redundant server running your cron jobs. There are others ways to skin the cat, but my favorite is Hashicorp’s Nomad. I like to call it “distributed cron”. Together with Consul for configuration it’s dead simple to schedule jobs across app servers - the jobs can be executables, Docker containers, shell scripts, anything.
- natdempk 8y agoI agree that is definitely the way to go at some scale. :) I really just put cron on there as an example of how someone might think about scheduled jobs as most of the more advanced things are conceptually similar to cron, but where you don't have to worry about where your job is actually running and how the environment was setup. I think it is worth noting for any of the systems above that there's a spectrum of possibilities around how much you automate/offload the management of them, as well as plenty of backend systems for managing those.
- freedomben 8y agoThese days I think of "cron" as more of a type than an actual implementation. When somebody says, "I need a cron job" my answer these days would never be, "ssh into www1 and add it to the crontab." It would be, "create a CronJob type in Kubernetes." But I agree and concede, a user with zero back-end experience will just google "cron" which will take them to a crontab example, so they will likely be mislead into the anti-pattern, as you said.
- whalesalad 8y agoIt's just as important to understand the history/genesis of cron as it is to know when to not use it.
- gravypod 8y ago> Cron jobs are the definition of the anti pattern of treating servers like pets and not cattle What's old is new again. Much of clean distributed systems development is now built on, what is essentially, scheduled period operations. They're pretty much the least complicated ways to loosely couple domain logic in distributed systems that follow eventually-consistent semantics. They're also a good model for the functionality of many distributed scheduling systems like Kubernetes, AWS' ECS Scheduled Tasks, and more. Kubernetes even goes so far to have Jobs (batch operations) and CronJobs (scheduler that creates Jobs).
- scarface74 8y agoI use AWS’s native services most of the time like CloudWatch to schedule jobs, lambdas, and step functions these days, but to keep the post generic, I mentioned Nomad/Consul that I have used in the past for an on prem implementation that kept us from having to bring Docker into the mix. Since we were already using Consul, using Nomad just made sense.
- hestefisk 8y agoDepends on the use case / workload.
- igotsideas 8y agoStill good to know for legacy fixes.
- zwetan 8y agodoesn't work when you can not access the machine where the cron is supposed to run for security reason or whatever there crontab is not an anti-pattern at all
- scarface74 8y agoWhat does not having access to the server have anything to do with using a fault tolerant solution?
- sl1ck731 8y agoThat is only true if your jobs aren't doing a stateless operation. I use cron all the time on cattle VMs. No reason to cargo cult extra stuff into the mix.
- scarface74 8y agoUntil that one server goes down in the middle of the night or it has issues. Or if the server doesn’t go down and your cron job fails. Do you then implement retry logic in every job since cron can’t do retries automatically?
- kiallmacinnes 8y agoI think the parent poster was referring to the fact that Cron jobs can act purely on local state, and that's OK. For example, if I had a traditionally deployed (i.e. not in K8S / a PaaS / similar) backend app that accepted file uploads, then passed those off to something else, I'd be streaming the uploads to a temporary holding directory on disk. I'd then have a CronJob that clears stale items from the temp dir. If the server fails, that's OK that the CronJob didn't run. There are still plenty of use cases for traditional cron.
- C1sc0cat 8y agoYes jobs that run unattended via chron should have logging and watch dog processes that check for completion and possibly do reconciliation - that can alert if something goes wrong and the logs help diagnosis.
- scarface74 8y agoNow you’re reinventing Nomad....
- coldtea 8y ago>Until that one server goes down in the middle of the night or it has issues. The extra complexity of any workflow manager would make it even more certain to "goes down in the middle of the night or have issues".
- sudhirj 8y agoLearning the cron format is still necessary / useful - most distributed deployment systems have some form of schedule job running. Even on a purely serverless model like AWS Lambda, it’s still possible to do distributed crons. I actually think the word ‘cron’ has already been repurposed - when using it my team actually refers to the distributed version, not the per server version.
- roadbeats 8y agoHey - why not just systemctl ? It’s quite robust and reliable.
- coldtea 8y ago>Cron jobs are the definition of the anti pattern of treating servers like pets and not cattle. Cron jobs are the definition of "if it works don't fix it" and YAGNI.
- scarface74 8y agoBut cron jobs don’t work when you need server redundancy or retry logic.
- coldtea 8y agoYes, but it's not like the original claim, that it's somehow totally "deprecated" today and people should skip it.
- scarface74 8y agoYeah because for me, anything that doesn’t have redundancy should be skipped.... Unless the cron job is only doing some type of maintenance that only affects the local redundant server....
- therealdrag0 8y agoThat's a common use case, log rotation, AV scan, etc. It's just a concept to be familiar with.
- felixgallo 8y agoThat’s not cron’s job. Different jobs have different requirements and tradeoffs. Ownership of retry logic and distribution design belongs with whatever cron kicked off.