Python
Python Backend Interview Questions: What Strong Answers Cover
Representative Python backend interview questions with the concepts, trade-offs, and follow-ups a strong answer should address.
Python backend interviews often begin with familiar language behavior and then move toward production concerns: concurrency, database consistency, background jobs, security, and observability.
The questions below are not a list to memorize. Use them to practice building complete explanations and handling likely follow-ups.
1. What is the difference between is and ==?
A strong answer distinguishes identity from equality. is checks whether two references point to the same object. == asks the objects whether their values should be considered equal.
The common follow-up is how to check for None:
if value is None:
handle_missing_value()None is a singleton, so an identity check expresses the intent and cannot be changed by a custom equality implementation.
2. Why are mutable default arguments dangerous?
Default argument expressions are evaluated when the function is defined, not each time it is called. A list used as a default can therefore be shared across calls.
def add_tag(tag: str, tags: list[str] | None = None) -> list[str]:
if tags is None:
tags = []
tags.append(tag)
return tagsA good explanation connects the behavior to object lifetime instead of only repeating the rule “do not use mutable defaults.”
3. When would you use asyncio, threads, or processes?
Start with the workload:
asynciois a good fit for high-concurrency I/O when the libraries in the call path support async operation.- Threads can integrate blocking I/O libraries and work well when the workload spends most of its time waiting.
- Separate processes or external workers are appropriate for CPU-heavy work that would otherwise block progress and compete under the GIL.
Strong answers also mention operational constraints. A CPU-heavy image job may belong outside the request process even if a process pool could technically execute it, because isolation, timeouts, retries, and capacity control matter.
4. What does a database transaction protect?
Avoid describing a transaction as simply “all queries succeed or fail.” Discuss the isolation level and the concurrent behavior the workflow needs.
For example, two requests may both read that the final item is available and then attempt to purchase it. A complete answer explains how a conditional update, row lock, serializable transaction, or constraint prevents an invalid result—and what retry behavior the chosen approach requires.
5. Can a background job run exactly once?
If a worker performs a side effect and crashes before acknowledging its message, the broker may deliver the message again. If it acknowledges first and then crashes, the work may never happen.
Strong answers are careful with the guarantee. They may propose:
- idempotency keys;
- a uniqueness constraint or deduplication record;
- a transactional outbox;
- a provider API that accepts an idempotency key;
- reconciliation for effects that cannot be made atomic.
The right strategy depends on the side effect. Sending an email, moving money, and rebuilding a cache have different consequences.
6. How would you secure a file-upload endpoint?
Cover the full path, not only the file extension:
- authenticate the user and authorize the action;
- limit request and file size;
- generate storage keys instead of trusting filenames;
- validate type from content where practical;
- store uploads outside the executable application path;
- scan or quarantine risky content;
- serve with safe content headers and access controls;
- protect downstream processors from decompression bombs and malformed files.
An interviewer may then narrow the scenario to direct-to-object-storage uploads, public files, or image processing.
7. How do you diagnose growing memory in a Python service?
First separate possibilities: a true leak, intentionally retained objects, an unbounded cache, native allocations, fragmentation, or a traffic-driven increase that has not returned to the operating system.
Then describe a process: reproduce the growth, compare object or allocation snapshots, inspect high-cardinality caches and queues, isolate native extensions, and correlate memory with workload. Mentioning a profiler is useful, but explaining what evidence you want from it is better.
Turn questions into interview practice
For each question, give an initial answer in two minutes. Then spend another five minutes on follow-ups and a concrete production example. The second part is often what separates recognition from working knowledge.
You can also take the Python backend mock interview to practice these topics in a timed round and review feedback by competency.