Python Developer Interview Question

How would you profile a Python service that got slower after a release?

What the interviewer is probing, how to structure your answer, and a spoken example you can adapt.

Quick answer

Start by narrowing where the time goes before touching code. Compare the release diff, check tracing or timing metrics to find the slow endpoint, then profile that path with cProfile or py-spy, which can sample a live process without a restart. Look at cumulative time to find the responsible call, form one hypothesis, change one thing, and measure again.

Why interviewers ask this

Performance questions separate people who measure from people who guess. The interviewer is looking for a method: reproduce, measure, isolate, change one variable, verify. They also want tool fluency, particularly a sampling profiler that can attach to a running production process, and the judgment to know that most Python slowness turns out to be database or network work rather than the interpreter.

How to structure your answer

  • Establish what changed and where the time goes.
  • Name the profiler you would attach and why.
  • Read cumulative time, not just self time.
  • Change one thing and measure the difference.

Example answer

Spoken example, first person

First question is what actually changed, because a release gives me a short list of suspects. Then I want numbers, not opinions, so tracing spans or per endpoint timing tell me which route regressed and whether the time is in the database, an upstream call, or the process itself. If it is in the process, py-spy is my first reach because it attaches to a running container and samples without a restart, so I can profile the real production workload rather than a synthetic one. A flame graph usually makes it obvious. For a reproducible local case I use cProfile and sort by cumulative time, since self time hides the caller that is really responsible. One caution: profiling changes timing, so I never trust absolute numbers from it, only relative shape. Then I change exactly one thing and measure again. Last time I did this the culprit was a new serializer doing a deep copy per row, and killing that copy took the endpoint from four hundred milliseconds back to ninety.

Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.

See how it works

Follow-up questions to expect

  • How does py-spy differ from cProfile?
  • How would you profile memory rather than time?
  • What if the regression only appears under load?

Related python developer questions

Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.

Predict my questions

Rehearse the hard questions before they are asked

Practise with a live copilot, then walk in ready. A $29 Session Pass gets you through the interview with no subscription and no lock-in.

Get GhostPilot