Code Review
Reviewing and being reviewed well — goals of code review, what to look for (correctness, design, tests, security, readability), small pull requests, writing good PR descriptions, giving kind and actionable feedback, comment prefixes, responding to reviews, automation, and review culture.
Code review is the practice of having teammates read changes before they merge. Done well, it catches defects, spreads knowledge, keeps the codebase consistent, and makes everyone better. Done badly, it's a slow, demoralising bottleneck.
Why review code?
| Goal | Notes |
|---|---|
| Find defects | Especially logic errors, edge cases, security issues and design problems tests didn't cover |
| Share knowledge | More than one person understands every part of the system (bus factor) |
| Keep the design coherent | Consistent patterns, architecture and naming |
| Mentoring | Both directions — juniors learn from seniors' feedback, seniors learn from fresh eyes |
| Shared ownership | The team, not an individual, owns the code |
Research at Microsoft and Google found that knowledge transfer and code improvement are as important as defect finding — and that review speed strongly affects developer satisfaction.
Small pull requests
The biggest lever for good reviews is small changes. Reviewers find more issues per line in small PRs; huge diffs get skimmed ("LGTM" on 2,000 lines).
- Aim for changes reviewable in under ~30 minutes — often under 200–400 lines.
- One logical change per PR. Separate refactoring, formatting and dependency bumps from behaviour changes.
- Use stacked PRs or feature flags to ship large features incrementally (CI/CD).
- Split by layer only if each piece is meaningful and safe on its own.
Writing a good PR description
## What
Add retry with exponential backoff to the payment client.
## Why
~0.4% of checkouts fail on transient 503s from the provider (see INC-2381).
Retrying with jitter should recover most of them.
## How
- Wraps `charge()` in a retry helper: 3 attempts, 200 ms base, full jitter.
- Uses the provider's idempotency key so retries can't double-charge.
- Retries only on 5xx and timeouts, never on 4xx.
## Testing
- Unit tests for the retry policy (including the non-retryable path).
- Ran against the provider sandbox with fault injection.
## Risks / rollout
Behind the `payment-retries` flag, enabled for 5% first. Watch the `payment_retry_total` metric.Self-review your own diff first: you'll catch leftover debug code, missing tests and unclear names before anyone else spends time on them. Point reviewers to the important parts and say what kind of feedback you want.
What reviewers look for
In rough priority order:
- Correctness: does it do what it claims? Edge cases (empty, null, large, concurrent), error handling, off-by-one, time zones, resource leaks.
- Design: does it fit the architecture? Is it the right place for this logic? Is it overly complex or prematurely general (Clean code)?
- Tests: are the important behaviours tested? Would the tests fail if the code were wrong (Testing)?
- Security and privacy: input validation, authorization checks on every object, injection, secrets, logging of personal data (Web security).
- Performance and scalability: N+1 queries, unbounded loops or memory, missing indexes, hot paths — when it matters.
- Operability: logging, metrics, feature flags, migrations that are backward-compatible, rollback plan.
- Readability: names, structure, comments explaining why; would a newcomer understand it?
- Documentation: public APIs, READMEs, changelogs, runbooks updated.
What reviewers should not spend time on: formatting and style that tools can enforce — automate that.
Giving feedback
- Review the code, not the person: "This function is hard to follow" rather than "you wrote confusing code".
- Ask questions when unsure: "What happens if
itemsis empty here?" — the author may know something you don't. - Explain why and, where helpful, suggest an alternative (with a code suggestion if your tool supports it).
- Distinguish severity so authors know what's blocking:
| Prefix | Meaning |
|---|---|
| (none) / issue | Must be addressed before merge |
| suggestion | Worth considering; author decides |
| nit | Minor polish; non-blocking |
| question | Seeking understanding |
| praise | Something done well — say it! |
- Approve with comments when remaining items are minor; don't hold a PR hostage over nits.
- Prefer a quick call for big disagreements or design rethinks — long comment threads are slow and can feel hostile.
- If the whole approach is wrong, say so early and kindly, ideally before line-by-line comments. Better yet, discuss designs before code is written (Documentation).
Conventional Comments (suggestion (non-blocking): …) is a popular format for this.
Receiving feedback
- Assume good intent; the goal is better code, not judging you.
- Respond to every comment — fix it, explain, or discuss — and don't silently ignore feedback.
- Don't take nits personally; do push back with reasons when you disagree.
- If several reviewers ask the same question, the code (or a comment) should answer it.
- Thank reviewers; they spent time on your work.
Speed matters
Slow reviews kill flow: authors context-switch, PRs grow stale, merge conflicts pile up. Healthy norms:
- First response within a few working hours, a complete review within a day.
- Reviewers prioritise unblocking others over starting new work.
- Limit required approvers to what's needed (usually one; two for risky areas).
- Use CODEOWNERS to route reviews to people with context.
Automate what machines do better
- Formatters (Prettier, Black, gofmt), linters and type checkers in CI.
- Tests, coverage on changed lines, build and preview deployments.
- Security scanning: dependency audit, secret scanning, SAST (CodeQL, Semgrep).
- Bots for dependency updates and changelogs.
- AI-assisted review can catch common issues and summarise changes — treat it as an extra reviewer, not a replacement for human judgement about design and intent.
Pair and mob programming
Pairing is continuous review: two people at one problem, discussing as they go. It reduces the need for separate review for that code and spreads knowledge fast. Many teams pair on complex or risky work and use asynchronous review for the rest.
- Code review finds defects, spreads knowledge, keeps design coherent and builds shared ownership.
- Small, single-purpose PRs with clear descriptions get better, faster reviews; self-review first.
- Review for correctness, design, tests, security, performance, operability and readability — automate style.
- Give kind, specific, explained feedback; label severity (nit, suggestion, question); praise good work.
- Receive feedback openly; respond to every comment.
- Keep review turnaround fast; use CODEOWNERS, CI checks and automation.