Frontend System Design1 min readPremium

Navigating Data Fetching Strategies: Network Only, Cache, and Hybrid Approaches

Choosing the right data fetching strategy is crucial for the performance and user experience of any web application. This article discusses three common strategies: Network Only, Network and Cache, and Cache Only, along with their advantages and disadvantages. Apollo’s fetch policy docs map closely to these data fetching strategies.

Network Only

Pros:

  • Fresh Data: Ensures access to the most up-to-date information directly from the server, ideal for real-time data needs.

Cons:

  • Latency: Can result in delays due to slow network connections or high server load.
  • Potential for Failure: Relies entirely on network availability; any disruption means no data is received.

Network and Cache

Pros:

  • Balanced Approach: Offers a compromise between speed (cache) and freshness (network).
  • Improved Performance: Immediate response from cache with background updates for fresh data.

Cons:

  • Potential for Stale Data: The cache might serve outdated information until the next network update.
  • Complex Caching Logic: Requires careful management of cache validity and synchronization.

Cache Only

Pros:

  • Instantaneous Response: Delivers immediate data retrieval if available in the cache.

Cons:

  • Risk of Stale Data: There’s a high chance of serving outdated information if the cache isn’t regularly refreshed.
  • Dependence on Cache: Excessive reliance on cached data can prevent accessing fresh data from the network.

Summary of Data Fetching Strategies

The choice of data fetching strategy should be tailored to the specific needs of your application. Network Only is best for applications requiring real-time data. Network and Cache offers a balanced solution suitable for most use cases. Cache Only is ideal for applications where data doesn’t change frequently and speed is paramount.

... premium content.

Premium

Keep reading with Premium

Get the rest of this guide plus every premium question, solution, and system design deep dive.

  • All premium solutions
  • System design deep dives
  • Company-specific prep

4.9/5 from our users