내용으로 건너뛰기

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?

질문됨 3년 전423회 조회

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

전문가

답변함 3년 전

AWS
전문가

검토됨 3년 전

  • 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 !!

답변함 3년 전

  • 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.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.