Idempotency Keys
The primary way to ensure idempotency is by providing anX-Idempotency-Key (or Idempotency-Key) header when triggering a job.
How it Works
- When a trigger request includes an idempotency key, Strait checks if a run with the same
job_idandidempotency_keyalready exists. - If a match is found, Strait returns the details of the existing run instead of creating a new one.
- If no match is found, a new run is created and associated with that key.
Example
Payload-Based Deduplication
In addition to explicit keys, Strait can automatically deduplicate runs based on their payload content.Dedup Window
This is configured per-job via thededup_window_secs field. If set, Strait will look for any recent run (within the window) that has the exact same payload hash.
How it Works
- Strait canonicalizes the JSON payload and generates a SHA-256 hash.
- It searches for a run of the same job with the same payload hash within the configured
dedup_window_secs. - If found, it returns the existing run.
Implementation Details
- Database Index: Idempotency is enforced at the database level using a unique partial index on
(job_id, idempotency_key). - Canonicalization: Before hashing, payloads are unmarshaled and remarshaled to ensure that differences in whitespace or key order do not result in different hashes for the same logical data.