I am trying to write a rest GET api to serve query results. The entire flow happening on the server is:
- Fetch user data
- Call the first query, if results generated: return results, else continue
- Call the second query, if results generated: return results, else continue
- And and continue so on.
The problem is I want to remember which query generated the results and next time the user makes the request, call and start the chain from there instead of the previous ones. Also since the step 1 always generates the same data for that specific user, I want to skip this too in the next queries. What would be the best practice for this?
The endpoint suggests a certain items to the user like recommendations. To generate these, I fetch the user seen items and execute certain queries e.g first based on type, second based on price and so on. The user data helps in these queries e.g prices of things he saw, type of products and so on. Since the user seen items are sensitive, I don't want to send it back to the client.
I thought of sending some helper data like query number back to the client (mobile app) and also the user data from step 1 back to the user and sending it back to the server from the client while making the subsequent calls but the I don't want to send user sensitive data from the server to the client.
Another way I thought of was using a cache like Redis but the problem is that adding a cache on Heroku will be costly. Any other way?