202 accepted on API requests for nextjs13 help

Hi, I am building a website using nextjs13, prisma on an Aws ec2 container with docker. Whenever I test my website on production sometimes some API requests will return a 202 accepted status and those requests will never be processed. I’m assuming this is because the nextjs13 thread is busy handling other api requests or other cpu intensive tasks. Though the end points I have are not really cpu intensive. I was wondering if you guys think the solution is a combination of a horizontal scaling of the nextjs containers and perhaps the offloading of some of the api work to a job queue or is there something im missing? Thank you, help would be very very much appreciated.
2 Replies
webdevkaleem
webdevkaleem2w ago
202 accepted status with the requests not getting processed does usually mean that you have resource or concurrency issues it could be that your ec2 container can't handle any more requests, or that your prisma connection / poollimit has been reached. might wanna play with prismas connection limit / pool timeout as your tasks arn't cpu intensive so it might be a numbers game. offloading work off to a job queue is also a good solution doing stuff like soft deletion, report generations, etc. tbh you are on the right track spot on you could also use a monitoring package, or logs to see exactly where what is failing
brandon76534
brandon76534OP2w ago
Thank you so much for your suggestions, will go down this route

Did you find this page helpful?