Design an experiment and logging to link API latency to engagement

Causal inference and data integration. Randomly inject latency for a treatment group with a control at baseline, then join server trace IDs to client events via a shared request ID. Never confuse correlation with causation or miss join issues.
What's really being asked
The interviewer wants to see if you can move beyond dashboard correlation and build a causal argument. They are looking for three specific competencies: designing a valid randomized controlled experiment, instrumenting a distributed system so server-side performance data can be reliably joined with client-side behavioral data, and reasoning about statistical power and confounders at scale.
The full answer
First, define the hypothesis and primary metric. State that the hypothesis is that added API latency reduces items viewed per session, and pick a guardrail metric like error rate so you do not harm reliability. Second, describe the randomization mechanism. Explain that you would bucket users or sessions randomly at the edge or API gateway into control and treatment groups, ensuring that the treatment group receives artificially injected latency while the control group receives baseline performance. Third, detail the logging contract. Propose that every API response includes a unique trace ID or request ID in a response header, and that the client analytics payload echoes that same ID when it fires engagement events like item viewed or session heartbeat. Fourth, explain the join strategy. Describe landing both streams, server performance logs and client analytics events, into a common data warehouse, then joining on the shared trace ID with a time bounded window to handle clock skew. Fifth, mention analysis. Note that you would compute the difference in means for items viewed per session between the two groups and use a statistical test to check significance, rather than just comparing averages.
The mistakes people make
A major red flag is proposing to analyze historical observational data by regressing engagement on response time. This fails because user segments, device types, and network conditions confound the relationship; slow responses may correlate with heavy users on poor networks rather than causing disengagement. Another red flag is suggesting a join on user ID plus timestamp without a shared request identifier, which produces a Cartesian product and inflates row counts. A third red flag is ignoring sample size and power, leading to an experiment that runs for weeks without a detectable effect.
What usually comes next
The interviewer may ask how you would handle dropped client events when the network is slow. A strong answer discusses using sessionization and probabilistic attribution or comparing per session metrics only for sessions with at least one ping. They may also ask how you would roll this out safely. Mention canary deployments, automatic shutoffs if error rates spike, and stratified randomization to preserve cohort balance. They might also probe how you would detect novelty effects versus true latency sensitivity by running the experiment for multiple business cycles.
A concrete example
Imagine an e-commerce search API. You add a sleep middleware that injects 200 milliseconds of latency for the treatment group. The API response header includes X-Request-ID. The mobile client reads this header and attaches it to every analytics event fired during that session. In your warehouse, you join the server log row, which has request ID and latency, to the client event rows sharing that request ID. You aggregate to the session level, summing items viewed, then compare the treatment distribution to the control using a t-test. If the treatment mean is 4.2 items and the control mean is 5.1 items with a p-value below 0.05, you have evidence that latency causes the drop.
Interview question
Several API requests from one user overlap within the same second. What is the most reliable way to link each client event to its corresponding server request?
- a.Match solely on identical client and server timestamps
- b.Match solely on the user ID
- c.Match each event to the nearest timestamp without checking a request identifier
- d.Propagate a unique request identifier and join the matching client and server records on itCorrect
Why? this is the answer
A shared request identifier distinguishes concurrent requests from the same user. User IDs and timestamps alone can be ambiguous, and device clocks may differ. Whether a join duplicates, drops or misattributes records depends on its predicate and data; a missing request identifier does not inevitably create a Cartesian product.
Just read this? Test yourself on what you have been reading.
Read the original → optimizely.com
- #experiment design
- #causal inference
- #data engineering
- #a/b testing
- #distributed tracing
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.
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