Skip to content

Commit 5807a1f

Browse files
committed
docs: moved expiration window to getting started; updated example to set to 24h
1 parent 51a7af7 commit 5807a1f

File tree

2 files changed

+30
-34
lines changed

2 files changed

+30
-34
lines changed

docs/utilities/idempotency.md

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,35 @@ Imagine the function runs successfully, but the client never receives the respon
300300
--8<-- "examples/idempotency/src/working_with_payload_subset_payload.json"
301301
```
302302

303+
### Adjusting expiration window
304+
305+
!!! note "We expire idempotency records after **an hour** (3600 seconds). After that, a transaction with the same payload [will not be considered idempotent](#expired-idempotency-records)."
306+
307+
You can change this expiration window with the **`expires_after_seconds`** parameter. There is no limit on how long this expiration window can be set to.
308+
309+
=== "Adjusting expiration window"
310+
311+
```python hl_lines="14"
312+
--8<-- "examples/idempotency/src/working_with_record_expiration.py"
313+
```
314+
315+
=== "Sample event"
316+
317+
```json
318+
--8<-- "examples/idempotency/src/working_with_record_expiration_payload.json"
319+
```
320+
321+
???+ important "Idempotency record expiration vs DynamoDB time-to-live (TTL)"
322+
[DynamoDB TTL is a feature](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/howitworks-ttl.html){target="_blank"} to remove items after a certain period of time, it may occur within 48 hours of expiration.
323+
324+
We don't rely on DynamoDB or any persistence storage layer to determine whether a record is expired to avoid eventual inconsistency states.
325+
326+
Instead, Idempotency records saved in the storage layer contain timestamps that can be verified upon retrieval and double checked within Idempotency feature.
327+
328+
**Why?**
329+
330+
A record might still be valid (`COMPLETE`) when we retrieved, but in some rare cases it might expire a second later. A record could also be [cached in memory](#using-in-memory-cache). You might also want to have idempotent transactions that should expire in seconds.
331+
303332
### Lambda timeouts
304333

305334
???+ note
@@ -773,39 +802,6 @@ This is a locking mechanism for correctness. Since we don't know the result from
773802

774803
When enabled, the default is to cache a maximum of 256 records in each Lambda execution environment - You can change it with the **`local_cache_max_items`** parameter.
775804

776-
### Expiring idempotency records
777-
778-
!!! note "By default, we expire idempotency records after **an hour** (3600 seconds)."
779-
780-
In most cases, it is not desirable to store the idempotency records forever. Rather, you want to guarantee that the same payload won't be executed within a period of time.
781-
782-
You can change this window with the **`expires_after_seconds`** parameter:
783-
784-
=== "Adjusting idempotency record expiration"
785-
786-
```python hl_lines="14"
787-
--8<-- "examples/idempotency/src/working_with_record_expiration.py"
788-
```
789-
790-
=== "Sample event"
791-
792-
```json
793-
--8<-- "examples/idempotency/src/working_with_record_expiration_payload.json"
794-
```
795-
796-
This will mark any records older than 5 minutes as expired, and [your function will be executed as normal if it is invoked with a matching payload](#expired-idempotency-records).
797-
798-
???+ important "Idempotency record expiration vs DynamoDB time-to-live (TTL)"
799-
[DynamoDB TTL is a feature](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/howitworks-ttl.html){target="_blank"} to remove items after a certain period of time, it may occur within 48 hours of expiration.
800-
801-
We don't rely on DynamoDB or any persistence storage layer to determine whether a record is expired to avoid eventual inconsistency states.
802-
803-
Instead, Idempotency records saved in the storage layer contain timestamps that can be verified upon retrieval and double checked within Idempotency feature.
804-
805-
**Why?**
806-
807-
A record might still be valid (`COMPLETE`) when we retrieved, but in some rare cases it might expire a second later. A record could also be [cached in memory](#using-in-memory-cache). You might also want to have idempotent transactions that should expire in seconds.
808-
809805
### Payload validation
810806

811807
???+ question "Question: What if your function is invoked with the same payload except some outer parameters have changed?"

examples/idempotency/src/working_with_record_expiration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
persistence_layer = DynamoDBPersistenceLayer(table_name=table)
1212
config = IdempotencyConfig(
1313
event_key_jmespath="body",
14-
expires_after_seconds=5 * 60, # 5 minutes
14+
expires_after_seconds=24 * 60 * 60, # 24 hours
1515
)
1616

1717

0 commit comments

Comments
 (0)