Hacker News new | ask | show | jobs
by c-fe 45 days ago
> Maybe it arrives while the first request is still running. Now your idempotency layer is part of your concurrency control.

I recently designed a system where this had to be taken into consideration. I find my solution very elegant: When the request arrives, I put the pending request into a map, keyed by the idempotenceId. This whole operation is executed in one step. Now the event loop may process other requests. If one of them has the same key, it will await the same response object from the store. And then, once i have the response, I resolve both promises with it.