done async-request-processor task#252
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your solution is approved because it correctly implements asynchronous request processing with CompletableFuture, uses a thread-safe ConcurrentHashMap cache, and returns cached results when the same userId is requested again. The processRequest(String userId) method in AsyncRequestProcessor meets the requirements by simulating a delay in fetchUserData, populating the cache after processing, and returning CompletableFuture<UserData> so multiple requests can run concurrently. It’s also a nice touch that you added an in-flight map to deduplicate concurrent requests for the same userId, which avoids doing the same work twice under load. One minor improvement would be in Main.java near the end of main, where after calling executor.shutdown() you could also wait for termination (for example with awaitTermination) to make shutdown behavior more robust in different environments. Another small consideration is that, because of true concurrency, the order of printed results may differ from the example; if you ever need deterministic ordering, you could collect the futures and print the results in the original input order using join(). Overall, you’ve satisfied the functional requirements and demonstrated solid use of async patterns and caching—well done.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
This implementation uses request coalescing to prevent duplicate concurrent calls for the same key.
It maintains a cache for completed results and an in-flight map to deduplicate ongoing requests.
Asynchcronous execution is handled via a custom executor, and completed results ae cached for fast subsequent access.
In-flight entries are cleaned up after completion to avoid memory leaks.