Nextjs sequential order of async api requests
Answered
Cape lion posted this in #help-forum
Cape lionOP
I have api endpoint to handle payment webhook requests. So it's multiple requests one by one which changes status of transaction and sometimes mine database updated in a wrong order. How it possible to ensure right order of requests in nextjs 13 ?
Answered by tafutada777
or KV(redis). even though Node.js is a single thread event loop, OS is multi threaded(multi core) and TCP/IP packets loss could happen. Plus, Node.js itself is actually multi threaded(OS thread) and DB side is also multi threaded.
5 Replies
where did you host? if it's Vercel, it could happen as multiple Lambada instances process requests in parallel. if it is a self-hosted single instance, most probably it is precessed sequentially. (but not guaranteed)
or u need a pub sub like Kafka
@tafutada777 where did you host? if it's Vercel, it could happen as multiple Lambada instances process requests in parallel. if it is a self-hosted single instance, most probably it is precessed sequentially. (but not guaranteed)
Cape lionOP
yes vercel but in my local machine it's also not working even if make sync endpoint with promises. Sleep for few seconds kind of helps but not really good solution. And add kafka only for this purpose looks like overhead. So it's like really not exist simple solution for this problem?
or KV(redis). even though Node.js is a single thread event loop, OS is multi threaded(multi core) and TCP/IP packets loss could happen. Plus, Node.js itself is actually multi threaded(OS thread) and DB side is also multi threaded.
Answer
Cape lionOP
eh ok ll try vercel KV, thank you ðŸ™