You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/utilities/idempotency.md
+27-32Lines changed: 27 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -316,41 +316,16 @@ To prevent extended failures, use **`register_lambda_context`** function from yo
316
316
317
317
### Handling exceptions
318
318
319
-
If you are using the `idempotent` decorator on your Lambda handler, any unhandled exceptions that are raised during the code execution will cause **the record in the persistence layer to be deleted**.
320
-
This means that new invocations will execute your code again despite having the same payload. If you don't want the record to be deleted, you need to catch exceptions within the idempotent function and return a successful response.
319
+
There are two failure modes that can cause new invocations to execute your code again despite having the same payload:
321
320
322
-
<center>
323
-
```mermaid
324
-
sequenceDiagram
325
-
participant Client
326
-
participant Lambda
327
-
participant Persistence Layer
328
-
Client->>Lambda: Invoke (event)
329
-
Lambda->>Persistence Layer: Get or set (id=event.search(payload))
330
-
activate Persistence Layer
331
-
Note right of Persistence Layer: Locked during this time. Prevents multiple<br/>Lambda invocations with the same<br/>payload running concurrently.
Lambda->>Persistence Layer: Delete record (id=event.search(payload))
334
-
deactivate Persistence Layer
335
-
Lambda-->>Client: Return error response
336
-
```
337
-
<i>Idempotent sequence exception</i>
338
-
</center>
321
+
***Unhandled exception**. We catch them to delete the idempotency record to prevent inconsistencies, then propagate them.
322
+
***Persistent layer errors**. We raise **`IdempotencyPersistenceLayerError`** for any persistence layer errors _e.g., remove idempotency record_.
339
323
340
-
If you are using `idempotent_function`, any unhandled exceptions that are raised _inside_ the decorated function will cause the record in the persistence layer to be deleted, and allow the function to be executed again if retried.
324
+
If an exception is handled or raised **outside** your decorated function, then idempotency will be maintained.
341
325
342
-
If an Exception is raised _outside_ the scope of the decorated function and after your function has been called, the persistent record will not be affected. In this case, idempotency will be maintained for your decorated function. Example:
**We will raise `IdempotencyPersistenceLayerError`** if any of the calls to the persistence layer fail unexpectedly.
352
-
353
-
As this happens outside the scope of your decorated function, you are not able to catch it if you're using the `idempotent` decorator on your Lambda handler.
0 commit comments