---
title: "Caching Without Marshal Part 1: Marshal from the Inside Out"
description: "Ruby's Marshal serializes an object's full class graph into cache entries, so a refactor that renamed classes caused old and new code to choke on each other's cached beta-flag objects mid-deploy and triggered an incident at Shopify."
url: "https://swe.quest/articles/caching-without-marshal-part-1-marshal-from-the-inside-out-57f413ca18174072"
canonical: "https://shopify.engineering/caching-without-marshal-part-one"
source: "Shopify Engineering"
published: "2022-11-11"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 11
tags: ["ruby","caching","runtimes"]
---

# Caching Without Marshal Part 1: Marshal from the Inside Out

A post on [Shopify Engineering](https://swe.quest/sources/shopify.md), published 2022-11-11, 11 min read, Deep dive. Original: [https://shopify.engineering/caching-without-marshal-part-one](https://shopify.engineering/caching-without-marshal-part-one)

## Summary

Ruby's Marshal serializes an object's full class graph into cache entries, so a refactor that renamed classes caused old and new code to choke on each other's cached beta-flag objects mid-deploy and triggered an incident at Shopify. Walking through marshal.c and real payloads, the post explains how Marshal encodes objects (TYPE\_OBJECT), instance variables on core types (TYPE\_IVAR), circular references (TYPE\_LINK) and subclasses of String/Array/Hash/Regex (TYPE\_UCLASS). These are exactly the features that break when replacing Marshal, setting up Shopify's migration of Rails cache serialization to MessagePack in part two.

Written by swe.quest, not by the author.

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

## Topics

- [Ruby](https://swe.quest/tags/ruby.md) (Languages)
- [Caching](https://swe.quest/tags/caching.md) (Backend & APIs)
- [Runtimes & VMs](https://swe.quest/tags/runtimes.md) (Compilers & runtimes)

## Prerequisites

- Ruby objects and classes ([easy posts on Ruby](https://swe.quest/tags/ruby.md?difficulty=easy))
- Rails caching basics ([easy posts on Ruby](https://swe.quest/tags/ruby.md?difficulty=easy))
- binary serialization

## Keywords

Marshal, MessagePack, Rails, ActiveSupport::Cache, Memcached, Shopify

## Related posts

- [Caching Without Marshal Part 2: The Path to MessagePack](https://swe.quest/articles/caching-without-marshal-part-2-the-path-to-messagepack-dde2d14188f0b673.md): Shopify Engineering · 2022-11-15 · Medium · 17 min read · Ruby, Caching, Refactoring & migrations
  Shopify replaced Ruby's Marshal with MessagePack as the Rails cache format for its core monolith so that code changes would stop breaking cached payloads on deploy.
- [Making Open Source Safer for Everyone with Shopify’s Bug Bounty Program](https://swe.quest/articles/making-open-source-safer-for-everyone-with-shopify-s-bug-bounty-program-48c56c4f3d09ee13.md): Shopify Engineering · 2022-06-15 · Medium · 5 min read · Application security, Ruby, Open source
  A Shopify bug bounty report showed that a leaked Rails development secret could be escalated to remote code execution because ActiveSupport's MessageEncryptor deserialized data with Marshal by default.
- [Changing a polymorphic\_type in Rails](https://swe.quest/articles/changing-a-polymorphic-type-in-rails-8b5924e77ba397de.md): Shopify Engineering · 2022-02-18 · Medium · 7 min read · Ruby, Refactoring & migrations, Schema migrations, Databases
  Rails stores the parent's class name in a polymorphic association's type column, so moving models into a new namespace (e.g. Car to Garage::Car) leaves mixed values like "Car" and "Garage::Car" and breaks lookups in both directions.
- [Code Ranges: A Deeper Look at Ruby Strings](https://swe.quest/articles/code-ranges-a-deeper-look-at-ruby-strings-b87e06d5cb44fa84.md): Shopify Engineering · 2022-04-14 · Hard · 14 min read · Ruby, Runtimes & VMs, Data structures, Performance engineering
  Ruby strings are mutable and encoding-aware across 100+ encodings, so runtimes cache a per-string "code range" (UNKNOWN, 7BIT, VALID, BROKEN) to avoid repeated O(n) validity scans.
- [It’s a non-transitive R class world](https://swe.quest/articles/it-s-a-non-transitive-r-class-world-dc7be71b63e01554.md): Slack Engineering · 2023-02-01 · Medium · 5 min read · Mobile, Build systems, Refactoring & migrations, Static analysis, Developer productivity
  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.

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)
