Production Incident Diagnosis and Distributed Systems Troubleshooting Questions
Debugging distributed systems under fire: diagnosing latency and reliability regressions, root-causing across service boundaries, reading traces and metrics during an incident, and reasoning about complex production failures. Covers the investigative method for hard-to-reproduce, multi-service problems. The operational counterpart to resilient design.
Monitoring shows that adding more instances of a microservice increased average and p95 latency instead of reducing it. Walk through a debugging checklist explaining possible causes (for example shared-resource contention, DNS or iptables issues, connection-pool exhaustion, or leader-election thrashing), how you'd gather evidence for each, and the remedial action for each cause.
Sample Answer
Direct answer. This is a genuinely counter-intuitive result, since adding instances should spread load and reduce latency, so the debugging checklist has to specifically look for mechanisms where MORE instances create MORE overhead or contention rather than simply assuming the scaling itself is broken.
Structured elaboration.
- Shared-resource contention. If the new instances all compete for the same downstream resource (a database, a cache, a shared connection pool with a fixed total size), adding instances doesn't add capacity to that shared resource, it just adds more competitors for the same fixed pie; check whether a shared downstream's own load or connection count grew proportionally to the new instance count, and whether ITS latency (not just this service's) got worse at the same time.
- DNS or iptables-level issues. A load balancer or service-discovery mechanism that takes non-trivial time to register or fully propagate new instances can cause uneven traffic distribution during scale-up (some instances overloaded while others are still ramping up); at the OS level, an inefficient iptables ruleset (iptables is the Linux kernel's packet-filtering and routing system, commonly used under the hood to implement service load-balancing rules in container networking) can scale poorly with a growing number of backend targets, adding real per-packet overhead as the instance count grows.
- Connection-pool exhaustion, from a different angle than shared-resource contention: if EACH instance opens its own pool of connections to a downstream, more instances can mean MORE total connections than the downstream can handle, even if each instance's own pool looks reasonably sized in isolation.
- Leader-election thrashing, if this service participates in any kind of coordination or leader election: more instances competing for leadership, or more instances triggering more frequent rebalancing in whatever coordination mechanism is in use, can itself consume real resources and add latency, especially if the coordination overhead scales poorly with instance count.
- Gather evidence for each candidate rather than guessing. For each of the above, there's a specific, checkable signal: shared-resource metrics correlated with instance count and latency; load-balancer target-registration timing and per-instance traffic distribution; per-instance versus aggregate connection counts against the shared downstream's own limits; and coordination-service metrics (rebalance frequency, election frequency) if relevant.
- Remedial actions per cause. Shared-resource contention needs the shared resource itself scaled or partitioned, not just the calling service. Load-balancer or iptables issues need investigation of the specific networking layer causing the overhead, which may mean a different load-balancing algorithm or container-networking mode. Connection-pool exhaustion needs a TOTAL connection budget considered across all instances, not just per-instance. Leader-election thrashing needs either fewer participants in the coordination (a subset act as candidates, not every instance) or a coordination mechanism that scales better.
Worked example. Suppose per-instance connection-pool size is a fixed 20 connections to a shared database, and the database's own max-connections limit is 200; at 8 instances, that's 160 total possible connections, comfortably under the limit. Scaling to 15 instances pushes the theoretical maximum to 300, which exceeds the database's 200-connection limit; once actual usage approaches that ceiling, connections start queueing or getting rejected, and EVERY instance (not just the newest ones) experiences worse latency waiting for a connection slot, which is exactly the paradox described: more instances made the shared resource, not any individual instance, the bottleneck. The fix is either reducing per-instance pool size as instance count grows (keeping the total bounded) or increasing the database's connection limit and capacity to match, with the total connection budget explicitly tracked as a fleet-wide constraint rather than a per-instance setting nobody re-evaluates as the fleet grows.
Trade-offs and pitfalls. The core lesson worth internalizing here is that per-instance settings (pool sizes, timeouts, cache sizes) that look reasonable in isolation can become a fleet-wide problem purely from being multiplied across a growing instance count; any config that's 'per instance' should be evaluated against what happens at your MAXIMUM realistic instance count, not just today's count. It's also worth being skeptical of your own instinct here: 'add more instances' is such a common, usually-correct scaling response that it's easy to reach for it again as the FIX when it was actually the trigger.
A microservice has become noisy and occasionally causes cascading failures in upstream services. Outline immediate mitigation steps (configuration and network-level), medium-term fixes (code or architecture changes), and long-term remediation to prevent recurrence. Specify the instrumentation you'd add to verify the improvements actually worked and the governance you'd put in place to limit future regressions.
Sample Answer
Direct answer. A noisy microservice causing intermittent cascading failures calls for a layered response: contain the blast radius immediately, fix the noisy behavior at a medium-term horizon, and put guardrails in place so a regression like this can't silently recur.
Structured elaboration.
- Immediate: configuration and network-level. Rate-limit or circuit-break calls TO the noisy service from its callers, so its bad behavior can't consume unlimited resources in the services that depend on it. If the noisy service is the one making excessive outbound calls (rather than being slow to respond), rate-limit or throttle IT at the network or gateway level. These are fast to apply and don't require a code change, which matters when you need to stop the bleeding now.
- Medium-term: code and architecture changes. Find and fix the actual cause of the noisiness: this is often a retry policy with no backoff or cap, a missing timeout that lets slow calls pile up, or a bug that occasionally sends a burst of redundant requests. Add proper backoff, timeouts, and request coalescing where the investigation points.
- Long-term: remediation to prevent recurrence. Add resource isolation (bulkheads) between this service and its callers so a future regression is contained structurally, not just by a runtime rate limit someone has to remember exists. Add automated tests or canary checks that specifically catch retry-storm or excessive-call-volume patterns before they reach full production traffic.
- Instrumentation to verify improvements. Add or confirm metrics for the specific behavior you're fixing (outbound call rate per instance, retry rate, circuit-breaker trip frequency) so you can see directly whether the fix worked, rather than inferring it indirectly from the absence of incidents.
- Governance to limit future regressions. This might mean a checklist or review step for any new retry logic (since that's the recurring theme across steps 1 to 3), or an automated linter/test that flags retry code with no backoff or cap during code review, so this class of bug is caught before it ships rather than after it causes an incident.
Worked example. Suppose the investigation finds the noisy service occasionally enters a state (triggered by a specific downstream timeout) where it retries a failed call up to 10 times with only a 50ms fixed delay between attempts and no jitter, so a brief downstream hiccup turns into a 10x request-volume burst from this one service. The immediate fix is capping the retry count and adding exponential backoff (waiting progressively longer between each retry attempt instead of retrying immediately) with jitter (a small random delay added so many clients retrying at once don't all hit the service at the exact same instant) in the code (medium-term), while a rate limit at the gateway (immediate) protects callers in the meantime. The long-term guardrail is a code-review checklist item (or an automated check) requiring any new retry logic to specify a max attempt count and a backoff strategy explicitly, since a fixed-delay, uncapped retry is exactly the pattern that caused this.
Trade-offs and pitfalls. Immediate rate-limiting protects the system but can also mean legitimate requests get throttled during the window before the real fix ships, which is a real cost that's usually still worth paying to avoid a wider cascade. The governance step is easy to skip once the immediate fire is out, but it's the piece that actually prevents the NEXT service from shipping the same uncapped-retry pattern; without it, this remediation only fixes one instance of a repeatable class of bug.
An hourly ETL job failed mid-run, leaving partially written partitions for several recent hours, and downstream consumers expect stable reads. Describe a safe recovery sequence: how you'd identify the affected partitions, snapshot the current state, safely delete or mark the partial partitions, re-run ingestion, and validate the result. Mention the SQL patterns or transactions you'd use to preserve atomicity where the storage layer supports it.
Sample Answer
Direct answer. A mid-run ETL failure leaving partial partitions is a data-integrity problem before it's anything else, so the recovery sequence has to be careful about ORDER: identify the exact damage, make it safe (don't let readers see it, don't lose the ability to undo), then repair, in that order.
Structured elaboration.
- Identify the affected partitions precisely. Compare the job's expected output (which partitions it was supposed to write, based on its schedule and input range) against what actually exists and its row counts or checksums; a partition with a suspiciously low row count, or one entirely missing, is your candidate set. Check the job's own logs for the exact point of failure to corroborate which partitions were mid-write versus genuinely untouched.
- Snapshot current state before touching anything, so you have a rollback point if your recovery sequence itself goes wrong; this is cheap insurance relative to the cost of compounding a partial-write incident with a botched recovery.
- Make the partial partitions safe for downstream consumers immediately. If downstream reads happen from the same partitions the failed job wrote to, either mark those specific partitions as unavailable/invalid (so readers get a clear 'not ready' signal rather than silently reading incomplete data) or, if the storage layer supports it, use an atomic swap pattern (write to a staging location, then atomically publish only once complete) so partial writes are simply never visible to readers in the first place, which is the more robust long-term pattern.
- Safely delete or mark the partial partitions, informed by step 1's precise identification, not a broad guess at which partitions might be affected.
- Re-run ingestion for exactly the affected range, not the whole job, to avoid unnecessary reprocessing and unnecessary risk to partitions that were never touched.
- Validate before declaring done. Compare row counts or checksums for the re-run partitions against an independent source of truth (an authoritative count or checksum comparison against a trusted source, the same kind of evidence used in any cross-system consistency check) to confirm the recovery is actually complete, not just that the job exited without an error this time.
Worked example. Say the job failed while writing partition 2026-07-20T14, and comparing that partition's row count (12,000) against the typical count for that hour (roughly 85,000, based on the surrounding hours) confirms it's a partial write, not a genuinely low-volume hour. Where the storage layer supports transactional writes at the partition level, the safest sequence is: write the re-run's output to a new, separate location, run the count/checksum validation against that new output BEFORE swapping it in, and only then atomically replace the partial partition with the validated, complete one, which never exposes readers to an intermediate, still-partial state during the fix itself, illustrated here for a Postgres-style target table using a swap pattern:
-- illustrative safe-swap pattern for a partitioned table
BEGIN;
-- new, validated data already loaded into staging_2026_07_20_14
ALTER TABLE events DETACH PARTITION events_2026_07_20_14;
-- DETACH does not drop the old partition, it stays present as a standalone table under its
-- original name, so that name must be freed up before staging can take it
ALTER TABLE events_2026_07_20_14 RENAME TO events_2026_07_20_14_old;
ALTER TABLE staging_2026_07_20_14 RENAME TO events_2026_07_20_14;
ALTER TABLE events ATTACH PARTITION events_2026_07_20_14
FOR VALUES FROM ('2026-07-20 14:00') TO ('2026-07-20 15:00');
COMMIT;
-- once the swap is confirmed correct (row counts/checksums match), drop the retained old partial data:
-- DROP TABLE events_2026_07_20_14_old;
The whole swap happens inside one transaction, so readers see either the old (partial) partition or the new (complete) one, never a state where the partition is half-replaced; the detached old partition is renamed rather than dropped immediately, so it stays available as a rollback/audit artifact until the swap is independently confirmed correct.
Trade-offs and pitfalls. Deleting the partial partition BEFORE the re-run has successfully produced and validated its replacement is a common and risky shortcut: if the re-run also fails, you've now made things worse (no data at all, rather than partial data) instead of better; always have the new, complete data validated and ready before removing the old, partial version. It's also worth checking WHY the job failed mid-run in the first place (a transient issue that a retry alone fixes, versus a systematic problem that will cause the exact same partial-write failure again) before considering the incident closed.
A latency-sensitive microservice exhibits 99.99th-percentile latency spikes under load. Describe a systematic methodology to find root causes across the software, hardware, and network layers, covering cases like elevated CPU with long garbage-collection pauses on the JVM. Propose mitigation techniques (for example hedged requests, resource isolation, garbage-collector tuning, and avoiding blocking I/O) and describe how you would validate that the improvements actually worked.
Sample Answer
Direct answer. At the 99.99th percentile, the causes worth chasing are specifically the RARE, TAIL-ONLY events, since anything that affects most requests would already show up at more common percentiles; that means the method has to isolate an extremely small slice of requests and look for what's different about them.
Structured elaboration.
- Confirm the scale of what you're chasing. At the 99.99th percentile, roughly 1 in 10,000 requests is affected; if you're serving even a few thousand requests per second, that's still a meaningful absolute number of slow requests, but it's a genuinely rare event per-request, which changes how you find it (sampling alone may miss it; you likely need either very high trace sampling for this specific investigation, or to trigger capture specifically when a request crosses a latency threshold).
- Software layer. Garbage-collector pauses (stop-the-world pauses, even brief ones, can land on a small fraction of requests and push exactly those into the extreme tail), lock contention under rare peak concurrency, and blocking I/O calls made from a supposedly async code path (which only manifests as a stall when that specific call happens to be slow) are the most common software-layer suspects at this percentile.
- Hardware layer. CPU throttling (a host hitting a thermal or power limit), a specific bad or degrading physical host in a fleet (one machine with a failing disk or a memory issue can produce a consistent trickle of extreme outliers from just that host), and NUMA (Non-Uniform Memory Access) effects on multi-socket machines are worth checking, especially if the extreme-tail requests correlate with a specific host or instance: on a multi-socket machine, a CPU core pays extra latency to access memory physically attached to a different socket than its own, which can add sporadic, hard-to-explain latency.
- Network layer. A rare TCP retransmit, a brief routing change, or contention on a shared network link can add tens to hundreds of milliseconds to an otherwise fast request, and these events are inherently sporadic and hard to reproduce on demand.
- Mitigation techniques matched to what you find. Hedged requests (firing a duplicate request to a second backend if the first hasn't responded within some threshold, and taking whichever comes back first) directly target rare-tail latency regardless of root cause, at the cost of some duplicate work. Resource isolation (dedicating specific cores or nodes to latency-sensitive work, away from noisy neighbors) helps with hardware- and contention-driven tail causes. GC tuning targets the software-layer pause-related causes specifically. Avoiding blocking I/O in supposedly async paths removes one specific, common software-layer cause outright.
- Validate improvements the right way. Because these events are rare, validating a fix needs either a long enough observation window to see the tail percentile stabilize with statistical confidence, or a targeted, repeatable synthetic test that reliably triggers the specific mechanism you fixed (for example a synthetic GC-pressure test if that was the cause), rather than eyeballing one day's dashboard.
Worked example. Say you correlate the extreme-tail requests against which physical host served them, and find that roughly 80% of the p99.99 outliers over a week trace back to just 3 of your fleet's 200 hosts. Checking those 3 hosts' hardware health shows elevated disk I/O wait times, consistent with a failing or degrading disk on those specific machines, unrelated to application code at all. The fix here isn't a code change, it's identifying and retiring or replacing those specific hosts, and the validation is confirming the p99.99 outlier rate drops once those hosts are out of rotation, which you'd expect to show up clearly since they were responsible for the large majority of the extreme tail.
Trade-offs and pitfalls. At this percentile, it's easy to chase a red herring: a handful of outlier data points can look like a pattern by chance, so before committing significant engineering time, check whether the correlation (a specific host, a specific time of day, a specific request type) holds up over a large enough sample to be more than noise. Hedged requests are also a real trade-off, not a free fix: firing duplicate requests reduces tail latency but increases total load on your backends, so it needs a cap and careful tuning to avoid making the load problem worse than the latency problem it's solving.
A schema migration is suspected to have caused silent data regressions. Design an investigative approach to prove causality: automated sampling strategies, aggregate- and row-level diffs using checksums, a deploy-bisection process to identify which deploy actually introduced the regression, and safeguards to prevent this class of regression in the future.
Sample Answer
Direct answer. Proving that a specific migration caused a data regression, rather than merely suspecting it, means finding the exact point where the data diverges from correct and confirming that point lines up with the migration's deployment, not just noticing that both happened around the same general time.
Structured elaboration.
- Define 'correct' precisely before comparing anything. Establish an authoritative source or a derivable expected value for the affected data (a recomputation from raw inputs, a comparison against a system that wasn't touched by the migration, or a snapshot from before the migration ran) so you have something concrete to diff against, not just a vague sense that something looks off.
- Run aggregate- and row-level diffs using checksums. An aggregate checksum (a hash or sum over a whole table or partition) tells you quickly whether TWO points in time or two sources agree at all; if they don't, row-level checksums (hashing each row's relevant fields) let you isolate exactly which rows differ, which is far more efficient than comparing every field of every row directly at scale.
- Use automated sampling to find the boundary, not just confirm a suspicion. Rather than comparing the entire dataset, sample rows across the time range spanning before and after the suspected migration, checking each sample's correctness against your reference from step 1; this narrows down not just WHETHER there's a regression but WHEN it starts, precisely.
- Deploy-binary-search to confirm causality specifically. If several deploys happened in the suspected window, checking correctness immediately before and after EACH deploy (not just before and after the whole window) isolates which specific deploy is responsible, the same logic as a code bisection but applied to data correctness checkpoints instead of a test suite.
- Safeguards to prevent recurrence. Adding an automated, ongoing checksum or row-count comparison specifically around future schema migrations (comparing a sample of migrated rows against their pre-migration values via a documented, checkable transformation rule) would catch this class of regression at migration time rather than requiring a manual investigation days or weeks later.
Worked example. Suppose you're checking whether a schema migration that changed how a total_amount field is computed introduced a systematic error. You compute an independent, from-raw-inputs recomputation of total_amount for a sample of orders and compare it against the stored value; below is an illustrative version of that comparison, checked for logical correctness (not run against real production data, since none is available here, but confirmed to execute and produce the expected result against a small synthetic case with a known correct answer):
# illustrative row-level regression check: recomputed vs stored value
def recompute_total(line_items, tax_rate, discount):
subtotal = sum(item['price'] * item['qty'] for item in line_items)
return round(subtotal * (1 + tax_rate) - discount, 2)
# a synthetic order with a KNOWN correct total, computed by hand:
# subtotal = 2*10.00 + 1*5.00 = 25.00; with 8% tax = 27.00; minus 2.00 discount = 25.00
order = {
'line_items': [{'price': 10.00, 'qty': 2}, {'price': 5.00, 'qty': 1}],
'tax_rate': 0.08,
'discount': 2.00,
'stored_total': 27.00, # what the migrated system actually stored
}
expected = recompute_total(order['line_items'], order['tax_rate'], order['discount'])
print(f"recomputed={expected}, stored={order['stored_total']}, match={expected == order['stored_total']}")
Running this: recomputed=25.0, stored=27.0, match=False. In this illustrative case, the migration's stored value (27.00) matches the PRE-discount total, meaning the migrated computation is applying the discount incorrectly (or not at all) somewhere in the pipeline; comparing this same check across a real sample of orders straddling the migration's deploy timestamp, and finding the mismatch rate jumps from 0% before the deploy to consistently nonzero after it, is what would confirm the migration as the cause with actual evidence rather than a hunch.
Trade-offs and pitfalls. A checksum comparing whole-row hashes is fast but only tells you THAT something differs, not WHAT or WHY; row-level, field-level comparison (like the recompute check above) is more expensive but is what actually reveals the mechanism, so budget for both: cheap aggregate checks to find the affected range fast, more expensive row-level checks to understand the mechanism once you've narrowed the range. It's also worth being careful that your 'authoritative' recomputation is itself genuinely correct and independent of the migrated logic, since a recomputation that shares a bug with the migration would falsely confirm the migration's (wrong) output as correct.
Unlock Full Question Bank
Get access to all 49 Production Incident Diagnosis and Distributed Systems Troubleshooting interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.