Skip to main content

Scheduled Jobs That Overlap Their Own Retries: Retry Age, Occurrence Keys and Claims with Leases

If a nightly job's target is down at its scheduled time, when does EventBridge Scheduler stop trying, and what happens to the invocation afterward? Many teams never answer this, because the defaults seem to answer it for them. They do not answer it well: Scheduler's defaults were written for a generic target, not for the period of your job. The basics of context attributes, IAM roles and dead-letter queues are covered in EventBridge Scheduler Pitfalls: Context Attributes, Retries and Dead-Letter Design. This guide goes deeper on two decisions that post only touches: how long to retry, and how to make a retried occurrence safe.

The default retry window is longer than many job periods

By default, Scheduler keeps trying to deliver an event for 24 hours and up to 185 attempts, with exponential backoff between attempts. If you configure no dead-letter queue (DLQ), the event is dropped once the attempts run out. Delivery is at-least-once. Together these defaults have three consequences:

  • A daily job can still be retrying yesterday's occurrence when today's fires. That follows from the 24-hour default.
  • One occurrence can reach the target more than once, so the handler has to tolerate repeats.
  • An exhausted event leaves little trace without a DLQ. Scheduler publishes CloudWatch metrics for dropped invocations and for invocations sent to a dead-letter queue (for example InvocationDroppedCount), but you have to alarm on them yourself. Confirm the metric names in the current documentation.

The deciding question is how long a late run is still worth executing. For an hourly aggregation, a run six hours late may be useless or may collide with the next hour's run. For a monthly report, a day of retrying may be fine. The retry age should come from that business answer, and the default is only a ceiling.

Set the retry budget from the job's period

The retry policy has two settings: the maximum event age, which can range from 60 to 86,400 seconds, and the maximum retry attempts, up to 185. This target configuration is for an hourly job that is better dropped and recovered than retried for a day. The ARNs are placeholders and the numbers are illustrative, not recommendations.

{
  "Arn": "arn:aws:lambda:REGION:ACCOUNT:function:hourly-rollup",
  "RoleArn": "arn:aws:iam::ACCOUNT:role/scheduler-invoke-rollup",
  "Input": "{\"scheduleArn\":\"<aws.scheduler.schedule-arn>\",\"scheduledTime\":\"<aws.scheduler.scheduled-time>\"}",
  "RetryPolicy": {
    "MaximumEventAgeInSeconds": 1800,
    "MaximumRetryAttempts": 5
  },
  "DeadLetterConfig": {
    "Arn": "arn:aws:sqs:REGION:ACCOUNT:rollup-schedule-dlq"
  }
}
  • MaximumEventAgeInSeconds: 1800 stops retrying an occurrence before the next hour begins, so a stale attempt cannot overlap the next run's work.
  • MaximumRetryAttempts is deliberately small. With exponential backoff, the age limit may be reached before the count anyway, so test which limit actually ends the retries in your account.
  • DeadLetterConfig turns "dropped" into "parked". The queue must be a standard SQS queue, and the schedule's role needs sqs:SendMessage on it. Verify both against the current documentation.
  • Input carries the schedule ARN and scheduled time into the handler, which the next section depends on.

Key idempotency on the occurrence, not on the attempt

Scheduler can substitute context attributes into the target input. There are four, and they differ in what they identify:

Attribute Identifies Safe as an idempotency key?
Schedule ARNWhich scheduleYes, as part of the key
Scheduled timeThe time specified for the invocationYes, as part of the key
Execution IDEach attempted invocationNo: it may differ between attempts of one occurrence
Attempt numberWhich try this isNo: it changes by design

The documentation describes the execution ID as assigned for each attempted invocation, which does not settle whether it stays the same across retries of the same occurrence. If it changes, a dedupe check keyed on it accepts the duplicate. The schedule ARN plus the scheduled time names the occurrence itself, so that pair is the safer key. One thing to test rather than assume: what the scheduled time contains when a flexible time window is configured.

A claim needs a status and a lease, not just existence

