Backend Developer Interview Question

A single table has grown to several billion rows and writes are slowing down. What are your options?

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

Quick answer

Exhaust the cheaper options first: better indexes, archiving cold rows, moving large columns out, and read replicas for read load. Then partition the table, usually by time or tenant, so each partition stays small and old partitions can be dropped instantly. Sharding across separate databases comes last, because it costs you cross shard queries, distributed transactions and rebalancing, and the shard key choice is very hard to change later.

Why interviewers ask this

The interviewer wants to see that you scale in order of cost rather than jumping to the most complex solution. They are listening for the distinction between partitioning within one database and sharding across many, for a sensible shard key discussion including hot spots, and for the operational reality of migrating a live table. Reaching straight for sharding is usually a red flag.

How to structure your answer

  • Diagnose first: is it writes, index maintenance or lock contention.
  • Order the options from cheapest to most invasive.
  • Explain partitioning and the pruning and retention benefits.
  • Cover shard key selection and what you lose by sharding.

Example answer

Spoken example, first person

First I would find out what is actually slow, because a big table is not automatically a problem. Usually it is index maintenance on every insert, or a few unused indexes, or autovacuum falling behind. So I start with the cheap wins: drop indexes nothing uses, move a large text or JSON column into a side table so the main rows stay compact, and archive anything older than the retention policy. If it is genuinely still too big, I partition, normally by time for event style data, which keeps each partition small, lets the planner prune to the relevant range, and turns deleting last year's data into dropping a partition rather than a delete that runs for a day. Sharding is the last resort because it changes the programming model: cross shard joins go away, transactions become distributed, and rebalancing is a project. If I do shard, the key gets real thought, since sharding an events table by customer id gives you a hot shard the moment one customer is ten times bigger than the rest.

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 would you pick a shard key that avoids hot spots?
  • How do you migrate a live table to a partitioned one without downtime?
  • What queries become expensive once data is sharded?

Related backend 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