Description
Is your feature request related to a problem? Please describe.
In the Account Security team at Booking, we rely on the Java Powertools library's idempotency support to manage both idempotent and non-idempotent downstream API calls. This functionality is crucial for ensuring that our security remediations are executed without unintended duplication or unnecessary load on our systems.
However, there is currently no mechanism to distinguish between a regular response and one that has been cached and returned by the Powertools library. While this behavior is technically correct and functions as intended, it presents a challenge when it comes to accurately tracking business metrics. Specifically, if we are unable to differentiate between regular and cached responses, our count of successful executions becomes inaccurate. This discrepancy impacts our projects on a business level, as we depend on these metrics to monitor key goals and milestones effectively.
Describe the solution you'd like
We propose two potential solutions, in decreasing order of preference:
- Callback Method for Response Manipulation: Introduce support for manipulating responses through a callback method during idempotency configuration. This would allow us to modify the response object to include additional information indicating whether it was served from cache.
Idempotency.config().withPersistenceStore(
DynamoDBPersistenceStore.builder()
.withTableName(System.getenv("TABLE_NAME"))
.withEventHandler(subscriptionResult -> {
return new SubscriptionResult(subscriptionResult.getPaymentId(), "noop", 200);
})
.build()
).configure();
- Key-Value Pair in Cached Responses: Allow the specification of a key-value pair that would be appended to cached responses. This would provide a straightforward way to identify cached responses in our metrics.
Idempotency.config().withPersistenceStore(
DynamoDBPersistenceStore.builder()
.withTableName(System.getenv("TABLE_NAME"))
.withCachedResponseKey("x-idempotent-key")
.withCachedResponseValue("true")
.build()
).configure();
Implementing either of these solutions would bring the Java implementation in line with the capabilities already available in the Python version of Powertools, which supports response manipulation as documented here: Powertools Python Documentation.
Describe alternatives you've considered
-
Moving the
@Idempotent
Annotation: Shifting the annotation to a secondary method rather than the handler method was deemed unviable, as idempotency execution is independent of the method itself. -
Custom Idempotency Annotation: Creating a custom annotation that inherits from Powertools was rejected due to the increased complexity in maintenance and the need to track upstream changes continuously.
-
Implementing Functionality In-House: Developing similar functionality within our project using DynamoDB would lead to duplication of existing features and an increased maintenance burden, which we aim to avoid.
Metadata
Metadata
Assignees
Type
Projects
Status