---
title: "The Constant Frozen at Boot Bug: A Ruby Exercise For An Interview"
url: https://daily.dev/posts/the-constant-frozen-at-boot-bug-a-ruby-exercise-for-an-interview-tsi81jrzt
source_url: https://zhisme.com/articles/ruby-constant-frozen-at-boot
type: article
source: "Ruby Flow"
published: 2026-06-11T13:09:00.795Z
updated: 2026-06-11T13:09:25.891Z
tags: ["ruby", "rails"]
reading_time: 7
upvotes: 0
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# The Constant Frozen at Boot Bug: A Ruby Exercise For An Interview

**[Ruby Flow](https://daily.dev/sources/rubyflow)** · 7 min read · 0 upvotes · 0 comments

## Summary

A real production bug from a payment service where class-level Ruby constants are evaluated once at class load time. If a database lookup returns nil at boot (due to autoload timing, deploy race conditions, or replica lag), the constant is permanently set to nil for the entire process lifetime — silently writing NULL to the database on every subsequent call. The fix replaces load-time constant assignment with lazy per-instance caching using the Singleton pattern and find_by! (which raises on missing rows instead of returning nil), ensuring the cache is never poisoned with a missing-row nil.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://zhisme.com/articles/ruby-constant-frozen-at-boot>

## Similar posts on daily.dev

- [Dynamic Ruby And Hidden Maintenance Costs](https://daily.dev/posts/dynamic-ruby-and-hidden-maintenance-costs-jnxrbecmr) · RUBYLAND · 0 upvotes · 0 comments
- [Ruby Instance Variables Are Not Inherited \(and Why That Breaks Your DSL\)](https://daily.dev/posts/ruby-instance-variables-are-not-inherited-and-why-that-breaks-your-dsl--gbn1gpbrt) · RUBYLAND · 1 upvotes · 0 comments
- [Benchmarks Are Free Now](https://daily.dev/posts/benchmarks-are-free-now-307ftwxma) · RUBYLAND · 0 upvotes · 0 comments

---

Tags: [#ruby](https://daily.dev/tags/ruby), [#rails](https://daily.dev/tags/rails)

[View this post on daily.dev](https://daily.dev/posts/the-constant-frozen-at-boot-bug-a-ruby-exercise-for-an-interview-tsi81jrzt)
