Interview Prep/Python for DevOps/Testing, CI/CD, packaging & services

Your Python app's latency spikes every few minutes. Prometheus shows the spikes line up with high GC activity. What do you investigate?

AdvancedScenarioTesting, CI/CD, packaging & services
Answer

Situation read → Garbage collection pauses or memory pressure.

What I'd do →

  1. Check the python_gc_collections_total and process_resident_memory_bytes metrics that prometheus_client exports by default.
  2. Profile allocations with tracemalloc snapshots or memray in staging.
  3. Look for large object graphs created per request (caching whole API responses, huge dict copies).
  4. Tune gc.freeze() after startup for pre-fork servers, or adjust thresholds, only after fixing allocation hot spots.
  5. Check CPU throttling from container limits, which can masquerade as GC pauses.

Why → Allocation reduction fixes GC pauses; tuning only hides them.

Interview tip → Mention CPU throttling; it is a common confounder in containers.

All Python for DevOps questions Roadmap: Python for automation

More on Testing, CI/CD, packaging & services