---
title: "Apollo Cache is Your Friend, If You Get To Know It"
description: "Apollo Client's InMemoryCache stores a normalized, in-session representation of GraphQL data, and its object lifecycle runs through four stages: fetching (governed by fetch policies, defaulting to cache-first), normalization (splitting responses into objects keyed by __typename plus id or custom keyFields into a flat hash map), updating and merging, and garbage collection and eviction."
url: "https://swe.quest/articles/apollo-cache-is-your-friend-if-you-get-to-know-it-2ce614128099fb3f"
canonical: "https://shopify.engineering/apollo-cache"
source: "Shopify Engineering"
published: "2022-11-09"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 15
tags: ["graphql","caching","frontend","memory-management"]
---

# Apollo Cache is Your Friend, If You Get To Know It

A post on [Shopify Engineering](https://swe.quest/sources/shopify.md), published 2022-11-09, 15 min read, Deep dive. Original: [https://shopify.engineering/apollo-cache](https://shopify.engineering/apollo-cache)

## Summary

Apollo Client's InMemoryCache stores a normalized, in-session representation of GraphQL data, and its object lifecycle runs through four stages: fetching (governed by fetch policies, defaulting to cache-first), normalization (splitting responses into objects keyed by \_\_typename plus id or custom keyFields into a flat hash map), updating and merging, and garbage collection and eviction. Automatic UI updates only happen when a mutation returns the same entity type with its ID, or the full collection. Related side effects, partial lists, reordering and additions or removals all require explicit update functions or refetches. A real bug where a nested object lacking an id failed to normalize shows why consistent IDs matter, and cache.gc() must be called manually to reclaim unreachable objects in long-lived apps.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [GraphQL](https://swe.quest/tags/graphql.md) (Backend & APIs)
- [Caching](https://swe.quest/tags/caching.md) (Backend & APIs)
- [Frontend](https://swe.quest/tags/frontend.md) (Web & mobile)
- [Memory management](https://swe.quest/tags/memory-management.md) (Compilers & runtimes)

## Prerequisites

- GraphQL queries and mutations ([easy posts on GraphQL](https://swe.quest/tags/graphql.md?difficulty=easy))
- React hooks ([easy posts on React](https://swe.quest/tags/react.md?difficulty=easy))
- Apollo Client basics

## Keywords

Apollo Client, InMemoryCache, GraphQL, keyFields, cache.gc(), Shopify

## Related posts

- [Medium Android App — Migrating from Apollo Kotlin 3 to 4: Lessons Learned](https://swe.quest/articles/medium-android-app-migrating-from-apollo-kotlin-3-to-4-lessons-learned-a49ead8ba5186c2f.md): Medium Engineering · 2025-10-06 · Medium · 7 min read · GraphQL, Mobile, Caching, Java & JVM, Refactoring & migrations
  Upgrading Medium's Android app from Apollo Kotlin 3 to 4 surfaced CacheMissException errors across every watch()-based UI, because v4 delivers fetch errors through ApolloResponse instead of throwing or silently dropping them.
- [GraphQL persisted queries and Schema stability](https://swe.quest/articles/graphql-persisted-queries-and-schema-stability-a96dada14e0377f0.md): Zalando Engineering · 2022-02-16 · Medium · 6 min read · GraphQL, API design, Schema migrations, Deployment
  Zalando disables arbitrary GraphQL queries in production and accepts only query IDs that were persisted at build time, where an ID is a hash of the normalized query.
- [Keeping it 100(x) with real-time data at scale](https://swe.quest/articles/keeping-it-100-x-with-real-time-data-at-scale-3b49e279c5a600f2.md): Figma · 2024-05-17 · Medium · 19 min read · Caching, Real-time systems, Scaling, PostgreSQL, System design
  Figma rebuilt LiveGraph, its real-time GraphQL-like subscription service over Postgres, to scale reads and database update load 100x as the database moved from one instance to vertical and horizontal shards.
- [Ownership and data flow in GPUI](https://swe.quest/articles/ownership-and-data-flow-in-gpui-d709f4da05260bf5.md): Zed · 2024-01-25 · Medium · 9 min read · Rust, Frontend, Memory management, Event-driven architecture
  GPUI, Zed's Rust UI framework, sidesteps Rust's single-ownership constraints by having a top-level App own every model and view, while code holds reference-counted Entity\<T\> handles that can only read or update state when given an App or Context.
- [Implementing Server-Driven UI Architecture on the Shop App](https://swe.quest/articles/implementing-server-driven-ui-architecture-on-the-shop-app-6be47fae080cf1dc.md): Shopify Engineering · 2022-11-22 · Medium · 10 min read · Mobile, GraphQL, React, System design, API design
  Shopify's Shop App moved its Store Screen from client-driven to server-driven UI so the backend decides which sections (Best Sellers, Collections, All Products) and layouts (Grid, Shelf) each merchant's store renders.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
