Skip to content
Preptima
mediumConceptScenarioMidSenior

You cached something in a module-level dictionary. It works on your laptop and behaves oddly in production. What is different?

5 min readUpdated 2026-08-15Target archetype: Big Tech, Enterprise Captive, Product Startup

Answer

Short answer

Production runs several worker processes, and each has its own interpreter, its own imported modules and therefore its own copy of that dictionary. Requests land on whichever worker is free, so a write in one is invisible to the others and every restart discards the lot.

Was this answer helpful?

Likely follow-ups

  • What does gunicorn's preload option change about where that dictionary is initialised?
  • Your app runs a scheduled job on startup and it now fires four times an hour. How do you fix it properly?
  • Which parts of a warm in-memory cache survive a fork, and which stop being shared as soon as they are read?
  • How would you make a per-process cache safe when the worker also uses threads?

Related questions

Related Topics