Code Review and Working with Existing Codebases Questions
Reviewing others' code and navigating unfamiliar systems: giving and receiving actionable review feedback, spotting correctness and design issues, and reading and understanding large or legacy codebases before changing them. Covers collaborative coding norms, incremental change in shared repositories, and verifying changes against existing behavior. The team-facing side of day-to-day engineering.
You are reviewing a change that reduces test coverage from 85% to 68% but the author argues the removed tests were flaky and unreliable. As a reviewer, outline a principled decision process: what evidence to request, how to measure test value, alternatives to removing tests, and how to document the decision so future reviewers can understand the risk.
Sample Answer
Direct answer
Don't accept "the tests were flaky" as self-certifying. Treat a large coverage drop as a risk decision that needs evidence: ask for the flakiness data, look for a way to keep the safety net while removing the noise (fix, quarantine, or narrow the test before deleting it), and if deletion really is the right call, document the risk and the reasoning so a reviewer looking at this months later can see what trade-off was made and why.
Structured elaboration
Evidence to request. Continuous integration (CI, the automated pipeline that builds and runs tests on every change) history for the removed tests over recent weeks, showing pass/fail per run; failure logs for a few representative failures; any links to prior attempts to fix them; and a plain description of what behavior each removed test actually asserted, since "flaky" and "not worth having" are two different claims that both need their own evidence.
How to measure test value. A useful starting point is a flakiness rate: how often a test fails non-deterministically, out of how many runs, over a recent window. Teams commonly treat anything in the low single digits as worth investigating and anything much higher as a real problem, but that's a tunable convention to calibrate to your own pipeline, not a fixed rule. Weigh that flakiness rate against the test's actual defect-detection value: does it cover a code path that has broken in production before, or a genuinely critical invariant, versus an incidental implementation detail that happens to be covered along the way?
Alternatives to removing tests. Fix the root cause (replace a real sleep-based wait with an explicit event or a fake clock, mock a flaky network call, isolate shared test state between runs); quarantine the test into a separate, still-running "known flaky" suite that's tracked but doesn't block merges; add a bounded, justified retry for a genuinely transient cause; or narrow the test so only the brittle assertion is removed, keeping the rest of the coverage.
Documenting the decision. Put the evidence, the alternatives considered, and the reasoning for why deletion won (or why a different fix was chosen) into the PR (pull request) description or a linked ticket, with a named owner and, for anything quarantined rather than truly resolved, a re-evaluation date. A future reviewer looking at the coverage graph should be able to find out why it dropped and whether that was a considered decision or a silent regression.
Worked example
An illustrative review comment applying this process to the scenario in the question:
"This PR removes 4 tests and drops coverage by a double-digit number of percentage points. Before I approve: can you attach the CI history showing these 4 failing intermittently over the last several weeks, and confirm whether you tried at least one stabilization approach, for example replacing a sleep-based wait with an explicit event, before deciding to delete them? If they're genuinely not fixable in a reasonable time, I'd rather see them moved into a quarantined suite with a tracking ticket and an owner than deleted outright, so we don't lose the safety net for the code path they cover. Either way, please add a short note to the PR description with the evidence and the decision, so this is traceable later."
Trade-offs and pitfalls
Quarantining without real follow-through is functionally the same as deletion but looks safer on paper, so a quarantine ticket needs a real owner and a real re-evaluation date, not just a label that never gets revisited. Sometimes a test genuinely is asserting an implementation detail rather than behavior, and removing it is a real improvement, so don't reflexively block every coverage drop, the point is evidence, not a floor on the percentage. The biggest pitfall is judging purely by the coverage number: two tests covering the same trivial line count the same toward that percentage as one test covering a critical path that has actually broken production before, so the review has to look at what was removed, not just how much.
A reviewer used harsh language in comments and the author felt publicly humiliated. As the engineering manager, describe a stepwise plan to de-escalate the situation, repair relationships, update code review guidelines, and prevent similar incidents, including any coaching, documentation changes, and follow-up measurements.
Sample Answer
Direct answer
As the engineering manager, act on two tracks at once: repair the specific relationship and any public harm quickly and privately, and separately fix the guidelines or process so this failure mode doesn't repeat. Treat a single conversation as the start of the fix, not the end of it, and check back later.
Structured elaboration
- Talk to the author first, 1:1. Acknowledge the harm directly without minimizing it, and ask what they need right now, whether the comment should be edited or removed, or whether they'd prefer a different reviewer on this PR (pull request).
- Talk to the reviewer separately, not in a group setting. Be direct that the language was out of line regardless of whether the underlying technical point was right, and get their perspective, rushed, frustrated, unaware of tone, without treating that as an excuse for the impact.
- Repair publicly if the harm was public. If the comment was visible to the team, a short, genuine acknowledgment of what happened is worth more than a vague "let's all be kind" message that erases the specifics; the goal is for the team to see it was actually addressed.
- Close the structural gap. Check whether the team's review guidelines say anything about tone and conduct at all. If they don't, that's a process gap, not solely the reviewer's individual failure, and it's the manager's job to close it, e.g. adding an explicit norm plus example phrasing (this is a nit, this is blocking, avoid absolute language like "this is terrible") to the team's review guide.
- Coach, don't just discipline, for a first occurrence. Work through concrete feedback practices together: phrasing comments about the code rather than the person, leading with a question instead of a command, labeling severity explicitly so a blocking issue doesn't read as optional, and pairing any criticism with a specific alternative rather than a bare complaint. Consider having the reviewer shadow reviews from someone whose feedback style already does this well. If this turns out to be a repeat pattern, it escalates beyond coaching.
- Follow up and actually measure it. Check in with the author privately again a couple of weeks later, not just once, to see if the relationship genuinely repaired rather than just went quiet. Watch later review threads for whether tone actually changed; a guideline that's written down but never checked tends to fade.
Worked example
A reviewer writes something like "this is embarrassing, did you even test this" on a junior engineer's PR, visible to the whole team channel. The manager messages both people privately within the day, has the reviewer edit the comment, and posts a short, honest acknowledgment in the channel rather than a vague platitude. The team's review guide gets an explicit tone section with example blocking-versus-nit phrasing. Two weeks later, the manager checks in privately with the junior engineer, not just assuming things are fine because nobody's raised it again.
Trade-offs and pitfalls
Over-correcting into a heavily policed review culture, where people are afraid to say anything critical, is its own failure mode; the goal is honest, direct feedback delivered respectfully, not conflict avoidance. Treating this as purely an individual coaching issue without fixing the guideline gap means the next person makes the same mistake. Treating it as purely a documentation fix without a real conversation with both people leaves the actual relationship unrepaired.
List five elements you always include in a pull request description to make reviews efficient for team members and new joiners. Explain why each element matters for maintainability, discovery, and onboarding.
Sample Answer
Direct answer
A good pull request (PR, a proposed code change submitted for review) description answers what changed, why, how it was tested, what the reviewer should focus on, and what's deliberately out of scope. Each element saves a reviewer from reconstructing context from the diff alone, and later saves an engineer doing archaeology on why the code looks the way it does.
Structured elaboration
Five elements and why each matters
- What changed (a one-to-two sentence summary): gives the reviewer a frame before reading the diff line by line; without it they infer intent from code, which is slower and more error-prone
- Why (the motivating problem, with a linked ticket or incident if there is one): this is the piece that survives long after the code changes again; an engineer later using
git blameor the commit log to understand "why is this here" finds the why in the description, not the diff - How it was tested: tells the reviewer what confidence already exists (unit tests added, manually verified in staging), so they know what's already covered versus what still needs scrutiny
- What to focus review on: the author usually knows which part of the diff is riskiest or most novel; naming it directs a time-constrained reviewer's attention where it matters most
- What's explicitly out of scope: prevents scope-creep comments ("why didn't you also fix X") and tells a future reader that a related-looking issue was a deliberate non-goal, not an oversight
Why this matters beyond the immediate review
- Maintainability: the description becomes permanent documentation attached to the commit history; months later it's often the only record of intent
- Discovery: someone tracing "why does this function do X" through the commit log finds the description as the answer, faster than re-deriving it from the diff
- Onboarding: a new engineer reading recent PR history to understand a codebase's evolution gets a narrated version of the system's history instead of bare diffs
Worked example
A PR titled "Fix race condition in session refresh" with the description "fixes bug, see diff" forces the reviewer to reverse-engineer what race condition, why this fix addresses it, and whether it was actually reproduced. Contrast: "What: adds a lock around session-token refresh. Why: intermittent authentication failures under concurrent requests, traced to two requests refreshing the same token at once and one overwriting the other's write. Tested: added a test that fires 50 concurrent refresh calls and asserts exactly one network call happens; manually reproduced the original bug on staging before the fix and confirmed it no longer reproduces after. Focus review on: the lock's scope, it needs to cover the full read-modify-write, not just the write. Out of scope: the underlying token storage isn't thread-safe either, that's a separate, larger fix tracked elsewhere." A reviewer can now scrutinize exactly the risky part (the lock's scope) instead of re-deriving the whole problem, and anyone reading this PR later understands both the bug and the deliberate boundary around the fix.
Trade-offs and pitfalls
- A template that's too long or bureaucratic gets filled in with boilerplate nobody reads; keep it to the elements that actually change reviewer behavior
- A "why" section that just restates the ticket title without the actual reasoning doesn't help; the value is in the reasoning, not a ticket number
- Descriptions get stale if the PR's scope changes mid-review and nobody updates them; treat the description as something to revisit before merge, not only before opening the PR
When reviewing code that touches user data storage and retrieval, what privacy and data-protection checks should you perform, and what would you want to see as concrete verification (not just an assurance) for each one?
Sample Answer
Direct answer
When a PR (pull request) touches how user data is stored or retrieved, review for four concrete things, what's collected, who can access it, how it's protected, and how it can be deleted, and insist on evidence for each one in the diff or PR description, since a comment claiming "it's handled" is exactly the gap that causes real incidents.
Structured elaboration
| Check | What to verify concretely |
|---|---|
| Data minimization | Does the PR description name the specific reason each new stored field is needed, not just "might be useful later"? |
| Access control | Point to the actual authorization check in the diff, a permission check or a row-level filter, not a comment asserting it's protected |
| PII (personally identifiable information) in logs | Grep the diff for new log statements touching user-supplied fields (email, name, IP, raw request bodies) and confirm they're redacted or omitted, not assumed safe because it's "just for debugging" |
| Encryption and handling | For a new field holding sensitive data (credentials, tokens, anything regulated), check it goes through the team's existing encryption or hashing utility rather than being stored raw, and that it can't leak into a client-facing API response by accident |
| Retention and deletion | If this data needs to be deletable later, e.g. for an account-deletion request under a privacy regulation such as GDPR (the EU's General Data Protection Regulation), check whether the PR updates or at least mentions the existing deletion or export path, or whether it silently creates a new place data lives that path doesn't know about |
Worked example
A PR adds a "recently viewed items" feature that stores a user's view history in a new table. Review pass: data minimization, does the feature need the full page content, or just an item ID and timestamp? Access control, is the table filtered by the requesting user's ID at the query level, not just hidden in the UI? Logging, a new debug log line dumps the entire view-history payload including the user's session token; flagged and removed. Retention, the existing account-deletion job doesn't touch this new table yet; raised as a blocking comment before merge.
Trade-offs and pitfalls
Treating this checklist as something only a dedicated security or privacy reviewer does means it gets skipped on every "small" PR by everyone else, and most real incidents come from exactly this kind of small, unglamorous change. Blocking every PR pending a full compliance review for genuinely low-risk data is its own failure mode, it trains people to route around the review entirely. Calibrate scrutiny to the actual sensitivity of the specific field, rather than treating all user data as equally high-risk.
How would you establish a healthy code review culture for a team of 10 engineers? Include guidelines (e.g., review SLAs, size limits), tooling or automation you'd use, ways to keep reviews constructive, and metrics to track review health over time.
Sample Answer
Direct answer
Healthy review culture for a 10-person team rests on four things: norms that are written down instead of living only in people's heads, automation that handles anything mechanical so humans only judge what machines can't, feedback habits that separate blocking issues from opinions, and a couple of lightweight metrics you watch as a team trend, not a scorecard on individuals.
Structured elaboration
Guidelines to write down explicitly
- A review service-level agreement (SLA, an explicit response-time target): for example, first response (even just an acknowledgment) within one business day
- A soft pull request (PR, a proposed code change submitted for review before merging) size guideline, around 300-400 changed lines, as a norm that prompts a conversation, not a hard block
- Who reviews what: at minimum one reviewer, with a config file like CODEOWNERS (a file that maps directories or paths to the people or team required to review changes there) routing risky areas to the right person
- A shared convention for what blocks merge versus what's a nit, e.g. prefixing non-blocking comments with "nit:"
Tooling and automation
- Continuous integration (CI, the automated pipeline that builds and tests every push) must pass before a human review even starts, so reviewers spend attention on logic, not formatting or broken builds
- An auto-formatter enforced in CI so style is never a discussion
- A PR template with a description and testing section, so reviewers get context before they open the diff
- A stale-PR reminder (a bot nudge after 24-48 hours with no review) instead of a person having to nag
Keeping it constructive
- Comment on the code, not the person; phrase feedback as a question or suggestion ("what happens if this is empty?") rather than a command
- Call out good patterns in-line, not only problems
- Have the author explicitly separate "must fix" from "worth considering" in their own replies, so an optional suggestion doesn't turn into a blocking argument
Metrics to track over time
- Median time-to-first-review, to see if the SLA is actually being met
- Median PR size, to catch it drifting upward before it becomes a review bottleneck
- Review iteration count, a high number can mean unclear expectations or real scope creep, worth a look either way
- Report these at the team level over weeks or a quarter, never as an individual leaderboard, since metrics used to grade people get gamed
Worked example
A 10-engineer team starts tracking a rolling two-week median time-to-first-review. It's sitting at 30 hours against a one-business-day (roughly 8-hour) target. Looking at PR size alongside it, the median has crept from 150 to 420 lines over two months. Instead of telling people to "review faster," the team addresses the size trend directly: they add a bot that comments (not blocks) suggesting a split when a diff exceeds 400 lines, and a daily digest listing PRs waiting over 24 hours. Four weeks later, median size is back near 200 lines and time-to-first-review is under 12 hours, because smaller PRs are simply faster for people to unblock.
Trade-offs and pitfalls
- A hard size limit gets gamed, people split one change into artificial, badly-scoped pieces just to dodge it; keep it a norm with a conversation, not a blocking gate
- Metrics tied to individual performance reviews reliably erode trust and get gamed; keep them team-level and diagnostic
- Over-automating can remove judgment entirely, a linter should nudge a reviewer, not replace their read of whether a diff hangs together as a whole
- An SLA introduced without addressing capacity (too few reviewers for the review load) just adds pressure without fixing the real bottleneck
Unlock Full Question Bank
Get access to all Code Review and Working with Existing Codebases interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.