Code Review Excellence
Code Review Excellence
At companies like Google, Meta, and Stripe, code review is not a formality — it is the primary quality gate before any change reaches production. Engineers at those companies say that a well-run review culture catches more bugs than any automated test suite, spreads architectural knowledge faster than any wiki, and is the main mechanism by which junior engineers learn to think like seniors. This lesson teaches you how to run that process: structuring pull requests for fast, high-quality review; building a feedback culture that does not create defensiveness; and using tooling such as CODEOWNERS and review automation to remove human bottlenecks.
Pull Requests: The Anatomy of a Reviewable Change
The single strongest predictor of review quality is diff size. A pull request with 50–200 lines of changed code gets reviewed carefully; one with 2,000 lines gets rubber-stamped because no reviewer can hold the full context in working memory. At Google, the internal review system (Critique) surfaces a health score that degrades sharply beyond 400 lines. The reason is cognitive: reviewers start skimming, missing logic errors, and approving just to unblock the author.
- One concern per PR. Refactoring, feature addition, and bug fix are three separate PRs — not three sections of one monster PR.
- Self-review first. Open your own diff in the GitHub UI before requesting reviewers. You will catch 30–40 % of comments before anyone else sees it.
- Write a meaningful description. Explain why the change exists, link the ticket, describe the testing approach, and flag any intentional trade-offs. Reviewers should not have to context-switch to Jira to understand what they are reading.
- Draft PRs for early feedback. Open a PR in Draft mode as soon as you have a skeleton. This invites architectural discussion before you invest days in the wrong direction.
main. GitHub and tools like Graphite natively support this. Reviewers read each layer independently; the final merge is a clean squash onto main.
The PR Template: Consistent Context at Scale
A pull request template enforces the minimum context every reviewer needs. Place a PULL_REQUEST_TEMPLATE.md file in the .github/ directory and GitHub will pre-populate the body of every new PR.
Review Culture: Feedback That Improves Code Without Breaking People
Google's internal code review guide distinguishes between nits (minor style preferences that should not block merge), suggestions (optional improvements), blocking comments (must be resolved), and questions (reviewer needs clarification, not necessarily a change). Using these labels in every comment removes ambiguity and prevents authors from spending hours on feedback the reviewer did not even think was mandatory.
- Comment on the code, never on the person. "This function has three responsibilities" instead of "You clearly did not think about this."
- Explain the why behind every blocking comment. A comment that just says "refactor this" teaches nothing and frustrates the author.
- Approve with comments. If the remaining items are nits, approve and let the author decide — do not hold up a deploy over a variable name.
- Respond within one business day. Long review queues are the main reason teams abandon the process and merge without review. If you cannot review by end of day, say so and suggest someone else.
CODEOWNERS: Automatic Reviewer Assignment
The CODEOWNERS file (placed in .github/, the repo root, or docs/) maps file path patterns to the GitHub users or teams who own that code. GitHub automatically requests a review from the matching owner whenever a PR touches those paths. This eliminates the manual step of tagging reviewers and ensures that the person with the most context always sees relevant changes.
When combined with branch protection rules that require CODEOWNERS approval, you get a hard guarantee: a migration cannot merge without a DBA sign-off, and no one can accidentally bypass it. Configure this in GitHub under Settings → Branches → Branch protection rules → Require review from Code Owners.
Review Automation: Let Bots Handle the Mechanical Work
Every comment a human reviewer writes about formatting, import order, or test coverage is cognitive overhead that should be automated. The goal is to make humans focus on logic, architecture, and safety — everything else runs in CI before reviewers even open the diff.
Adding a PR size labeler surfaces diff size visually for reviewers. An XL label is a social signal that the PR needs to be split — no policy required, just visibility.
git rebase --autosquash before merge.
Closing the Loop: Review Metrics That Matter
High-performing teams track review health quantitatively. The four metrics to instrument (via GitHub's API or a tool like LinearB or DX) are: Time to First Review (target under 4 hours), Review Turnaround (time from last push to approval, target under 24 hours), PR Cycle Time (open to merge, target under 2 days for most changes), and Review Iteration Count (how many round-trips before approval — more than 3 suggests the description was unclear or the PR was too large). Tracking these makes bottlenecks visible and gives teams a concrete target to improve.