Fix Wrong Appointment Statuses and Speed Up Appointment Queries in a Full-Stack App
Company: Headway
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: hard
Interview Round: Onsite
You are given a full-stack web application for booking appointments, along with a database seeded with sample data, and you may use an AI coding assistant during the session. The interviewer reports one symptom: some appointments show the wrong status. Your job is to find the cause and fix it. The interviewer gives little detail beyond that symptom, so asking questions and reading the code base carefully are part of the exercise.
After your fix works, the interviewer adds a request that was not mentioned at the start: some queries that read appointments need to be optimized.
The code base is not reproduced here. For each part, explain how you would work through it, what you would look for in the code and data, and how you would confirm and fix each likely cause.
### Clarifying Questions
- Which appointments show the wrong status? Can I see two or three specific records, with the status shown and the status expected?
- Where does the wrong status appear: in the API response, on the web page, or both?
- Is the status stored in the database, or computed from fields such as the start and end times?
- Are there existing tests, and may I add new ones?
### Part 1: Find and fix the wrong appointment statuses
Starting from the symptom, find the cause of the wrong statuses, fix it, and show that the fix works.
```hint Trace one record end to end
Pick one appointment whose status is wrong and follow its status from the database row, through the API response, to what the page shows. The first layer where it is wrong is where to look.
```
#### What This Part Should Cover
- Reproducing the problem on specific records before changing code.
- Candidate causes checked against evidence, and the confirmed root cause.
- A fix at the source of truth, with a regression test and a plan for records that are already wrong.
- How suggestions from the AI assistant were checked before being kept.
### Part 2: Optimize the appointment queries
Some queries that read appointments now need to be faster. Find which ones are slow and why, and fix them.
```hint Measure before changing
Find out how many queries one page load sends and how the database executes the slowest one before choosing a fix.
```
#### Clarifying Questions for this Part
- Which pages or endpoints are slow, and what response time is the target?
- How many rows does the production table hold compared with the seeded data?
#### What This Part Should Cover
- Identifying the slow queries with evidence, such as query logs and query plans.
- Fixes matched to each cause: indexes, query shape, batching or pagination.
- Checking that results are unchanged and faster, and stating what each fix costs.
### What a Strong Answer Covers
- Steady, specific questions when information is thin, and assumptions stated out loud when answers stay vague.
- Enough reading of the code base to understand the data flow before editing.
- Fixes verified by running the application and the tests.
- Critical use of the AI assistant: precise prompts and reviewed output.
### Follow-up Questions
- The fix corrects new appointments, but thousands of existing rows still hold the wrong status. How do you repair them safely?
- Should the status be stored or derived from the appointment times? What does each choice cost?
- After you add an index, reads are fast but creating appointments got slower. What happened, and what do you do?
- How would you keep this class of status bug from coming back?
Overview: In an AI-assisted coding session on a full-stack appointment booking app, find why some appointments show the wrong status and fix it, then speed up slow queries that read appointments. It tests debugging with little information, reading an unfamiliar code base, verifying AI suggestions and query optimization.
Read the full Headway Software Engineer interview experience this question came from