Skip to content

Commit a01a2d1

Browse files
committed
docs: moved expiration window to getting started; updated example to set to 24h
1 parent 4f3988a commit a01a2d1

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
@@ -319,6 +319,35 @@ We want to use `user_id` and `product_id` fields as our idempotency key. **If we
319319
--8<-- "examples/idempotency/src/working_with_payload_subset_payload.json"
320320
```
321321

322+
### Adjusting expiration window
323+
324+
!!! 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)."
325+
326+
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.
327+
328+
=== "Adjusting expiration window"
329+
330+
```python hl_lines="14"
331+
--8<-- "examples/idempotency/src/working_with_record_expiration.py"
332+
```
333+
334+
=== "Sample event"
335+
336+
```json
337+
--8<-- "examples/idempotency/src/working_with_record_expiration_payload.json"
338+
```
339+
340+
???+ important "Idempotency record expiration vs DynamoDB time-to-live (TTL)"
341+
[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.
342+
343+
We don't rely on DynamoDB or any persistence storage layer to determine whether a record is expired to avoid eventual inconsistency states.
344+
345+
Instead, Idempotency records saved in the storage layer contain timestamps that can be verified upon retrieval and double checked within Idempotency feature.
346+
347+
**Why?**
348+
349+
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.
350+
322351
### Lambda timeouts
323352

324353
!!! note "You can skip this section if you are using the [`@idempotent` decorator](#idempotent-decorator)"
@@ -802,39 +831,6 @@ This is a locking mechanism for correctness. Since we don't know the result from
802831

803832
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.
804833

805-
### Expiring idempotency records
806-
807-
!!! note "By default, we expire idempotency records after **an hour** (3600 seconds)."
808-
809-
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.
810-
811-
You can change this window with the **`expires_after_seconds`** parameter:
812-
813-
=== "Adjusting idempotency record expiration"
814-
815-
```python hl_lines="14"
816-
--8<-- "examples/idempotency/src/working_with_record_expiration.py"
817-
```
818-
819-
=== "Sample event"
820-
821-
```json
822-
--8<-- "examples/idempotency/src/working_with_record_expiration_payload.json"
823-
```
824-
825-
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).
826-
827-
???+ important "Idempotency record expiration vs DynamoDB time-to-live (TTL)"
828-
[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.
829-
830-
We don't rely on DynamoDB or any persistence storage layer to determine whether a record is expired to avoid eventual inconsistency states.
831-
832-
Instead, Idempotency records saved in the storage layer contain timestamps that can be verified upon retrieval and double checked within Idempotency feature.
833-
834-
**Why?**
835-
836-
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.
837-
838834
### Payload validation
839835

840836
???+ 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)