Skip to content

Commit cd90fc1

Browse files
committed
chore(documentation): replace idempotency diagrams with mermaid.js
1 parent 975933d commit cd90fc1

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

docs/media/idempotent_sequence.png

-72.9 KB
Binary file not shown.
-45.6 KB
Binary file not shown.

docs/utilities/idempotency.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,31 @@ Imagine the function executes successfully, but the client never receives the re
355355

356356
This sequence diagram shows an example flow of what happens in the payment scenario:
357357

358-
![Idempotent sequence](../media/idempotent_sequence.png)
358+
<center>
359+
```mermaid
360+
sequenceDiagram
361+
participant Client
362+
participant Lambda
363+
participant Persistence Layer
364+
alt initial request:
365+
Client->>Lambda: Invoke (event)
366+
Lambda->>Persistence Layer: Get or set (id=event.search(payload))
367+
activate Persistence Layer
368+
Note right of Persistence Layer: Locked during this time. Prevents multiple<br/>Lambda invocations with the same<br/>payload running concurrently.
369+
Lambda-->>Lambda: Run Lambda handler (event)
370+
Lambda->>Persistence Layer: Update record with Lambda handler results
371+
deactivate Persistence Layer
372+
Persistence Layer-->>Persistence Layer: Update record with result
373+
Lambda--xClient: Response not received by client
374+
else retried request:
375+
Client->>Lambda: Invoke (event)
376+
Lambda->>Persistence Layer: Get or set (id=event.search(payload))
377+
Persistence Layer-->>Lambda: Already exists in persistence layer. Return result
378+
Lambda-->>Client: Response sent to client
379+
end
380+
```
381+
<i>Idempotent sequence</i>
382+
</center>
359383

360384
The client was successful in receiving the result after the retry. Since the Lambda handler was only executed once, our customer hasn't been charged twice.
361385

@@ -367,7 +391,23 @@ The client was successful in receiving the result after the retry. Since the Lam
367391
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**.
368392
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.
369393

370-
![Idempotent sequence exception](../media/idempotent_sequence_exception.png)
394+
<center>
395+
```mermaid
396+
sequenceDiagram
397+
participant Client
398+
participant Lambda
399+
participant Persistence Layer
400+
Client->>Lambda: Invoke (event)
401+
Lambda->>Persistence Layer: Get or set (id=event.search(payload))
402+
activate Persistence Layer
403+
Note right of Persistence Layer: Locked during this time. Prevents multiple<br/>Lambda invocations with the same<br/>payload running concurrently.
404+
Lambda--xLambda: Run Lambda handler (event).<br/>Raises exception
405+
Lambda->>Persistence Layer: Delete record (id=event.search(payload))
406+
deactivate Persistence Layer
407+
Lambda-->>Client: Return error response
408+
```
409+
<i>Idempotent sequence exception</i>
410+
</center>
371411

372412
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.
373413

tests/functional/event_handler/test_api_gateway.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def test_base64_encode():
283283

284284
@app.get("/my/path", compress=True)
285285
def read_image() -> Response:
286-
return Response(200, "image/png", read_media("idempotent_sequence_exception.png"))
286+
return Response(200, "image/png", read_media("tracer_utility_showcase.png"))
287287

288288
# WHEN calling the event handler
289289
result = app(mock_event, None)

0 commit comments

Comments
 (0)