Production investigation
Tracing Intermittent Production Bugs
By Team · Sat May 09 2026 · 4 min read
Intermittent production bugs are non-deterministic failures. They occur sporadically and lack consistent reproduction steps. This unpredictability hinders traditional debugging workflows. Resolution requires systematic data aggregation and analysis to identify contributing factors present during failure events.
Why This Happens
Intermittent bugs stem from race conditions, resource contention, external service instability, or poorly handled edge cases. Asynchronous operations often expose these issues. Distributed systems exacerbate the problem. Many components interact, creating complex timing dependencies. Shared resources like databases or caches can briefly deadlock or return stale data. Network latency fluctuation triggers timeouts or reordering issues. Environment specific factors, such as specific traffic patterns or host utilization, can also expose latent defects. System noise often masks the true cause. Race conditions in production are a common source of intermittent failures. Monitoring alone does not prevent issues, especially intermittent ones.Investigation Process
- Define the Symptom: Clearly document observed behavior. Include frequency, impact, and associated error messages. Note any correlation with system load or time of day.
- Enhance Observability: Increase logging granularity around affected components. Add unique correlation IDs to trace requests across services. Instrument code paths with custom metrics. This provides more context for each failing event.
- Stabilize the Environment: Attempt to isolate the bug to a smaller scope. Can it be reproduced in a staging environment? Can specific traffic patterns trigger it? Use chaos engineering principles cautiously in non-production.
- Collect Data Systematically: Gather all relevant logs from all services involved. Collect metrics for CPU, memory, network, and disk I/O. Focus on data from the exact time window of the failure.
- Identify Common Denominators: Analyze collected data for patterns. Look for specific request parameters, user IDs, or environmental conditions present during failures. Compare failing events to successful ones.
- Formulate Hypotheses: Based on patterns, propose potential causes. For instance, "The bug occurs when Service A receives a specific payload and Service B is under high load."
- Test Hypotheses: Deploy targeted logging or introduce small, controlled changes. Can you force the condition that causes the bug? Can you mitigate it temporarily?
- Re-test and Verify: Once a fix is implemented, monitor closely in production. Confirm the intermittent bug no longer manifests. Ensure no new issues arise.
Practical Example
A user reported occasional `500 Internal Server Error` responses when updating their profile. The errors occurred only several times a day. Retrying immediately often succeeded. Initial logs were generic, providing little insight. We added request-specific trace IDs propagated through all microservices. We increased logging verbosity in the profile update service and the user data service. Custom metrics were added to track database connection pool utilization in the user data service. Analysis showed errors consistently correlated with a sudden spike in database connection pool waiting times. This spike happened regardless of overall database CPU or memory. Further investigation revealed a specific type of profile update (e.g., adding a new address) triggered an unindexed query. This query occasionally locked a table when concurrent requests were high. The lock release was non-deterministic due to other active transactions. Adding an index to the `user_addresses` table on the `user_id` column resolved the issue. Database connection waiting times returned to normal. The `500` errors ceased for this operation.Preventing Recurrence
Implement robust retry mechanisms with exponential backoff for external calls. Use circuit breakers to prevent cascading failures during intermittent service unavailability. Enhance logging and monitoring for critical code paths and shared resources. Focus on metrics that expose resource contention immediately. Implement distributed tracing end-to-end between all services. Conduct regular code reviews specifically for potential race conditions. Integrate chaos engineering practices into dev environments. This helps uncover latent intermittent issues before production deployment. Identifying system bottlenecks proactively is crucial.What Teams Usually Do Instead
Many teams rely solely on simple error logs. They categorize intermittent bugs as "flaky" or "transient" without deep investigation. This leads to accumulating technical debt and eroding system reliability. Engineers often spend time on local machine reproduction rather than production data analysis. They add unrelated, broad logging in a panic during an incident. This creates log noise, obscuring actual issues. They might apply seemingly logical but untargeted fixes. These patchwork solutions often mask symptoms instead of addressing root causes. This cycle consumes engineering resources without resolution. It also breeds distrust regarding system stability.Key Takeaways
- Intermittent bugs require systematic data collection.
- Enhance observability with tracing and custom metrics.
- Identify common patterns across failure events.
- Test hypotheses with targeted logging or changes.
- Prevent recurrence with robust architectural patterns.