Urgent.News

What's breaking now, across thousands of outlets.

Tech

Your Serverless Cron Job Failed Silently at 3AM: Making Event-Driven Jobs Reliable

Moving scheduled tasks off a cron box and onto serverless functions solves the "one server, one crontab, one single point of failure" problem. It also introduces a quieter one: a job that used to fail loudly in a log you'd eventually read now fails silently, retries in ways you didn't design, and sometimes runs twice. The reliability work doesn't disappear when you delete the crontab — it moves…

When moving scheduled tasks to serverless functions, the problem of a single point of failure is replaced with a quieter one: jobs that fail silently and retry in unexpected ways. This shift introduces new challenges in ensuring reliable execution of event-driven jobs. To address this, three key aspects must be considered: delivery semantics, idempotency, and observability.

The delivery semantics of serverless events are typically at-least-once, meaning a job may be executed multiple times due to network issues or message redelivery. This is in contrast to exactly-once delivery, which is not commonly available in serverless environments. Consequently, jobs that modify state must be designed to handle duplicate executions safely. The code should assume that it will be invoked at least twice with identical input.

To make a job safe to run twice, the principle of idempotency is essential. This can be achieved by using an idempotency key, which is a stable identifier derived from the event data. The key is then checked against a durable record to determine if the job has already been processed. The idempotency key should be generated before the actual work is done, not during the function execution.

The practical implementation involves deriving the idempotency key from the event using a hashing function, such as SHA-256. The key is then used in an atomic check-and-set operation to mark the job as processed. If the job has already been executed, the function returns a "duplicate skipped" status. It is crucial that the check-and-set operation is atomic to prevent race conditions during concurrent retries.

In addition to idempotency, observability plays a vital role in detecting when a job fails to execute. Without proper observability, failures may go unnoticed until they cause downstream issues. A dead-letter queue (DLQ) can be used to handle failed jobs by capturing them and allowing for manual inspection or automated redelivery after a specified number of attempts.

However, a DLQ without active monitoring is ineffective. The depth of the DLQ should be monitored and set up with alerts to notify the team when a job is failing repeatedly, indicating a need for investigation and resolution. By implementing these measures, scheduled tasks can be reliably run in a serverless environment without the risk of silent failures or unnoticed errors.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Ghidra internals: Where are my logs ?

Ghidra uses the Apache Log4j logging library to store a lot of execution messages. Finding these logs can be quite tricky, especially if you launch Ghidra from a shell (using ghidraRun ) because no…

I got an email about resistance

  • Author received email criticizing writing style and admission of sadness about income loss.
  • Author aims to prevent career-ruining mistakes and influence system safely from power.

Apple tests Chinese memory chips

Apple is testing memory chips from China’s CXMT across its product lines, including iPhones and MacBooks, as global tech reckons with an AI-induced memory shortage.

Pytest Built-in Fixtures

As I've been onboarding to my new position, I've been reviewing some of my coworker's code. I learned that pytest 1) has some built-in fixtures, and 2) they are really useful!

Kernel prepatch 7.2-rc7

The 7.2-rc7 kernel prepatch is out for testing. It is still bigger than Linus would like, but he said nonetheless: " I don't currently see any value in delaying the 7.2 release, so I would expect that…

More from Sunday 9 August →