Debug a Node.js car-rental backend: leaked cars, missing new cars, lost edits
Company: Amazon
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Online Assessment
In a timed online assessment, you are given an existing Node.js backend for a car-rental app. You did not write the code. The project comes with API documentation for its endpoints and a preset test suite, and some of those tests currently fail. Three bugs have been reported:
1. **My Cars shows other people's cars.** The My Cars list, which should contain only the signed-in user's cars, also contains cars that belong to other users.
2. **A newly added car does not appear.** After a user adds a car, it is missing from their list.
3. **Edits are lost on refresh.** Editing a car appears to succeed, but after the page is refreshed the car shows its old values.
The three bugs are independent of one another. The goal is to fix all of them until every preset test passes, working quickly in code you have never seen. The source code is not reproduced here, so explain how you would work: which code paths each symptom points to and in what order you would read them, the most likely root causes, what each fix looks like, and how you would confirm it without breaking anything else.
### Constraints and Clarifications
- The project is the app's Node.js backend. The API documentation is the reference for what each endpoint should accept, return and allow.
- Done means every preset test passes.
- Assume a conventional layout (routes, middleware that identifies the signed-in user, handlers or services, and a data store) unless your clarifying questions establish otherwise.
### Clarifying Questions
- How does a request identify the signed-in user (session, token, a header), and does the API documentation say which endpoints require it?
- What is the data store: a database, a JSON file, or an in-memory structure? Is there a cache in front of it?
- Do the preset tests call the HTTP endpoints, the service functions directly, or both, and do they reset the data between tests?
- In bug 3, does a refresh make the client re-fetch from the server, or could the client be showing a locally cached copy?
### Part 1 — My Cars includes other users' cars
Find and fix the reason the My Cars list returns cars owned by other users.
```hint Follow the identity
Trace where the signed-in user's id comes from on this request, and check whether it actually reaches the query that builds the list.
```
#### What This Part Should Cover
- Where the list is filtered, and the ways that filter can end up absent or ineffective
- Where the user's identity should come from, and why not from a client-supplied value
- Whether sibling endpoints share the same ownership gap
### Part 2 — A newly added car never appears
Find and fix the reason a car the user just added is missing from their list.
```hint Split the round trip
Decide first whether the car was never stored or was stored but is not returned. One look at the store tells you which half of the code to read.
```
#### What This Part Should Cover
- Separating a write-path failure from a read-path failure before reading code in depth
- What the create handler must store, including the fields the list relies on, and when it should respond
- How a cache or a list filter can hide a record that was stored correctly
### Part 3 — Edits disappear after a refresh
Find and fix the reason an edit looks successful but is gone after a refresh.
```hint Success is not persistence
Look at what the update handler sends back, and ask whether that response proves anything was written.
```
#### What This Part Should Cover
- Why a successful response can coexist with no persisted change
- How the update locates the record, and what happens when it matches nothing
- What the handler should return so that the client sees the stored state
### What a Strong Answer Covers
- Running the suite first and mapping each failing test to one of the three symptoms
- Reading each endpoint against its documented contract instead of guessing
- Small, targeted fixes, one bug at a time, with the full suite rerun after each
- Recognizing that bug 1 is an access-control flaw, not only a display bug
- Sensible time allocation across three independent bugs
### Follow-up Questions
- Your fix for bug 1 covers the list. How would you check that fetching, editing or deleting a single car by id cannot reach another user's car either?
- Beyond the preset tests, which test would you add for each bug so that it cannot come back unnoticed?
- If an AI coding assistant were available in the environment, how would you use it on this unfamiliar codebase, and what would you still verify yourself?
- If the store turned out to be a JSON file written by several requests at once, what new failure could also lose edits, and how would you prevent it?
Overview: An unfamiliar Node.js car-rental backend with API documentation and failing preset tests has three independent bugs: the My Cars list shows other users' cars, newly added cars never appear, and edits vanish after a refresh. The question tests systematic debugging, ownership checks across endpoints, and confirming that writes really persist.
Read the full Amazon Software Engineer interview experience this question came from