Read entire item from database to begin with or make a second call when needed

35 views Asked by At

Using DynamoDB.

An online store where you see a snapshot of the data for 20 items on the first screen, including price, picture, product name.

When you click on the product it reveals more data, such as description, any deals, more images, etc.

Would you make another call to the database for the second view or just get all the data on the first call?

1

There are 1 answers

1
Seth Geoghegan On BEST ANSWER

When considering "best practices", I wouldn't consider one approach a clear winner over another. Which approach works best for you will depend on the specifics of your application. For example, are you in a high latency/low bandwidth environment? Are you on a mobile device? How often is this query run? Etc.

I would recommend starting by pulling back all the data you need in a single request because it's simpler. If you run into performance issues along the way, you can circle back and try fetching additional data on an as-needed basis.

If there is a "best practice" here, it's to avoid pre-optimizing your code. Now if only I could take my own advice :)