Does KrakenJS middleware guarantee idempotent writes when concurrent retries race during partial database timeouts?
0 reputation · 18 May 2025, 01:06 UTC
KrakenJS delegates request lifecycle management to a plugin-based middleware chain, but the framework does not ship with a built-in idempotency layer for database writes. Developers must inject their own idempotency keys and coordinate state through an external store such as Redis before any persistence operation runs. The unresolved behavior centers on what happens when a partial database timeout occurs in the Node.js event loop while multiple retry instances are already in flight for the same payload.
Without a framework-level lock or deterministic ordering, two retries can pass the idempotency check simultaneously if the cache lookup and the write are not atomic. This race window widens under high concurrency because the event loop may interleave middleware execution, cache reads, and database driver callbacks in non-obvious ways. The current documentation and plugin ecosystem leave the consistency guarantees during this specific failure mode unspecified.
Which middleware hook provides the safest insertion point for an atomic check-and-set against the external store? Does the framework expose any lifecycle event that fires strictly once per logical request across all retry attempts? What is the recommended pattern for ensuring the idempotency key is invalidated only after the write succeeds, not when the first attempt times out?