Apollo Cache is Your Friend, If You Get To Know It
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.
Related posts
- Medium Android App — Migrating from Apollo Kotlin 3 to 4: Lessons Learned
Medium Engineering mediumAdeptUpgrading 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. The root cause was a flawed programmatic CacheKeyGenerator, fixed by switching to declarative @typePolicy/@fieldPolicy cache IDs and adding __typename to all operations. A safeWatch wrapper filters expected exceptions per fetch policy (cache misses under CacheFirst/CacheAndNetwork, network errors under NetworkFirst) so the UI only sees meaningful failures. Fragment cache-update extension functions, a custom Currency scalar adapter, and planned HTTP batching and persisted queries round out the upgrade.
- GraphQL persisted queries and Schema stability
Zalando Engineering mediumAdeptZalando 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. Because every production query is known, the team can monitor and alert per query and tell which schema fields are unused and therefore safe to break. On top of this they add schema directives: @draft blocks a field from being persisted so it can be merged, deployed and changed freely. @component and @allowedFor restrict an experimental field to specific UI components, so a breaking change only touches those callers. Fields move from draft to restricted to stable, which lets the schema evolve without long-lived feature branches across microservices.
- Keeping it 100(x) with real-time data at scale
Figma mediumAdept
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. The old design tailed a single globally ordered replication stream into per-server mutation-based caches, which caused excessive fan-in and fan-out, fragmented caches, thundering herds on deploy, and stalled optimistic updates whenever any shard blipped. Two traffic findings drove the redesign: most data is delivered by initial reads rather than live updates, and most queries can be invalidated directly from a row mutation. The result is a three-tier Go system: an edge that expands views, a read-through cache sharded by query hash, and stateless invalidators sharded like the databases that tail the replication streams and send invalidations only to the relevant cache shards.
- Ownership and data flow in GPUI
Zed mediumAdeptGPUI, 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. Entities communicate via notify/observe and typed emit/subscribe, but calling emit or notify only enqueues an effect; App::update flushes the effect queue after the outermost update, giving run-to-completion semantics without the reentrancy bugs of naive event emitters. To hand out both &mut T and &mut Context<T>, update_entity temporarily leases the entity's state out of the App onto the stack and returns it afterward, at the cost of forbidding reentrant updates to the same entity.
- Implementing Server-Driven UI Architecture on the Shop App
Shopify Engineering mediumAdeptShopify'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. Doing this decouples UI fixes and experiments from the weekly mobile release cadence. Server side, a template processing layer, per-section data loaders, a GraphQL layer exposing typed ProductsSection/CollectionsSection with configurable layouts, and an orchestrator work together. On the client, a React component tree dispatches each section to grid or shelf components. Older clients that receive unknown layout types fall back to a per-section default layout defined on the client.