How to Explain a Bug You Fixed: A Double-Booking Example

Interviewers ask about bugs because a fixed bug shows how you think when you do not know the answer. Many candidates reply with a missing semicolon, or with a long story that ends in “and then it worked”. A better answer is small and exact: what was wrong, how you proved the cause, what you changed and how you know it stays fixed. Here is a complete example from a student room-booking app, with the code, followed by a two-minute version you can model your own answer on.

The report and the first wrong idea

Two clubs arrived for the same seminar room at 4 pm, and both had a confirmation. The booking code looked correct:

const clash = await db.query(
  `SELECT 1 FROM bookings
   WHERE room_id = $1 AND starts_at < $3 AND ends_at > $2`,
  [roomId, startsAt, endsAt]
);
if (clash.rowCount > 0) throw new Error("Room is taken");

await db.query(
  `INSERT INTO bookings (room_id, club_id, starts_at, ends_at)
   VALUES ($1, $2, $3, $4)`,
  [roomId, clubId, startsAt, endsAt]
);

The overlap check is right. An existing booking clashes when it starts before the new one ends and ends after the new one starts. Booking the room twice by hand always gave the correct error.

The first idea was that someone had clicked the button twice, so the button was disabled after a click. That did not explain the report: the two bookings came from different clubs on different phones. It is fine to include a wrong idea like this in an interview, as long as you say which fact ruled it out.

Checklist
  • Write the symptom as a user would see it
  • Keep the original code or the commit
  • Note the fact that ruled out your first idea

Find the cause with a timeline

The created times of the two rows were 40 milliseconds apart. That suggested both requests were running together:

StepRequest from Club ARequest from Club B
1Checks for a clash, finds none
2Checks for a clash, finds none
3Inserts its booking
4Inserts its booking

Each request was correct alone. Together, the second check ran before the first insert was saved. This is a race condition: the result depends on timing.

Guessing is not enough, so reproduce it. A short script sends ten requests for the same room and time at once and counts how many succeed:

const attempts = Array.from({ length: 10 }, (_, i) =>
  fetch("http://localhost:3000/bookings", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      roomId: 7, clubId: i + 1,
      startsAt: "2026-12-10T16:00:00+05:30",
      endsAt: "2026-12-10T17:00:00+05:30",
    }),
  })
);
const results = await Promise.all(attempts);
console.log(results.filter((r) => r.status === 201).length);

The correct output is 1. If your version prints a larger number, you have reproduced the bug. Because timing varies, run it several times.

Checklist
  • Draw two requests side by side
  • Write a script that shows the bug
  • Run it more than once

Put the rule where both requests must meet

Adding a delay or a second check only makes the gap smaller. Both requests pass through the database, so the rule belongs there. PostgreSQL can refuse overlapping time ranges for the same room:

CREATE EXTENSION IF NOT EXISTS btree_gist;

ALTER TABLE bookings
  ADD CONSTRAINT no_overlapping_bookings
  EXCLUDE USING gist (
    room_id WITH =,
    tstzrange(starts_at, ends_at) WITH &&
  );

Read it as: no two rows may have an equal room_id and overlapping time ranges. By default the range includes the start and excludes the end, so a 3 to 4 pm booking and a 4 to 5 pm booking are both allowed. The columns here are timestamptz.

The second insert now fails with error code 23P01. The API should catch that code and return a clear message such as "This room was just booked for that time", with status 409. The earlier check can stay, because it gives a quick answer in the usual case. It is no longer what keeps the data correct.

One practical point: the constraint cannot be added while overlapping rows already exist. Find them first, and let the clubs decide which booking stays. Do not delete one silently.

Checklist
  • Explain why a second check would not help
  • Handle the database error in the API
  • Say what you did with existing bad data

The two-minute answer

Here is the same story at speaking length:

"In our room-booking project, two clubs got a confirmation for the same slot. My first guess was a double click, but the rows had different users, created 40 milliseconds apart. I realised both requests could pass the availability check before either one saved. I wrote a script that sent ten requests together, and more than one succeeded, so I had reproduced it. I moved the rule into PostgreSQL with an exclusion constraint on room and time range, and returned a 409 with a clear message when it fails. I ran the same script again and exactly one request succeeded. I kept it as a test. If I did it again, I would think about two users acting at once when designing the table."

Notice what is missing: no list of every tool in the project and no invented percentage. "Exactly one of ten requests succeeded" is a result you can show.

Use this example to learn the structure, not as your own story. Interviewers ask follow-ups that only someone who did the work can answer.

Checklist
  • Symptom, cause, proof, fix, check, lesson
  • Keep it under two minutes
  • Use only results you can reproduce

Follow-up questions to prepare

  • Would a transaction alone fix it? Not at PostgreSQL’s default isolation level, Read Committed. Both transactions could still find no clash. Serializable isolation can prevent it, but your code must retry when the database cancels one transaction.
  • Could you lock the room instead? Yes. SELECT ... FROM rooms WHERE id = $1 FOR UPDATE inside the transaction makes the second request wait. It works if every path that creates a booking takes the same lock.
  • What if you use MySQL? It has no exclusion constraint, so a row lock on the room is a common choice. If bookings use fixed one-hour slots, a unique key on room and slot is simpler.
  • How would you test it automatically? Run the ten-request script against a test database and check the number of rows, not only the status codes.

If you do not know an answer, reason from the timeline: "I would check whether both requests can still read before either one writes." To practise aloud, use the recording method in The Self-Directed Mock Interview Framework: Video Recording, Evaluation Rubrics, and Systematic Iteration.

Checklist
  • Prepare one alternative fix and its drawback
  • Know your database’s default isolation level
  • Practise the answer aloud once

What to remember

  • Explain the symptom, the proof, the fix and the check, in that order.
  • A rule that must always hold belongs where every request has to pass, which is often the database.
  • A reproducible result is stronger than an impressive percentage.

Common questions

My project never had a serious bug. What can I say?

Look at your commit history for fixes, or test your project now: use a slow network, two browser tabs, empty input and a long list. You will probably find something. Fix it and explain it honestly as a problem you found while testing.

Can I talk about a bug a teammate fixed?

Yes, if you say so. Explain your part, such as reproducing it or reviewing the change. Interviewers notice when “we” hides who did the work.

Should I share my screen and show the code?

Offer it if the interviewer wants detail. Have the commit open and the sensitive values removed. Start with the spoken version so they know what to look for.

Sources and further reading

Campus to Career. Runs CampusToCareer, a job board and set of free preparation tools for Indian freshers. Examples in this guide are illustrations. Replace them with your own work, and write to campustocarrer@gmail.com if a step is out of date.