Code review, giving and receiving
Review a change by asking what happens if it ships, rank every comment by that answer, say it so the author can act on it, and take your own reviews the same way
You are two months in. A staff engineer's change retries a write that is not idempotent, and you are fairly sure it will create duplicates. Which approach matches how good teams run review?
Code review is the one practice every engineer does from the first week and almost nobody is taught. You learn it by being on the receiving end, which teaches you what hurts and little about what helps. This chapter covers both sides, because they are the same skill: working out what a change will do, and saying so in a way that moves the work forward. The scope is one engineer reviewing one change and one engineer receiving a review. How a company sets review rules, ownership files and automated checks is the subject of Standards and code review at scale in the staff track. How to read a diff for security holes is in Secure code review and AppSec.
The model: a review answers one question
The question is: what happens if this ships? Everything else is a way of answering it.
Google’s published engineering practices state the standard plainly. The aim of review is to keep the overall health of the codebase improving over time, and a reviewer should approve a change once it clearly improves that health, even if it is not perfect. Two things follow. A review is not a search for every flaw you could name; a reviewer who holds a good change for a week over taste has made the codebase worse by delaying it. And a review is not a rubber stamp; if the change makes the system worse in a way that matters, approval is a false statement.
Review does three jobs, and teams that expect only one of them are disappointed by it.
- It catches defects before customers do. This is the job people name, and it is the least reliable one. Reviewers miss bugs, and the chapter on code review in Software Engineering at Google treats catching defects as one benefit among several, not the only one.
- It spreads knowledge. Someone other than the author now knows the change exists, how it works and why. When the author is on leave, that second person can fix it. This is the main reason review is worth its cost in a team of any size.
- It keeps the code consistent and readable. A change that the reviewer cannot follow will not be followed by the engineer who opens the file in two years. The reviewer is a test reader, standing in for that person.
Notice that none of the three says “approve or reject”. You are a reader with a duty to report what you understood and what you could not.
The model has a corollary for your own work, which you met in Engineering philosophies: a small change is a reviewable change. A reviewer can hold perhaps a few hundred lines in their head. Past that, they skim, and a skimmed review finds nothing. If you want a real review, the pull request you open has to be one a person can read.
Reading a change: the order matters
Most people read a diff top to bottom, file by file, in the order the tool shows it. That is the order the author’s editor produced, and it hides the design. Read in this order instead.
1. The description and the linked ticket. What is the change meant to do, and why now? If you cannot tell, that is your first comment, and you can stop reading until you can. A change you cannot place against a purpose cannot be judged against it.
2. The tests. Read them before the code. They are the author’s claim about behaviour. Which cases do they cover, and which are missing: the empty input, the failure of a dependency, the second call, the value at the boundary? A test that only runs the success path says the author did not think about the other paths, or did and did not say so.
3. The shape of the change. Which files and functions changed, and which did not? A change to a shared library with no change to its callers deserves a question: who else uses this? Google’s guidance puts design first among what to look for, and says it is the most important thing a reviewer can examine, because lines can be fixed in a minute and a wrong design takes a rewrite.
4. The lines. Only now read line by line, for correctness, naming, error handling and clarity.
At each step, run the question again for the paths that rarely run. A diff shows you what the author wrote on the day it worked. The bugs live in what happens when it does not. Use this list.
| Look at | Ask | Where it goes wrong |
|---|---|---|
| Calls over a network | What if it times out, fails, or answers twice? | Retries of writes that are not idempotent: see Idempotency and exactly-once |
| Retries | How many, how long between, what stops them? | No backoff or jitter, so the retries arrive together: see Retries, backoff and jitter |
| Money and counts | What type, what rounding, what unit? | A figure a kobo out, quietly |
| Input from outside | Who controls it, and is it checked? | Injection, or an unbounded size |
| State shared between requests | Who else writes this, and in what order do events arrive? | Out-of-order updates overwrite newer data |
| Logs | What is written, and about whom? | Personal data in a log line that thirty people can read |
| Tests | Do they fail if the code is wrong? | A test that passes with the fix removed |
| Flags and config | What is the default, who can change it, how is it switched off? | A flag on by default with no owner |
The table is a prompt, not a ritual. A change to a button label needs none of it, and a change to a connector may need all of it.
One more habit helps a great deal: say what you did not check. “I read the retry logic and the tests; I did not check the ERP client’s timeout settings” tells the author and the next reviewer where the gap is. An approval with no stated limits claims more than you did.
Ranking comments by consequence
A review with fifteen comments of equal weight is a review the author cannot use. They will fix the easy ones, argue the hard one or two, and miss that one was serious. Rank every comment, and say the rank in the comment.
| Rank | Test | Example | What the author does |
|---|---|---|---|
| Blocker | If it ships and I am right, data is wrong, money moves twice, something is unsafe or the service can go down | A retry of a non-idempotent write | Must change, or show me why I am wrong, before merging |
| Should fix | It works, but the next change will be harder or a rare case will bite | Out-of-order updates are not handled; the test misses an empty input | Fix now, or open a ticket and say so in the thread |
| Question | I do not understand, and the answer decides whether I have a comment | “Why 5 seconds for the timeout?” | Answer, and change the code or the comments if the answer was not obvious |
| Nit | A matter of taste or small tidiness | A variable called st |
Take it or leave it; never blocks |
| Praise | Something done well that you would like repeated | A test built from a real callback payload | Nothing; it tells them what to keep |
Three rules keep the ranking honest.
Blockers are rare, and each one is a claim. A claim is a statement about consequence that you can defend: “if the ERP applies the write and then times out, this creates a second purchase order”. If you cannot state the consequence, you do not have a blocker; you have a question. If you have more than two or three blockers on a change, say so in the summary and ask for a conversation. The change may need a different design, and comments are a slow way to deliver that news.
Mark nits as nits. An unlabelled preference reads as a demand. The author guesses, complies with all of them and resents the review. The same comment marked as a nit costs them five seconds and costs you nothing.
Say what is good. A review that lists only faults teaches the author that review is a hazard, and they will make changes harder to read to avoid it. Praise has a practical function: it marks the pattern you want to see again. It must be true and specific. “Nice test” is a pat on the head; “this test uses a captured payload, so it will fail if the carrier changes its format” is information.
Some teams standardise the labels. The Conventional Comments scheme, linked in the reading, gives a short vocabulary (praise, nitpick, suggestion, issue, question and others) and lets you add a note such as non-blocking. You do not need the scheme to get the benefit. A word at the start of each comment saying what kind it is does most of the work.
Writing the comment
A comment has four parts: where, what you see, what it costs, and what would unblock it. Most poor comments leave out the second half.
Compare two comments on the same line.
This is wrong. Don’t retry here.
create_purchase_order, line 48: this retries the write after a timeout. The README says the ERP’s create call takes no idempotency key, so if the ERP applied the first attempt and was slow to answer, the retry creates a second order. Blocking until this is handled. Two ways out: send a reference we generate and check for it before retrying, or retry only reads and queue failed writes for the forward deployed engineers to inspect. Happy to talk through it if neither fits.
The second is longer and quicker to resolve. It points to the line, says what you saw, names the consequence, gives the way out and offers a conversation. It also states a fact the author can check (the README) instead of an opinion they can dispute.
Four habits make comments land.
Comment on the code, not the person. “This retries a write” is about the code. “You forgot idempotency” is about the author, and invites defence. Google’s guidance on pushback notes that upset in review comes from how comments are worded more than from the standard being applied.
Ask when you do not know; state when you do. A question you already know the answer to (“have you considered idempotency?”) is a hint dressed as a question, and people see through it. If you are sure, say so and give the evidence. If you are not, ask a real question.
Give a way forward. Even a rough one. “This is wrong” leaves the author guessing. “This is wrong, and here are two options” lets them start.
Do not review in the dark. If you cannot judge part of the change, because it is in a system you have not read, say it and ask for a second reviewer on that part. That is part of the job, not a failure of it.
Reviewing up and across
You will review changes from people more senior than you, and the advice for the early months is easier to give than to follow: do it the same way. Senior engineers write code that goes wrong in the same ways everyone’s does, and they have more power to cause damage because their changes reach further. A new engineer sometimes reads the code more carefully than the author’s peers, because they do not yet assume it is right. That is an advantage to use.
What changes is tone and framing, not substance. State your finding as a finding, give the evidence, and offer to be corrected: “I may be missing context about how the ERP behaves on a timeout; from the README it looks like this creates duplicates.” That wording makes the author’s reply easy (“you are right” or “here is the part you missed”) without softening the point. Avoid wording that is a request for permission to have an opinion.
When to message privately first. Most findings belong on the change, in writing, where the next reviewer and the author’s team can read them. Go private when the issue is about a person and not the code, when something sensitive needs removing before it is visible (a credential committed by mistake), or when you have already left two comments and the thread is turning into an argument. Even then, summarise the outcome on the change afterwards so the record is complete.
When to ask your lead. Ask Nandini, or whoever leads your team, in three cases: the change touches something you cannot assess, you and the author disagree after a real exchange and a call, or the change is large and you cannot give it a proper review in the time available. Asking is not a way to avoid saying what you found. Say it first, then ask for another pair of eyes.
Receiving a review
You will spend as much time on this side. Read every comment as an attempt to help the codebase, not as a verdict on you. That is easier to say than to feel, so use a method.
- Read all the comments before replying to any. The third may change your answer to the first.
- Ask whether the reviewer is right. Google’s guidance tells reviewers to do this when an author pushes back, so do it for them first. If you cannot tell, or a comment is unclear, ask for clarification before you defend the change, and do not reply in anger.
- Reply to every comment. “Done”, “Fixed in the next commit”, “I disagree because…”, “Ticket opened: LINK”. Silence leaves the reviewer unsure whether you saw it.
- Do not resolve other people’s threads. Let the reviewer close what they raised. It tells them you did the thing.
- Disagree with evidence. “This is how it works in the ERP, see this log” ends an argument; “I prefer mine” starts one.
- After two rounds without agreement, talk. Comments are poor at carrying disagreement. A ten-minute call, followed by a note on the change recording what was decided, resolves what ten comments will not. If you still disagree, bring in the tech lead or the owner of the code; most teams have a rule for who decides.
- Thank people for the ones that hurt. The comment that stings and is right is the most valuable one you will get.
Keep a short list of the comments you receive more than twice. They are your habits, and the cheapest way to improve is to fix one at source so the comment is never needed.
Speed and size
Review that waits is review that costs. A change that sits for three days blocks the author, grows stale against the main branch, and teaches people to open large changes so they wait less often. Google’s guidance says the speed of each response matters more than the time the change takes to merge. A common team norm is a first response within one working day. Treat that as a rule of thumb and agree your own.
Your side of the bargain is the size of the change. Keep it small enough to read in one sitting, say in the description what is and is not covered, and split unrelated work. How to do this is the subject of the next chapter, Pull requests that get merged. For now, remember that the review you get is capped by the review the change allows.
Where practitioners disagree
Block on style, or not. Some teams treat any style departure as blocking. Others say anything a formatter or linter can enforce should never be a human comment. The second is cheaper and kinder; a human’s attention is for what machines cannot see. If your team has no formatter, adding one is the best review improvement available.
Approve with comments, or hold. Many teams allow “approve, with these small fixes” when the comments are nits and should-fix items and the author is trusted to address them. Others require a second look. The risk of the first is a nit that is really a defect; the risk of the second is delay. Pick a rule and say it in the team’s norms.
Review by comment, or by pairing. A hard change often reviews better as a call with the screen shared than as a thread. Pairing is quicker and finds more design faults, and it leaves no record, so write a summary on the change afterwards.
Does review catch bugs? Practitioners differ on how many it catches. Whatever the answer, a review is worth its cost for the knowledge it spreads and the readability it enforces. Do not rely on it as your only test; the chapter Testing your own work, later in this track, covers what you owe before anyone reviews.
Day to day
Review queue, once or twice a day. Check requests addressed to you, and read the oldest first. A morning slot and an afternoon slot beat constant interruption; see what an engineer is paid for for why your time is the scarce thing.
Fifteen to thirty minutes per change under a few hundred lines. If it will take more, say so in the thread and give a time.
One real review of a design-heavy change each week. Read the description, the tests and the shape, and write a summary comment stating the verdict and what you did not check.
Reply to your own review comments the same day. Reviewers remember context for a day.
Fifteen minutes a week on a pattern list. Note a comment you have received or given twice. Fix one at source.
Team norms review, once a quarter. Reread what the team agreed about response time, size, nits and blocking. Change one thing.
Pairing slots, as needed. When a thread passes four exchanges, offer a call.
There may be two engineers and no rule about review, so reviews happen when someone remembers. The bar is lower and the risk is higher, because the other person is often the only one who knows the code. Agree one habit: nothing reaches production unreviewed except an emergency fix, and an emergency fix is reviewed the next morning. Review for knowledge-sharing first and defects second, and keep each change small enough that a tired person can read it at the end of the day.
Review is a rule, a tool and a few conventions that differ by team. People review across team lines for the first time, and a change to a shared library may have eight consumers who have never met its author. Write down who must review what (an ownership file helps), how fast the first response should be, and what blocks a merge. Mentoring happens in review comments, so a vague or harsh style spreads. Check your own comments against the four parts.
Review is automated in part: required reviewers, code owners, formatters, scanners and change records. Your task as a human is the part machines cannot do: design, failure paths and whether the change fits what the company intends. Expect many reviewers on shared code, some you have never met, and a formal path for disagreement. A connector or platform change may reach every customer, so a blocking comment from any reviewer is taken seriously. Write comments that a stranger can act on without a meeting.
Template
# Review of <change title>
Reviewer · Author · Date · Verdict: <approve / approve with changes / changes needed>
**What the change does, in one line:**
**Comments, ranked**
| # | Where | Rank | What I see | What happens if it ships | What would unblock it |
|---|---|---|---|---|---|
**Praise:** <one specific thing, and why it is worth repeating>
**What I did not check:**
**Summary for the author (three lines):** WORKED EXAMPLE
Change under review (Wrenpost, Delivery Reports team, eight engineers). A colleague’s 60-line change, “Store delivery status from carrier callbacks”. It adds a handler that receives a carrier’s callback and writes a status to the message record. At peak, the handler receives about 1,200 callbacks a minute (illustrative). It maps the carrier’s code 03 to delivered, uses a 5-second timeout to the database, names a variable st, and has one test built from a captured carrier payload.
Review of “Store delivery status from carrier callbacks”. Verdict: changes needed. The change stores callback statuses.
| # | Where | Rank | What I see | What happens if it ships | What would unblock it |
|---|---|---|---|---|---|
| 1 | map_status, code 03 |
Blocker | The carrier’s docs say 03 means accepted by the carrier’s network, not delivered to the phone | Customer delivery reports show delivered for messages that may still fail, so every customer’s delivered rate is overstated |
Map 03 to sent; add a test with a 03 payload |
| 2 | handle_callback, the write |
Should fix | The status is overwritten whatever order callbacks arrive in | A late sent can replace delivered, so a message flips back |
Compare the carrier’s timestamp, or only move status forward; add an out-of-order test |
| 3 | database timeout | Question | Why 5 seconds? | If the answer is a guess, slow writes pile up at peak | Say where the figure comes from, or link the setting |
| 4 | variable st |
Nit | Unclear name | A reader pauses | Rename status if you like |
Praise: the test uses a captured carrier payload, so it fails if the carrier changes its format.
What I did not check: the database schema change, which the platform team reviews.
Now you
You are two months into Larkhollow, the 300-person AI agent and data platform with 120 engineers, and you are added as a reviewer on a change from Nwabueze, a staff engineer. The 140-line change, titled “Retry ERP writes on timeout”, is to the ERP connector, which every customer deployment uses, and is due to release on Thursday. It makes create_purchase_order and update_order_status retry up to three times on timeout or a 5xx response, waiting 2, 4 and 8 seconds. The core of the diff is below. It adds one test where a fake ERP times out once and then succeeds. The description says some customers’ ERPs time out about 1 call in 50 at month-end (illustrative). One agent cycle writes up to 500 orders. The connector’s README says the ERP’s create call takes no idempotency key. Your lead is Nandini. Produce your review.
-def _post(path, body):
- return erp.post(path, body, timeout=10)
+def post_with_retry(path, body, waits=(2, 4, 8)):
+ for wait in (*waits, None):
+ try:
+ return erp.post(path, body, timeout=10)
+ except (Timeout, ServerError) as err:
+ print("ERP error, retrying", err)
+ if wait is None:
+ raise
+ time.sleep(wait)
def create_purchase_order(order):
- return _post("/purchase-orders", order)
+ return post_with_retry("/purchase-orders", order)Self-check
You are two months into Larkhollow. Nwabueze, a staff engineer, has changed the ERP connector, which every customer deployment uses, to retry `create_purchase_order` up to three times on timeout. The connector's README says the ERP's create call has no idempotency key, and one cycle writes up to 500 orders. Nwabueze has asked you and Nandini, your tech lead, to review, and wants to release on Thursday. You think a timeout after the ERP has applied the write will create a second purchase order. What do you do?
- DOC The Standard of Code Review Google Engineering Practices
The test for when to approve: a change that improves the health of the code gets approved even if it is not perfect. Read it before your next review to calibrate what is worth blocking.
- DOC How to write code review comments Google Engineering Practices
On being courteous, explaining why, and pointing at the problem without judging the person. It is the shortest guide to the writing half of this chapter.
- DOC Handling pushback in code reviews Google Engineering Practices
What to do when the author disagrees: why tone matters, why speed makes complaints fade, and how to keep the standard without a fight.
- DOC How to handle reviewer comments Google Engineering Practices
The author's side: do not take comments personally, think collaboratively when you disagree, and fix unclear code before you explain it in a thread. Read it before your next review lands.
- DOC Conventional Comments
A small vocabulary of labels for review comments, with a way to mark whether one blocks. Use it whole or borrow the idea of a word at the start.
- BOOK Software Engineering at Google, chapter 9: Code Review Winters, Manshreck and Wright (eds.), 2020
Why a large company requires review of almost every change, and what it gives besides finding bugs. Read it for the case that review is mainly about shared knowledge and readability. Read: O'Reilly, 2020; chapter 9, free online.
All companies and people in these examples are fictional. Any resemblance to a real business or person is unintended.