Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Medium Engineering 7 min read Case study mediumAdept

Medium Android App — Migrating from Apollo Kotlin 3 to 4: Lessons Learned

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. 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.

Related posts

  • Migrating from Apollo Tooling to GraphQL Codegen at Yelp

    Yelp Engineering mediumAdept

    Yelp replaced the deprecated apollo-tooling codegen with GraphQL Codegen across a 500+ package React/TypeScript monorepo without requiring developers to change imports or queries. Rather than adopting gql.tada or Codegen's native client preset, the team patched the typescript-operations plugin and near-operation-file preset to emit apollo-tooling-compatible output: per-operation file names, inlined enums and input types, plain `T | null` instead of Maybe/Exact wrappers, and field-only nested type names. The patches also fixed a concurrency problem where multiple processes regenerated shared fragments. The changes were upstreamed into GraphQL Codegen v6 in collaboration with its maintainer. The remaining few hundred type errors were fixed incrementally, with Claude's help, using a shrinking allowlist of packages still on the old tool.

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

    Shopify Engineering mediumAdept

    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.

  • Improving Shopify App’s Performance

    Shopify Engineering mediumAdept

    Shopify cut its React Native mobile app's P75 launch time by 44% and screen load times by 59% over 2023, against targets of 2s launch and 500ms critical-screen loads. The fixes fell into three themes. The first was deferring work until it is needed: FlashList-based LazyScrollView and ListSource render only visible content, inlineRequires in the Metro config alone gave a 17% launch gain, and slow native modules were fixed. The second was eliminating unnecessary work: freezing back-stack screens cut navigation time by up to 70%, Restyle allocations were trimmed, and default state batching improved screen loads by about 15%. The third was maximizing cache use by fixing a GraphQL cache bug and pre-warming caches so up to 90% of merchants see cached data first.

  • Lessons From Building Android Widgets

    Shopify Engineering mediumAdept

    Shopify built its Android analytics widgets natively rather than in React Native, because widgets must be built from RemoteViews, which React Native does not support. Widget onUpdate() fires several times per cycle, so a one-minute cache keyed by widget ID removes redundant network calls and incorrect analytics. RemoteViews also append to existing views on each update, which they fixed by calling removeAllViews() before addView(). Charts are drawn from MPAndroidChart as ARGB_8888 bitmaps, relative timestamps were dropped over battery cost, and update flicker is reduced by suppressing updates for 60 seconds after placement and rendering early from cached shared preferences.

  • It’s a non-transitive R class world

    Slack Engineering mediumAdept

    Slack migrated its 400+ module Android codebase to non-transitive R classes, where each module's R class contains only its own resources, yielding ~14% faster incremental builds after resource or layout changes and an ~8.5% (about 5.5MB) APK/DEX size reduction. Because Android Studio's built-in migration refactor stalled at this scale, the team used regex find-and-replace on the two modules holding most resources, a script to add Kotlin import aliases (e.g. L10nR, SlackKitR), and then enabled android.nonTransitiveRClass and android.enableAppCompileTimeRClass. Shared live templates and three auto-fixing lint checks enforce consistent alias conventions, and the migration also exposed misplaced resources and made resource origins easier to trace.

The quest for software engineering knowledge.

Look:
Layout: