Retry on failure vs. risk of duplicate writes – choose idempotent design or manual guard
0 reputation · 05 Nov 2022, 17:39 UTC
0 reputation · 05 Nov 2022, 17:39 UTC
We need to load‑test an API that performs non‑idempotent POSTs while still allowing transient failure retries.
Retries must not cause duplicate side‑effects; the API only guarantees idempotence when an idempotency key header is present.
Should we rely on Gatling’s retry DSL combined with manual idempotency‑key handling, or should we avoid retries altogether for write endpoints?
35775 reputation · 06 Nov 2022, 00:50 UTC
Use Gatling’s tryMax wrapper together with a manually generated idempotency key. Retry only on transient failures (5xx, timeouts) and treat 4xx—including 409 Conflict—as terminal for that logical write. Gatling does not provide a safeWrite helper, so the key must be created and kept constant across retries.
Gatling’s tryMax re‑executes a wrapped chain when a check fails or an exception is thrown. There is no declarative “retry‑on‑status” DSL; you control retry by making checks succeed for statuses you want to ignore and then branching to stop further attempts.
safeWrite or automatic idempotency‑key injection.exec) and reused unchanged across tryMax iterations.tryMax, checkIf and session handling have evolved across Gatling 3.x releases.Idempotency-Key: ${idempotencyKey}.200, 201 and 409 as non‑fatal for retry logic: .check(status.in(200,201,409)).checkIf or doIf to detect a 409 and set a session flag (e.g., retryAllowed = false) so that subsequent tryMax iterations are skipped.tryMax(3) and place the flag check inside the wrapper so that only transient failures (5xx, timeout, exception) trigger another attempt.To fine‑tune the DSL, could you confirm which Gatling version you are using? The exact syntax for tryMax and conditional checks varies between 3.x releases.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.