I'm currently working on a project with an organization as follows:
- Client - Gets data from the main server via REST api.
- Server - Requests data from various other servers via third-party APIs
- Third-party APIs - Services out of my control that provide data to the server (Reddit, Hackernews, Quora, etc.)
For the sake of argument, let's say the client first needs a list of items from each of the third-party APIs. From this list, an item will be chosen at which point the client needs to see the full content of the item as well as responses (i.e. comments) to the item. I'm trying to decide between three options:
A la Carte
In this approach, I would have 3 separate endpoints on my server: one to get the list of items, one to get the main content for an item, and one to get the responses of the item.
- Pros: I never make more requests than I need to, requests should be small so generally they should be faster.
- Cons: I have to make a lot of requests. After choosing an item from the list, the user may have to wait before seeing the main content and then wait even longer to see the responses
Server-side cache
In this request, I would make a single call to my server to "fetch" all the data for all sources. The data would then be cached on the server. The client would then have the same REST endpoints as before, except there wouldn't be much waiting between calls since my server already has the data and just has to feed it to the client.
- Pros: Still easy to implement on the client side, but without the latency issues
- Cons: A bit more involved server side, and the first call could take really really long.
Client-side cache
This scenario is similar to the previous one except the client only ever makes one request to the server: give me all of the data. From here it's the client's responsibility to save the data and use it appropriately.
- Pros: Easy server implementation, very speedy after the first call
- Cons: First call will be very slow, more complicated client-side implementation
I'm not sure which is the best approach, or if maybe I'm missing the obvious solution. Any advice would be greatly appreciated!