DynamoDB read usage spike when using frontend API

0

I'm building a full stack application using Amazon DynamoDB as the Database. I can use an HTTP Client to make an API call, which calls upon DynamoDB to BatchGet a collection of User items. When I use Postman as the Client, my read usage metrics are normal, they don't even peak above 0.5 units. However, when I use a HTTP Client in my React App (Axios, Fetch API, etc.), it causes a MASSIVE spike (above 3 units, sometimes even 4). What is causing this spike?

M-Allen
已提問 6 個月前檢視次數 153 次
2 個答案
0
已接受的答案

Hi,

one potential issue with React generating such amount of calls is unnecessary re-rendering: see https://dev.to/femi_dev/how-to-prevent-unnecessary-react-component-re-rendering-3c08 for all details.

You can trace re-rendering by following this post: https://jsramblings.com/how-to-check-if-your-component-rerendered-and-why/

Best,

Didier

profile pictureAWS
專家
已回答 6 個月前
profile pictureAWS
專家
已審閱 6 個月前
  • You are absolutely right! I didn't not have a dependency list in my useEffect hook where I made the HTTP request, and I should know better than that. Once I declared the dependency list, no rerender, no spike!

  • Happy that you found the root cause of your issue! Didier

0

This is very interesting situation! The fact that you see different DynamoDB read usage between Postman and your React App suggests that the difference is likely in how the requests are being made or handled, rather than anything intrinsic to DynamoDB itself.

Here are a few possible causes to consider:

  1. Frequency of Requests: If your React App is making more requests per second than Postman, this could account for the increased read usage.

  2. Parallelization of Requests: If your React App is making multiple requests in parallel, this could cause a spike in read usage. Postman typically sends requests one at a time.

  3. Data Volume: If the React App is fetching more data (more items or larger items) than Postman, this would result in more read capacity unit usage. Remember, DynamoDB charges read capacity units based on item size, with one unit representing one read per second for items up to 4 KB.

  4. Consistency: DynamoDB has two read types: eventually consistent and strongly consistent. Strongly consistent reads use twice the read capacity units as eventually consistent reads. Check if there's a difference in the consistency model between your Postman and React App requests.

To debug this, I would recommend you start by logging detailed request and response information in both Postman and your React App. Compare the logs to identify any differences in the frequency of requests, the size of the data being fetched, or the request parameters. AWS X-Ray can also be useful for tracing requests and identifying bottlenecks or differences in request handling.

Hope this helps !!

已回答 6 個月前
  • Thank you for your response! It actually turned out that I forgot to use a dependency list for my useEffect hook in my React App, which essentially caused it to call the DB multiple times, resulting in the spike.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南