Skip to content
tezvyn:
Menu

Explain the difference between correlation and causation with a software example.

Source: Wikipedia: Correlation does not imply causationMediumHow cards are made

Tests whether you distinguish association from causation to avoid blaming production issues. A strong answer defines both concepts, names a confounding variable, and gives a software example with a common cause. Red flag: claiming correlation is causation.

What's really being asked

This question tests your ability to reason about observational data without falling into the cum hoc ergo propter hoc fallacy. Interviewers want to see that you understand a metric relationship is not enough to justify an intervention. In production systems, acting on a spurious correlation can lead to wasted engineering time, bad autoscaling rules, or incorrect alerting thresholds. The goal is to see if you ask what hidden variable could explain both observations before committing to a causal story.

The full answer

First, a crisp definition of correlation as a statistical association or co-occurrence between two variables, and causation as a directional relationship where manipulating one variable changes the other. Second, an explicit mention of a confounding variable or common cause that links the two metrics. Third, a software example where two metrics move together because of an underlying third factor rather than a direct causal link. Fourth, a brief note on how you would validate causation, such as controlled experiments, randomized load tests, or instrumental variable analysis.

The mistakes people make

Claiming that correlation never appears alongside causation, or that correlation is simply useless. Another red flag is offering a purely physical example like ice cream and drowning without connecting it back to software. A dangerous pattern is suggesting you would immediately scale CPU because it correlates with memory, without questioning whether traffic is the real driver. Also, confusing the direction of causation, for example asserting that high memory causes high CPU when the reverse could also be plausible.

What usually comes next

The interviewer might ask how you would prove causation in a production system without running a full experiment. They could ask you to design an A/B test or canary deployment to isolate the effect of one variable. Another follow-up is distinguishing between correlation, causation, and mere coincidence in a noisy metrics pipeline with thousands of time series. You might also be asked how spurious correlations affect alerting and SLO definitions.

A concrete example

Consider a microservice where CPU usage and memory usage both rise sharply at 9 AM every day. A naive reading suggests CPU spikes cause memory pressure, or vice versa. The actual cause is a scheduled batch job that sends a burst of requests; request volume is the confounding variable. If you vertically scale CPU based on the correlation alone, you waste money and still hit memory limits because the root cause is unaddressed. A better response is to throttle the batch, cache results, or scale horizontally based on request queue depth rather than the correlated symptoms.

Interview question

When CPU and memory usage in a microservice both rise at 9 AM because a scheduled batch job increases request volume, which statement best describes the relationship?

  • a.Because the metrics move together daily, no further experiment is needed to prove causation
  • b.CPU usage causes memory pressure, so scaling CPU will prevent the memory spike
  • c.The correlation is spurious and should be dismissed as a monitoring artifact
  • d.CPU usage and memory usage are correlated but not causally related to each other; request volume is a confounding variableCorrect
Why?

The batch job drives both metrics, making request volume a confounding variable that creates correlation without direct causation between CPU and memory. Option B is tempting because the metrics do move together, but it incorrectly asserts a causal direction and ignores the shared root cause.

Just read this? Test yourself on what you have been reading.

Read the original → en.wikipedia.org

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.

See open roles