Repository navigation
Feature request: Priming for powertools-idempotency #1997
Description
Activity
- added a parent issue
on Aug 4, 2025 - addedgood-first-issueGood for newcomersGood for newcomersand removed
on Aug 4, 2025 Hey @phipag!
I've been looking into this issue and went through the PR #1861 to understand how the priming was implemented. Here's what I found and my plan to tackle this:
Current State
From what I can see, PR #1861 already implemented:
- Automatic priming for
powertools-metrics(the full class preloading flow) - Invoke priming for
powertools-idempotency-dynamodb(warm-up calls to DynamoDB)
The infrastructure is solid -
ClassPreLoaderinpowertools-commonis reusable and the pattern inMetricsFactoryis pretty clean.What's Missing
For
powertools-idempotency-core, we still need the automatic priming (class preloading). The invoke priming checkbox is marked as done, so I'm assuming we only need the automatic part here.Implementation Plan
Following the same pattern from
MetricsFactory, here's what I'm thinking:-
Add CRaC dependency to
powertools-idempotency-core/pom.xml<dependency> <groupId>org.crac</groupId> <artifactId>crac</artifactId> </dependency>
-
Add Maven profile for class loading generation
<profile> <id>generate-classesloaded-file</id> <!-- same pattern as metrics module --> </profile>
-
Modify
Idempotency.javato implementResource:- Add static
INSTANCEfield - Register with
Core.getGlobalContext().register(INSTANCE)in static block - Implement
beforeCheckpoint()→ callgetInstance()+ClassPreLoader.preloadClasses() - Implement empty
afterRestore()
- Add static
-
Generate and cleanup
classesloaded.txt:- Run
mvn -Pgenerate-classesloaded-file clean test - Clean up with the regex patterns from
Priming.md - Place in
src/main/resources/classesloaded.txt
- Run
Questions
- Does this approach sound right, or am I missing something?
- The
Idempotencyclass uses the holder pattern for singleton - should I create the static instance for CRaC registration similarly to how it was done inMetricsFactory? - Any specific test scenarios you'd like me to cover?
Let me know if this looks good and if you need help implementing this! Happy to open a PR if you're cool with the approach.
- Automatic priming for
Hey @dcabib,
thanks for proposing to work on this. Feel free to give this a go. The high-level plan sounds about right. You can follow the similar approach like in the MetricsFactory case and these two other PRs:
- feat(crac): Support CRaC and priming of powertools tracing #2345
- feat: add CRaC priming support to powertools-kafka module #2145
Regarding testing: If you can, it would be great if you can test to deploy an example Lambda in your AWS account and double-check if the snapstart hooks run. For example, you can print a line from the hooks and verify in cloudwatch logs that it exists for a snapstart enabled lambda function.
I assigned this issue to you. Let me know if new questions come up in the meantime.
Hey @phipag,
I've completed the automatic priming implementation for powertools-idempotency and wanted to clarify the scope before opening a PR.
What I Implemented
I implemented automatic priming in
powertools-idempotency-dynamodb(specifically inDynamoDBPersistenceStore.java), following the pattern from PR #2145 (Kafka) and PR #2345 (Tracing):Changes:
- ✅ Added
powertools-commondependency topowertools-idempotency-dynamodb/pom.xml - ✅ Added Maven profile
generate-classesloaded-file - ✅ Modified
DynamoDBPersistenceStore.javato callClassPreLoader.preloadClasses()in existingbeforeCheckpoint()hook - ✅ Generated
classesloaded.txt(8,726 classes including 47 from idempotency-core) - ✅ Added unit tests for CRaC hooks
Potential Discrepancy
In my initial comment on this issue, I proposed implementing automatic priming in
powertools-idempotency-core(modifyingIdempotency.java), similar to howMetricsFactoryworks in the metrics module.However, looking at the reference PRs you mentioned:
- PR feat: add CRaC priming support to powertools-kafka module #2145 (Kafka): Implemented priming in
PowertoolsSerializer(single module, no sub-modules) - PR feat(crac): Support CRaC and priming of powertools tracing #2345 (Tracing): Implemented priming in
TracingUtils(single module) - PR feat: Support CRaC and priming of powertools metrics and idempotency-dynamodb #1861 (Metrics): Implemented priming in
MetricsFactory(single module)
The idempotency module is different - it has two sub-modules:
powertools-idempotency-core(interfaces, base classes)powertools-idempotency-dynamodb(concrete DynamoDB implementation)
Question
Should automatic priming be implemented in:
Option 1: Only in
powertools-idempotency-dynamodb(what I implemented)- ✅ Follows the pattern of PR feat: Support CRaC and priming of powertools metrics and idempotency-dynamodb #1861 where invoke priming was added to
DynamoDBPersistenceStore - ✅ The
classesloaded.txtin dynamodb module already includes all core classes (47 classes) - ✅ In production, users always need a concrete persistence implementation (DynamoDB)
- ✅ Avoids duplication
Option 2: Also in
powertools-idempotency-core(my initial proposal)- ✅ Would follow the singleton pattern like
MetricsFactory - ✅ More modular (core independent of specific implementation)
- ✅ Future-proof if other persistence implementations are added
- ❌ Potential duplication since dynamodb module already loads core classes
Which approach aligns with your vision for the module architecture?
Thanks for the guidance!
- ✅ Added
Hey @dcabib, Option 1 sounds good. Only add it in -dynamodb for now.
- added a commit that references this issue
on Feb 2, 2026
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsBacklog
Use case
PLEASE READ: Priming documentation: https://github.com/aws-powertools/powertools-lambda-java/blob/main/Priming.md
Parent issue: #1588
Sample PR: #1861
Java CRaC can be used to prime an application by implementing
beforeCheckpoint()andafterRestore()hooks in selected classes. When used with AWS Snapstart, thebeforeCheckpoint()hook runs before the memory snapshot is taken. This behavior can be leveraged to further reduce restore durations by pre-loading classes and calling commonly used code to incorporate this into the memory snapshot.classesloaded.txtfile, loads classes used at runtime into memoryThe goal of this issue is to implementing priming techniques for the
powertools-idempotencymodule.Solution/User Experience
Implement priming based on Priming Documentation (feel free to update documentation and suggest improvements):
Alternative solutions
Acknowledgment
Future readers
Please react with 👍 and your use case to help us understand customer demand.