Python Developer Interview Question

How would you process a forty gigabyte CSV that will not fit in memory?

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

Quick answer

Stream it. Open the file and iterate line by line, or use csv.reader over the file object, so only one row is resident at a time, and push each record through generator stages rather than building intermediate lists. Batch writes to the destination in chunks of a few thousand. If the work is CPU bound, split by byte ranges across processes.

Why interviewers ask this

This checks whether streaming is your instinct or an afterthought. Interviewers see plenty of candidates who reach for pandas read_csv by reflex and then discover the container gets killed. They also want to hear operational thinking: restartability, progress tracking, batching writes, and knowing when the right answer is to stop writing Python and load the file into the database instead.

How to structure your answer

  • Commit to streaming rather than loading.
  • Describe the generator pipeline and batched writes.
  • Add restartability and progress reporting.
  • Say when you would hand it to another tool.

Example answer

Spoken example, first person

Nothing gets loaded whole. A file object is already an iterator over lines, so I read row by row with csv.reader and chain generator stages for parsing, filtering, and transforming, which keeps peak memory at roughly one record regardless of file size. Writes get batched, typically a few thousand rows per insert, because per row round trips to Postgres dominate everything else. Since forty gigabytes takes a while, I make it restartable: track the byte offset or the last processed key in a small state file, log progress every hundred thousand rows, and make the write idempotent with an upsert so a rerun cannot duplicate. If parsing turns out to be the bottleneck rather than I/O, I split the file by byte offsets and hand ranges to a process pool, taking care to align on line boundaries. Honestly, though, my first suggestion is often to skip Python for the load entirely and use the database bulk copy, then do the transformation in SQL, because that is usually an order of magnitude faster.

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 do you handle malformed rows mid stream?
  • Would polars or duckdb change your answer?
  • How would you make the process resumable exactly once?

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