I have a collection that is updated frequently and contains a large amount of data. The schema is essentially:
{
productType: Array,
productName: Array,
productPrice: Array
}
My users are concerned with finding products with prices lower than $100. Prices are constantly changing, so I query a database that contains over 100,000 products every 10 minutes to filter to all products under $100. This brings the dataset down to about 20,000 items per array with a total size of about 2MB. Since these values change so frequently, I feel it’s best to store them in a single collection instead of writing to each product to their own collection.
On my frontend, the users would like to search for products by name or type to find the lowest prices. My current design is to pull the entire collection into memory with an API call that takes about 0.5-1 seconds. Then when they perform the search, all prices are stored in memory and easily accessible. If they open the search window later and greater than 30 minutes has passed, they pull the updated collection into memory.
The other alternative is to create API calls to show them only the product name or type they’re currently searching for. Each character typed would make a call where the search results show them the lowest price for the input.
My question is, is it better to store the entire collection in memory which results in faster speed and the client’s machine or is it better to make frequent API calls to only show them relevant information? Which solution is most sustainable in the long run? If I have 1000s of users, is less calls pulling more data better or many frequent calls?