The handler side is a conditional claim: before doing any work, insert a record keyed on schedule ARN plus scheduled time, and treat a duplicate-key failure as "someone has this". Any store with an atomic insert-if-absent works. The hazard is a crash after the claim: if the handler claims the key and dies, every retry sees the claim and skips the work, so the occurrence looks handled but never ran. The remedy is to give the claim a status and a lease time, so a retry can take over a stale claim. A SQL Server sketch:

CREATE TABLE dbo.JobClaims (
    ClaimKey    nvarchar(400) NOT NULL PRIMARY KEY,   -- scheduleArn + '|' + scheduledTime
    Status      varchar(12)   NOT NULL,               -- started | completed | failed
    LeaseUntil  datetime2     NOT NULL,
    UpdatedAt   datetime2     NOT NULL
);

-- 1) Try to claim: a duplicate-key error means another attempt already holds it
INSERT INTO dbo.JobClaims (ClaimKey, Status, LeaseUntil, UpdatedAt)
VALUES (@key, 'started', DATEADD(MINUTE, 10, SYSUTCDATETIME()), SYSUTCDATETIME());

-- 2) On duplicate key: take over only if the claim is stale and not completed
UPDATE dbo.JobClaims
SET Status = 'started',
    LeaseUntil = DATEADD(MINUTE, 10, SYSUTCDATETIME()),
    UpdatedAt = SYSUTCDATETIME()
WHERE ClaimKey = @key
  AND Status <> 'completed'
  AND LeaseUntil < SYSUTCDATETIME();
-- one row affected: this attempt owns the work; zero rows: exit successfully

When the work finishes, set the status to completed so later attempts and replays exit immediately. The lease length is a trade-off: too short and two attempts can run at once, too long and a crashed run delays its own recovery. Choose it from the job's real duration, and recording the status also makes "claimed but never completed" a state you can query instead of a guess. This is the same reasoning that makes pipeline reruns safe by default: the guarantee has to live in the receiving code.

Flexible windows trade timing precision for load smoothing

Each schedule declares a flexible time window, either off or from 1 to 1,440 minutes, and the invocation happens at some point after the scheduled time within that window. It is useful when many schedules fire in the same minute against a shared dependency. It costs exact start times, and it interacts with the retry age: a 15-minute window followed by a 30-minute retry age may leave less retry time than the age setting suggests. Whether the age is measured from the scheduled time or from the actual dispatch is something to test, and until you have, assume the less generous reading.

A DLQ is only a recovery path if someone owns it

  • Who reads the queue? An unwatched DLQ is the silent drop with extra steps. Alarm on a message arriving, not on a slow growth in depth.
  • Is replaying safe? Replay works only if the handler is idempotent on the occurrence key. Otherwise the DLQ is a hazard, not a safety net.
  • Do the layers stack retries? Scheduler's retries cover failures to deliver the invocation. For a Lambda target, a function that throws is also subject to Lambda's own asynchronous retries, which default to two more attempts. Attempts multiply across layers instead of adding, so pick one layer to own the policy.

Checks before trusting a schedule

  1. Write down the latest time a late run is still useful, and set the maximum event age below it.
  2. Make the handler idempotent on schedule ARN plus scheduled time, and prove it by invoking the same payload twice.
  3. Test the crash-after-claim case: kill the handler mid-run and confirm a retry takes over once the lease expires.
  4. Force a failure in a non-production account and watch where the invocation ends up, with and without a DLQ.
  5. Check in your own account whether the execution ID changes across retries, and what the scheduled time holds under a flexible window.
  6. Alarm on the dropped and dead-letter metrics, and confirm the alarm fires during the forced failure.

Where to stay cautious

Defaults and limits change, so recheck the current Scheduler documentation for retry settings and context attributes before copying any numbers. Three points in this guide are deliberately framed as things to test: whether the execution ID is stable across retries, what the scheduled time holds under a flexible window, and how the retry age interacts with the window. The recommendation is narrow: for any recurring schedule, set the retry age from the job's period, attach a DLQ someone actually reads, and key the claim on the occurrence with a status and a lease.

Comments