Code Review Best Practices: Authors and Reviewers
A practical guide to useful code reviews: how to write reviewable code, give constructive feedback, and keep reviews fast and focused.
Introduction
Code review is one of the highest-return activities in software development. Done well, it catches bugs while they are still cheap, spreads how the codebase actually works across the team, and keeps every merge meeting the same bar. The following walks through practices for both authors (who submit code) and reviewers (who evaluate it).
For Authors: Making Your Code Reviewable
1. Keep PRs Small
Aim for 200-400 lines of changed code per PR. Large PRs overwhelm reviewers and increase the chance of bugs slipping through.
# Bad: 2000 lines across 15 files
# Good: 150 lines in 3 related files
Strategies for small PRs:
- Split large capabilities into stacked PRs
- Extract refactoring into separate PRs
- Use feature flags to merge incrementally
2. Write a Clear Description
A good PR description answers:
- What changed and why
- How to test it
- Links to tickets, designs, or related PRs
- Screenshots for UI changes
## What
Add email validation to the user registration form.
## Why
Currently invalid emails pass through and cause downstream
processing errors in the marketing automation pipeline.
## How to test
1. Go to /register
2. Enter "not-an-email" — should see validation error
3. Enter "user@example.com" — should pass
## Related
Fixes #142
3. Self-Review Before Submitting
Review your own PR first. You will catch:
- Leftover debug code (
console.log,print) - Unintended changes
- Missing tests or documentation
- Typo-level bugs
4. Respond to Feedback Constructively
- Assume positive intent from reviewers
- Ask clarifying questions instead of defending
- Separate “must fix” from “nice to have” suggestions
- Update the PR promptly after feedback
For Reviewers: Giving Useful Feedback
1. Review Within 24 Hours
Fast turnaround keeps the author in context and prevents blocked work. If you cannot review in 24 hours, delegate or let the team know.
2. Use a Review Checklist
Systematic reviews are more thorough:
| Category | Questions |
|---|---|
| Functionality | Does it do what the PR claims? Are edge cases handled? |
| Tests | Are there tests for new logic? Do existing tests still pass? |
| Readability | Are names clear? Is complexity justified? |
| Security | Are inputs validated? Are secrets exposed? |
| Performance | Are there N+1 queries? Unnecessary allocations? |
| Maintainability | Is there duplicated code? Will this be hard to change? |
3. Categorize Feedback
Use severity levels to help authors prioritize:
| Level | Meaning | Example |
|---|---|---|
| Blocking | Must fix before merge | ”This query lacks an index; it will scan the entire table” |
| Suggestion | Consider it | ”You could simplify this with map instead of for” |
| Nitpick | Personal preference | ”I prefer single quotes for strings” |
4. Ask Questions, Don’t Dictate
Instead of: “Change this to use a dictionary.”
Ask: “Would a dictionary make the lookup faster here?”
Questions encourage discussion and help the author learn, whereas orders create resistance.
5. Approve with Comments
If the code is acceptable but you have minor suggestions, approve the PR and let the author decide whether to address them. Don’t block merges for nits.
The Review Cycle
A review is a loop, not a gate. The author opens a small, well-described PR; automation runs first so the reviewer never spends human attention on what a machine checks; the reviewer reads for context and correctness; feedback cycles until the change is either approved or clearly blocked. Each stage has an owner and a failure mode — and most review pain comes from skipping a stage, not from any single bad actor.
Comment Examples That Help
The difference between a review that improves code and one that starts an argument is usually phrasing. These patterns work consistently:
# BAD: personal attack
"Why did you do it this way? This is obviously wrong."
# GOOD: focus on the code
"This approach has a potential issue with concurrent access.
Consider using a mutex here. What do you think?"
# BAD: dictatorial
"Change this to use a Map instead."
# GOOD: collaborative question
"Would a Map be more efficient here? The current approach
iterates the array on every lookup, which could be slow
with large datasets."
# BAD: vague
"This code is messy."
# GOOD: specific and actionable
"The `processData` function handles validation, transformation,
and database insertion. Extracting the validation into a
separate function would make each responsibility clearer
and easier to test."
Notice the pattern in the good versions: they name the code, they name the problem, and they end with a question or a concrete suggestion. The reviewer keeps the authority to flag the issue; the author keeps the authority to solve it. If you can’t phrase a comment that way, the comment is probably venting, not feedback — leave it as a draft and come back later.
Reviewing with a Checklist
A checklist turns “I looked at it” into a repeatable process. This one covers what actually catches problems in practice; keep it beside the review, not in a wiki nobody opens.
Functionality
- Does the code do what the PR description says?
- Are edge cases handled (null, empty, boundary values)?
- Are error cases covered with appropriate handling?
- Does the code handle concurrent access if needed?
Design
- Does the change follow existing patterns in the codebase?
- Is the change at the right level of abstraction?
- Are new dependencies justified?
- Is the change over-engineered or under-engineered?
Readability
- Are names clear and intention-revealing?
- Are functions small and focused?
- Are comments explaining why, not what?
Testing
- Are there tests for the new functionality?
- Do tests cover edge cases and error paths?
- Do tests run fast enough for the CI pipeline?
Security
- Is user input validated and sanitized?
- Are secrets and credentials handled securely?
- Are permissions checked correctly?
Performance
- Are there obvious performance issues (N+1 queries, unnecessary loops)?
- Is the change efficient for large inputs?
Documentation
- Is the PR description clear and complete?
- Are breaking changes noted?
Use the checklist as a floor, not a ceiling: it catches the categories that get missed under time pressure, but the hardest review comments are still the ones that need judgment — whether this abstraction is worth it, whether the test actually tests anything, whether the refactor belongs in this PR at all.
PR Size and Review Turnaround
The single strongest predictor of review quality is PR size. Studies across teams converge on the same range: reviews lose effectiveness fast past ~400 lines of change. A 2.000-line PR gets a skim and an “LGTM”; a 200-line PR gets read. If you take one practice from this guide, take this: split work until each PR does one thing.
Splitting is a skill to build, not an excuse to dodge it. Feature flags, stacked PRs, and separating refactors from behavior changes all let you ship in reviewable chunks. The “prepare, then change” pattern — one PR that refactors the surrounding code, a second that adds the feature — produces two easy reviews instead of one impossible one.
Turnaround is the other half of the contract. A review left for three days costs the author the context-switch back to old work and quietly teaches the team that reviews don’t matter. Set a norm — “first pass within one business day” — and treat review as part of the work, not an interruption of it. Teams that measure review latency almost always find it predicts their cycle time better than coding speed does.
Reviewing Different Change Types
Not every PR deserves the same scrutiny. A bug fix needs “does this actually fix it, and is there a regression test”; a new feature needs design review up front, not after 600 lines exist. Spend the heavy attention where the risk is:
- Bug fixes — verify the reproduction case, check for a regression test, look for siblings of the same bug (if
parseDatemishandled DST here, does it elsewhere?). - Refactors — the diff should be mechanical; if a “refactor” also changes behavior, ask for a split. Reviews of pure refactors should confirm the transformation, not re-litigate the design.
- New features — check the public surface first (API shape, naming, error contract); internals can be iterated, the interface can’t.
- Config and infra changes — easy to rubber-stamp, expensive to get wrong. Check defaults, rollouts, and what happens on failure.
- Dependency bumps — skim the changelog for breaking changes; the risk isn’t the diff, it’s what changed underneath it.
Matching effort to risk keeps reviews fast without making them shallow.
Review Patterns That Work
Pair Review
Two reviewers alternate: one reads logic, the other reads tests. Catches different categories of issues.
Tool-Assisted Review
Let automation handle the boring stuff:
- Linters (ESLint, Black, Prettier) for style
- Static analysis (SonarQube, CodeClimate) for complexity
- Security scanners (Snyk, CodeQL) for vulnerabilities
- CI tests for regressions
Reserve human review for architecture, logic, and intent.
Review Roulette
Rotate reviewers so knowledge spreads evenly. Avoid having only senior engineers review everything.
Building a Review Culture
Checklists and norms only stick when the team treats review as everyone’s job, not the senior’s burden. Two practices change the dynamic fastest.
Rotate reviewers. If the same person reviews everything, they become a bottleneck and the rest of the team stops learning. Rotate reviews so knowledge spreads and no single person is the gatekeeper — it also removes the social awkwardness of “always criticizing the same person’s code”.
Review your own reviews. Once a quarter, pick a merged PR and read your own comments as the author would. Did you ask questions or give orders? Did the author learn anything, or just comply? The feedback loop applies to reviewers as much as authors — a team that audits its own review quality improves faster than one that only polices code.
The signal of a healthy culture isn’t speed or defect counts alone — it’s when junior developers start leaving the same quality of comments they receive. That transfer of standards is what a review process is really for.
Handling the Hard Cases
Some reviews are uncomfortable by nature. A few patterns help.
The too-big-to-review PR. When a 3.000-line diff lands anyway, don’t skim it: ask for the split. If splitting isn’t possible, review structurally — read the tests, the public interface, and the diff’s shape rather than every line, and say explicitly what level of review you did. An honest partial review beats a silent skim.
The senior whose code nobody dares review. Authority bias is real: juniors approve senior PRs without reading them. Counter it by making review assignment random where possible, and by seniors explicitly inviting criticism — a senior who says “tell me what’s wrong” gets better reviews than one who says nothing.
The disagreement that won’t resolve. Two reasonable engineers can disagree on design forever. The tiebreaker is ownership: the person who maintains the code decides, after genuinely hearing the objection. Document the dissenting view in the PR so the record exists if it proves right later — “I flagged X” beats hindsight arguments.
The external contributor. Reviews of outside PRs carry an extra obligation: the contributor can’t see your internal docs, doesn’t know the team’s conventions, and may be contributing in a second language or their spare time. Assume good intent longer, be more explicit about what you need (“could you add a test for this case?” rather than “needs tests”), and thank them for the patch — open source review is also community-building.
The hotfix under deadline. Under pressure, review shrinks to “does it fix it” — and that’s acceptable as long as it’s deliberate. Mark it clearly (“reviewed for the fix only, follow-up review needed”), merge it, and schedule the real review as a follow-up task. The mistake isn’t fast-tracking under fire; it’s letting the follow-up never happen and the hacky patch becoming permanent. And when the follow-up review does happen, treat it as real review, not archaeology — the person reading it next quarter won’t know the hotfix context unless you wrote it down in the PR or the commit.
Finally, remember that review skills compound. Every PR you split well, every comment you phrase as a question, every checklist item that becomes a lint rule makes the next review faster and better. Teams don’t get good at code review by writing down a process — they get good by running it enough times that the good habits stop feeling like extra work. Start with the two habits that pay off immediately — smaller PRs and comments that ask instead of order — and the rest of the process follows from there.
Metrics to Track
Wire review checks into the pipeline itself — the CI/CD pipeline guide covers gating merges on automated checks.
| Metric | Target | Why |
|---|---|---|
| PR size | <400 lines | Review quality drops sharply above this |
| Review turnaround | <24 hours | Prevents context loss and blocked work |
| Defect escape rate | Decreasing | Bugs found in production vs. review |
| Review participation | >80% of team | Knowledge sharing |
Common Mistakes
- Bike-shedding: Spending review time on trivial style issues while missing real bugs
- Rubber-stamping: Approving without reading because “they never make mistakes”
- Gatekeeping: Using review power to enforce personal preferences
- Delayed feedback: Waiting days to review, forcing the author to re-learn context
- No follow-up: Suggesting changes but never checking if they were made
Troubleshooting
- Reviews stall for days. The norm is missing or not enforced — agree on “first pass within one business day” and, if the repo supports it, add a reminder automation or a review rotation so nobody becomes the single point of latency.
- PRs come back as “LGTM” with no real feedback. Usually a size problem: a giant diff gets skimmed because there’s no time to do otherwise. Enforce smaller PRs at the culture level — nobody reviews 2.000 lines well — and lead by splitting your own work first.
- Reviews turn into arguments in the comments. Tone is the tell: comments that read as orders or judgments start fights. Move style debates to a shared style guide or formatter config, take genuine design disagreements to a call, and keep the PR comments for questions and concrete suggestions.
- The same feedback repeats every PR. That’s a missing shared standard, not a reviewer problem. Turn recurring comments into lint rules, formatter config, or the project checklist — automate the repeatable so reviewers can spend attention on what needs judgment.
- Authors push back on every comment. Sometimes defensiveness, sometimes the comments really are opinions without basis. Require comments to name the problem and offer a suggestion or question — if a comment can’t do that, it probably isn’t feedback worth a fight.
- Nobody knows what “done” means for a review. Define it: approvals required, who can merge, whether comments must be resolved or just answered. A PR template that names the bar removes most of the ambiguity — see the pull request template for a starting point.
Further Reading
- Google Engineering Practices — How to do a code review: the industry reference on reviewer behavior and review speed.
- Best practices for code review — SmartBear: the research behind the ~400-line effectiveness drop.
- GitHub — Reviewing changes in pull requests: the platform mechanics behind the workflow.
- Technical Debt: Track, Prioritize, Pay Down — where review findings become registered debt items with an owner and an interest rate, instead of tribal knowledge.
- Companion resources — printable review checklist by category plus BAD/GOOD comment examples ready to paste into PR templates.
Production Notes
- Deploy gradually using canary or blue-green to catch regressions early.
- Set alerts on error rate, p99 latency and failure rate before the rollout goes live.
- Document the rollback in the runbook; test the procedure in staging at least once per quarter.
- Review structured logs with correlation IDs to trace requests end-to-end during incidents.
Key Takeaways
- Apply what works in code review — for authors and reviewers when you need a practical solution for your use case.
- Monitor performance after implementation; measure latency, errors, and resource usage before and after.
- Check the Troubleshooting section for common failures; most have documented root causes with fixes.
- Keep dependencies updated and run tests in CI to prevent production regressions.
Advanced Topics
Scenario: Code Review Checklist for a Payment Service
Service: Payment processing microservice
Risk: High (financial transactions, PII)
Reviewers: 2 required (1 senior + 1 peer)
Pre-review automated checks:
[x] Linter passes (ESLint + Prettier)
[x] Type checker passes (tsc --noEmit)
[x] Unit tests pass (>90% coverage on changed lines)
[x] SAST scan clean (Semgrep)
[x] No secrets in diff (trufflehog)
[x] Dependency audit clean (npm audit)
Review checklist (reviewer fills):
Security:
[ ] Input validation on all endpoints (Zod schemas)
[ ] No SQL injection (parameterized queries)
[ ] No hardcoded secrets or API keys
[ ] PII not logged (mask card numbers, emails)
[ ] Auth checks present on every route
[ ] Rate limiting on sensitive endpoints
Correctness:
[ ] Transaction boundaries correct (ACID)
[ ] Error handling covers edge cases
[ ] Idempotency for payment operations
[ ] Decimal arithmetic (no floating point for money)
[ ] Null/undefined checks on external data
[ ] Race conditions addressed
Design:
[ ] Single responsibility per function
[ ] No God classes or functions > 50 lines
[ ] Dependencies injected (testable)
[ ] No circular imports
[ ] API contract matches OpenAPI spec
Testing:
[ ] Happy path covered
[ ] Error paths covered
[ ] Boundary values tested (0, negative, max)
[ ] Integration test for DB operations
[ ] Mock external services (Stripe, bank API)
[ ] No flaky tests (timeouts, random data)
Performance:
[ ] N+1 queries eliminated
[ ] No synchronous I/O in hot paths
[ ] Indexes exist for new queries
[ ] Pagination on list endpoints
[ ] No unnecessary data fetched (SELECT * avoided)
Documentation:
[ ] JSDoc on exported functions
[ ] README updated if setup changed
[ ] Changelog entry added
[ ] Breaking changes documented
Review comments format:
[blocking] Must fix before merge
[suggestion] Consider this approach
[question] Why this design choice?
[nit] Minor style preference
Metrics tracked:
| Metric | Target |
|--------|--------|
| Review time | < 4 hours |
| Defect escape rate | < 5% |
| Reviewer load | < 5 PRs/day |
| PR size | < 400 lines changed |
| Comment density | 2-5 per PR |
Lessons:
- Automated checks reduce reviewer burden
- Checklists ensure consistency across reviewers
- Small PRs get better reviews than large ones
- [blocking] vs [suggestion] clarifies intent
- Track metrics to improve the review process
Common Production Pitfalls
- Treating the guide as a checklist to complete once rather than a practice to evolve.
- Adopting every recommendation at once instead of starting with one measured change.
- Skipping the maturity assessment and forcing advanced practices on an unprepared team.
- Not updating runbooks and on-call expectations as new practices are introduced.
- Ignoring real incident data when prioritizing which parts of the guide to apply first.
- Failing to assign an owner who reviews decisions quarterly.
- Copying examples without adapting them to the team’s actual tooling and constraints.
- Forgetting to measure outcomes before adding the next improvement.
Frequently Asked Questions
How do I review code in an unfamiliar language or domain?
Review what's still reviewable — test coverage, naming, error handling, docs, API shape — and say so explicitly. "I checked the interface and the tests; the internals need someone who knows the framework" is an honest, useful review. Ask domain experts for the technical nuances.
What if the author disagrees with my feedback?
Talk it through — most disagreements dissolve once each side explains the reasoning behind theirs. If it stays stuck, whoever maintains the code decides after hearing the objection, and the dissent gets noted in the PR. If it's a blocking issue and you cannot agree, escalate to the team lead. For suggestions, let the author decide and move on.
Should I block a PR for missing tests?
Yes, if the PR adds logic that can be tested. No, if it's a pure refactor with existing coverage, or UI changes that require E2E tests owned by another team.
How do I handle large PRs that are hard to review?
Ask the author to split into smaller PRs. If splitting is not possible, request a walkthrough (screen share or detailed description). Review in chunks: first the design, then the tests, then the implementation. Use diff tools that allow commenting on specific lines. Large PRs (> 400 lines) consistently get lower quality reviews.
Related Resources
Code Review Checklist Template
A structured checklist template for conducting consistent, thorough code reviews that catch bugs, improve readability, and share knowledge across the team.
GuideSoftware Testing Strategy Guide
A practical guide to building a layered testing strategy with unit, integration, contract, and end-to-end tests that your team will actually maintain.
GuideCI/CD Pipeline Guide: From Commit to Production
A practical guide to building CI/CD pipelines with GitHub Actions, testing gates, deployment strategies, and rollback procedures.
DocPull Request Template
A thorough pull request template to standardize code reviews and improve merge quality.
GuideClean Code Principles: Naming, Functions, Classes
A practical guide to clean code principles: meaningful names, small functions, single responsibility, useful comments, error handling, DRY, and formatting.
GuideTechnical Documentation Strategy: Docs as Code
A practical guide to treating documentation as code: versioning, review workflows, structure, and tools that keep docs accurate, discoverable, and maintainable.