If your code depends on a database, an external service, or a specific set of permissions — verify those conditions the moment the process boots up. If something is missing or misconfigured, crash immediately.
Do not let the process ‘limp’ forward only to die 2 hours into a run because some credentials were missing. This pattern is called fail-fast, and it is one of the simplest, highest-leverage practices that should always be followed.
Here are a few things to check on startup
- can you reach the database?
- do env vars exist and are they non-empty?,
- do you have the permissions you need?
- are the downstream services reachable?
None of this is complex to write. A few checks and guard clauses at the top of your main function are all it takes. When your code does crash mid-run, it should be because something genuinely unexpected happened — not because a config value was missing (fixable issues).
Late crashes from fixable issues are not just a waste of time. I have followed this since my very first job, and it has saved me countless hours :)
Hope this helps.