Idempotent
Marker for steps that are safe to retry (idempotent operations).
When marked idempotent, the saga executor knows the step can be safely retried without side effects if execution fails and is restarted.
Idempotency
An operation is idempotent if it produces the same result when executed multiple times. Examples:
Idempotent: Setting a value, deleting a resource, querying data
Not idempotent: Incrementing a counter, creating a new resource, charging payment
Usage Example
@Idempotent
fun updateOrderStatus(orderId: String, status: String) {
// This operation is idempotent - calling it multiple times
// with the same parameters produces the same result
orderRepository.setStatus(orderId, status)
}
saga.step("update-status") { context ->
updateOrderStatus(context.orderId, "CONFIRMED")
}
.idempotent(true) // Mark as idempotent at runtimeContent copied to clipboard
Runtime Marking
Steps can be marked idempotent at runtime using the idempotent() DSL method:
step("set-status") { context ->
statusService.set(context.orderId, "PROCESSING")
}
.idempotent(true)Content copied to clipboard
Since
1.0.0