Standards and code review at scale
A standard is worth what enforces it: decide which rules exist, push every rule a machine can check into a machine, and keep human review fast and aimed at judgement
A 300-engineer organisation enforces a 60-rule style guide through code review. Reviewers disagree about the rules and median time to first review is two days. Which change does most for both consistency and speed?
An engineering standard is the set of rules and guidance that lets code be read, changed and reviewed by people who did not write it. Code review is the main place most organisations apply it. At one team, both are informal and work fine, because everyone learned the same habits from the same three people. At ten teams they drift: different formatters, different ideas of what a reviewer is for, different answers to “is this allowed?” The drift is invisible until someone tries to move between teams, run a change across all of them, or explain to an auditor what review means.
You will not fix this by writing more rules. This chapter is about the decisions underneath the document: what earns a place as a rule, where each rule is enforced, what human reviewers check, how fast they do it, and who may change the standard.
The model: a standard is a set of enforcement decisions
The chapter on style guides in Software Engineering at Google, by Shaindel Schwartz, separates rules from guidance. Rules are mandatory and “universally enforceable”; guidance is advice “good to follow” with “some room for variance”. Keep that split. A standards document that mixes the two teaches readers that nothing in it is mandatory.
The same chapter gives the principles a rule must satisfy: rules must pull their weight, optimise for the reader, be consistent, avoid error-prone and surprising constructs, and concede to practicalities when necessary. The first is the one most organisations break. Every rule has a cost, paid by every engineer who has to learn it and every reviewer who has to check it. Google’s guide deliberately leaves out rules for things engineers already avoid, and the chapter’s reasoning is blunt: if one or two engineers get something wrong, adding to everyone’s mental load does not scale.
The second principle explains what the whole exercise is for. Code is read far more often than it is written, by colleagues, by the engineer who inherits it, and by tools. That last reader matters more than people expect. Hyrum Wright’s chapter on large-scale changes in the same book says such changes “really work only when the bulk of the effort for them can be done by computers”, and that heterogeneity of tooling and formatting makes sweeping changes difficult. Consistency is what lets a tool, rather than a hundred engineers by hand, upgrade a library across every repository.
So the useful way to think about a standard is not as a list of rules but as a set of decisions, one per rule:
- Is this a rule, guidance, or nothing? If a reader would not be harmed by the variation, it is nothing.
- What enforces it? A formatter, a linter, a test, an ownership file, a human reviewer, or a design review.
- What is the exception path? Who can grant one, how it is recorded, and when it expires.
- Who can change it? And how a proposal reaches them.
A rule with no answer to the second question is a wish.
Where each rule is enforced
Think of the enforcement mechanisms as a ladder. The lower the rung, the cheaper and more consistent the enforcement, and the less judgement it can apply.
| Rung | Catches | Cost per change | Fails by |
|---|---|---|---|
| Formatter with no options (gofmt, Prettier, Black) | Layout, whitespace, import order | Zero; runs on save | Configuration debates if you allow options |
| Linter or static analyser with autofix | Banned APIs, unsafe patterns, naming, deprecated calls | Seconds; the author fixes before review | False positives that train people to ignore it |
| CI checks and tests | Behaviour, contracts, dependency rules | Minutes of compute | Flaky tests; checks nobody owns |
| Ownership (CODEOWNERS, OWNERS files) | Changes to code a team is accountable for | A required reviewer | Owners who become a queue |
| Human review | Design, clarity, naming that matters, missing tests, wrong abstraction | Reviewer hours and author wait | Variance, delay, nit wars |
| Design review or RFC | Choices that are expensive to reverse | Days | Arriving after the code is written |
The principle is to push each rule as far down the ladder as it will go. The Google chapter is explicit: “we strongly prefer to automate enforcement with tooling.” It gives three reasons. Automated rules are not forgotten as time passes and new people join. They have one definition instead of one per reviewer. And they scale: if the company doubles, the cost of enforcement stays about the same. It reports that when Google began flagging deprecated functions in review with the fix offered in place, new uses of those APIs “disappeared almost overnight”.
Formatting is the clearest case. Go shipped with gofmt from its first release; the tool has no configuration knobs, and nearly all Go code is formatted identically. Once formatting is automatic it stops being a review topic. If your reviewers still leave comments about brace placement, the standard has failed at the bottom rung, and every one of those comments is a minute taken from something only a human can see.
Two kinds of rule stay with humans. Some need judgement: “avoid complicated template metaprogramming” is a real rule in Google’s C++ guide, and no tool can draw that line. Others are social. Google has no tooling that rejects a change for exceeding a line limit, because a one-line update across hundreds of files can be easy to review and a 20-line change can be hard; reviewers push back on size instead. Write these rules down, say that review enforces them, and keep them few.
The linter rung has a failure mode you must manage. A rule that cries wolf trains engineers to dismiss it, and the real finding goes with the false ones. The secure code review chapter covers the measure for this, the effective false positive, and the triage process; the same discipline applies to your style and correctness rules. In practice:
- Ratchet, do not big-bang. Record existing violations as a baseline, block only new ones, and burn the baseline down as owned work. Hyrum Wright’s chapter notes that organic migrations “are unlikely to fully succeed, in part because engineers tend to use existing code as examples”, which is why a check that stops new uses matters more than the clean-up.
- Suppressions carry a reason. An inline suppression without a comment is a hole; with one, it is a recorded exception you can count.
- Watch the dismissal rate per rule. A rule dismissed more often than it is fixed is costing more than it saves. Tune it or delete it.
This is the same move the security track calls a paved road: make the right way the default, so the standard is met by people who never read it.
What human review is for
Ask a room of engineers what code review is for and most will say finding bugs. The evidence says it does more than that. The code review chapter of Software Engineering at Google lists checking correctness, checking that the code is comprehensible, enforcing consistency, promoting team ownership and enabling knowledge sharing. In the case study by Caitlin Sadowski and colleagues, the engineer who introduced review at Google said its main impetus was to make developers write code that other developers could understand; finding bugs was welcome but not the foremost reason.
That matters for your standard, because it tells reviewers where to spend their attention once tools have taken the mechanical work: is this the right change, is it understandable, is it tested, does it fit the system, and will the next person be able to change it?
Google’s public reviewer guide states the bar in one sentence, and it is the best single line you can put in your own document: reviewers should “favor approving a CL once it is in a state where it definitely improves the overall code health of the system being worked on, even if the CL isn’t perfect.” Two principles sit next to it. On style, the style guide is the absolute authority, and any point not in it is personal preference. On design, choices rest on principles rather than taste, and where the author shows several approaches are equally valid, the reviewer accepts the author’s. Optional comments are prefixed “Nit:” so the author knows they can be ignored.
The guide is equally clear about the opposite failure. When an author promises to clean something up in a later change, it says that unless they do it immediately after, “it never happens”, and that letting people clean up later is a common way for codebases to degenerate. A reviewer who approves imperfect code that improves the system is applying the standard. A reviewer who approves new complexity against a promise is not.
Changes to shared code need one more question. Hyrum’s Law, named by Titus Winters after Hyrum Wright’s observation, states: “With a sufficient number of users of an API, it does not matter what you promise in the contract: all observable behaviors of your system will be depended on by somebody.” A reviewer of a shared library therefore cannot stop at “the documented contract still holds”. Ordering, timing, error text and default values are all part of the interface somebody uses. Your standard should require that changes to code with many callers state which observable behaviours change.
Comments themselves benefit from a convention. Conventional Comments proposes prefixing each review comment with a label (praise, nitpick, suggestion, issue, question) and optional decorations such as blocking or non-blocking. It costs nothing, removes most of the tone problems in written review, and makes it obvious which comments must be resolved before merge.
Speed, size and who reviews
Strict review and slow review are different problems, and most complaints about the first are really about the second. Google’s guide on review speed says so directly: “Most complaints about the code review process are actually resolved by making the process faster.” Its target is that one business day is the maximum time to respond to a review request, and it measures the response, not the time to merge. A reviewer who cannot do the full review can still reply with a time or a better reviewer.
Speed depends on size. The Google book suggests small changes “should generally be limited to about 200 lines of code”; the public author’s guide calls 100 lines usually reasonable and 1,000 usually too large, and says reviewers may reject a change for size alone. For a sense of what small changes and good tooling make possible: the Sadowski case study, analysing nine million reviewed changes at Google, found a median change of 24 lines, a median of one reviewer, and a median latency under four hours for the whole review process. Treat those as a description of one mature system, not a target your organisation should hit next quarter.
The number of reviewers is where teams most often over-spend. The Google book reports that “the most important LGTM is the first one” and that the cost of additional reviewers quickly outweighs their value. Google separates three kinds of approval: an LGTM from a peer for correctness and comprehension, approval from an owner of the directory, and approval from someone with readability in the language, a certification that the code follows that language’s practices. Most reviews have one person holding all three. The separation is what lets one review do all the work most of the time while still guaranteeing an owner and a language expert saw each change.
You probably cannot run a readability programme; it needs trained reviewers in every language and a pool large enough to avoid a queue. You can borrow its parts. Ownership becomes a CODEOWNERS file, which on GitHub automatically requests the owners’ review and, with branch protection, can require it; GitHub’s documentation also tells you to give the CODEOWNERS file itself an owner. Readability becomes a small named group per language who review the changes that set precedent: a new service template, a new shared library, the first use of a framework.
Changing the standard and the code that predates it
A standard nobody can change fossilises; one anybody can change is not a standard. Google gives each style guide owners it calls style arbiters, long-time language experts who decide changes as engineering trade-offs against the guide’s stated goals rather than personal preference. Exceptions go to the same group and are not granted lightly. The chapter’s case study of Python method names shows the process working. Google’s Python guide had required CamelCase to match its C++ code; once most Python at Google was written by Python engineers mixing in third-party libraries, the arbiters weighed the costs and benefits and changed the rule to permit snake_case, as a file-wide choice, with an exemption for existing code.
At your scale the arbiters are three to five engineers per language, you among them, and the proposal is a short RFC (writing RFCs and design docs covers the document). Version the standard, keep a changelog, and date every rule’s introduction so a reviewer can tell old code from non-compliant code.
Every new rule creates a migration: the existing code that does not meet it. Decide in the same document who pays. The large-scale changes chapter argues that the team that owns the system and wants the old one gone should run the migration centrally, because an unfunded mandate pushes the cost onto every other team, and that mechanical changes are cheaper with one expert approver than with every local owner. It also notes that some code is a “haunted graveyard” nobody dares touch, and that the counter is tests. If a rule cannot be applied to a module because nobody trusts its tests, that is a finding in its own right. Running the migration itself belongs to cross-team projects and migrations; your standard needs to say whose job it is and how the baseline is tracked.
Where practitioners disagree
Strict or permissive review. One camp holds every change to a high bar; the other trusts authors and reviews lightly. Google’s guide sides with strictness made tolerable by speed, and says complaints about a new strict regime can take months to fade. Teams shipping prototypes reasonably choose lighter review. Decide per codebase, not per company.
Global or local consistency. Google’s chapter describes a hierarchy: the norms of the file come first, then the team’s, then the project’s, then the whole codebase’s. It also records that the C++ arbiters gave up on the whole codebase ever being fully consistent. Insisting on rewriting old code to the new rule before anyone touches it is usually the wrong trade.
Lint as a gate or as a comment. Blocking makes the rule real; commenting lets you learn the rule’s false-positive rate first. A common compromise is a comment for a few weeks, then a block once the dismissal rate is low.
One reviewer or two. Some teams require two approvals as a quality measure, often because a compliance control is read that way. The Google evidence suggests the second adds little. Before adding one, read what your control actually asks for: often it is evidence that someone other than the author reviewed each change, which one approval and a branch rule already provide. Your compliance team, not you, owns that reading.
Day to day
Owning standards is a small, steady slice of a staff engineer’s week, a few hours as a rule of thumb, with spikes when a rule changes.
Every day, you review. Not everything: the changes that set precedent, the shared libraries you own, and anything where the author asked for you. You answer within a working day, label your comments, and approve when the change improves the system. Your reviews are where the standard is visibly applied, so they are read more widely than you think.
Every week, you read a handful of merged changes from teams you do not work with, not to re-review them but to see where the standard is failing: a rule everybody suppresses, a comment pattern that should be a lint rule, a team that has stopped asking for owners. You hold thirty minutes of office hours for questions and proposals.
Every month, the standards group meets for forty-five minutes with a small dashboard: median time to first review response, the distribution of change sizes, suppression counts per rule, dismissal rates, and the size of each baseline. Proposals arrive as RFCs and are decided there or sent back. Decisions go into the changelog the same day.
Every quarter, you prune. Each rule is checked against “does it pull its weight?” and against its own enforcement record. Rules nobody breaks may not need to be rules; rules everybody suppresses need fixing. You report one paragraph to the engineering leadership meeting: what changed, what it cost, what the numbers did.
After an incident whose cause was a pattern, you are asked whether it should become a rule. Ask first whether a tool can stop it, then whether a test can, and only then whether reviewers should look for it. The postmortem mechanics are in the incidents and postmortems chapter; the rule you write is one of its action items.
There is one codebase, one language or two, and the standard is whatever the founding engineers do. Do not write a rules document. Adopt an off-the-shelf formatter and linter configuration with as few options as possible, wire them into CI on day one, and write a half-page note on what review is for and how fast it should be. The temptation is to let everyone push to main without review because the team is small. Review is how the second engineer learns the first one’s code; keep it, keep it fast, and keep changes small.
This is when drift happens. New teams copy configurations from whichever repository they started from, two lint setups appear, and review norms differ by manager. Your job is to converge before divergence becomes expensive: one shared configuration package per language, a CODEOWNERS file in every repository, a written review standard with a response target, and a standards group of three to five engineers. The first custom lint rules arrive here, usually after an incident. Expect pushback from teams whose code is different; sometimes they are right, and the standard says where it does not apply.
The standards exist, sometimes several of them, inherited from acquisitions and reorganisations. The problem is politics and scale: per-language arbiters with real authority, a waiver process that does not become a queue, compliance teams who need evidence of review, and rule changes that create migrations across hundreds of repositories. Your leverage is tooling owned by a platform team and the large-scale change process: a rule nobody can apply automatically will not be applied at all. Architecture-level governance, which sits above code standards, is covered in the head of engineering chapter.
Template
# Engineering standards: <scope, e.g. backend services>
Owner(s) · Version · Last reviewed · Applies to: <repos, languages>
Arbiters per language: <names>
## Purpose
<Two or three sentences: what this standard optimises for (readers, tools, safety) and what it is not for.>
## Rules (mandatory)
| ID | Rule | Why | Enforced by | Since | Exceptions |
|---|---|---|---|---|---|
| R1 | <checkable rule> | <one line> | formatter / linter <rule name> / CI / CODEOWNERS / review | <version> | <who grants, how recorded> |
## Guidance (recommended)
- <recommendation> (why; where the variance is acceptable)
## Code review
- Approval bar: <e.g. approve when the change improves code health, even if imperfect>
- Approvals required: <number; owner approval rules>
- Response target: <e.g. first response within one working day>
- Size: <guidance and who may reject for size>
- Comment labels: <convention; which labels block merge>
- Shared code: <what the author states about changes to observable behaviour>
## Exceptions and waivers
- Inline suppressions: <format; reason required>
- Waivers for a whole module: <who grants; record; expiry>
## Existing code
| Rule | Baseline count | Owner | Plan | Target date |
|---|---|---|---|---|
## Changing this standard
- Proposals: <RFC location>; decided by: <arbiters>; cadence: <meeting>
- Changelog: <link>
## Measures
| Measure | Current | Target | Source |
|---|---|---|---|
## Not covered here
- <topics owned elsewhere, with links: security review, test strategy, architecture review> WORKED EXAMPLE
Allspice is a fictional company that sells telecom billing and charging software: 2,000 people, 350 engineers in 44 teams across four product groups (rating and charging, invoicing, mediation, the self-care portal). Most code is Java, with Go in mediation and TypeScript in the portal, spread over 120 repositories. Yetunde, a principal engineer, wrote this standard with Akosua, the staff engineer who acts as Java arbiter, and Otieno, director of rating and charging, as sponsor.
Purpose. Code any Allspice engineer can read, and that tools can change across all 120 repositories. Security review and test strategy are covered by their own standards and linked.
Rules (Java, extract). R1: code is formatted by the shared formatter configuration; enforced by a CI check that fails on any diff; no exceptions. This replaces three configurations in use today. R2: monetary amounts use the Money type in integer minor units, never double or float; enforced by a custom lint rule on the rating, charging and invoicing packages; suppressions need a reason and an arbiter’s name. Why: two legacy rating modules stored amounts as double, and rounding differences reached customer invoices. R3: no new calls to the deprecated tariff API; lint rule with autofix to the replacement.
Code review. One approval from someone other than the author, plus owner approval through CODEOWNERS. Approve when the change improves the code, even if imperfect; optional points are labelled nitpick. First response within one working day. Changes over 400 changed lines may be returned for splitting. Changes to the shared rating library state any change in ordering, rounding or error codes.
Existing code. R2 baseline: 212 occurrences in two modules, owned by the rating platform team, burned down by the end of Q3. R3 baseline: 1,840 calls, migrated by an automated change with Akosua as the single approver.
Measures (last 90 days, from the Git host’s API). Median time to first review response: 31 hours; target under 8. Median change size: 380 lines; target under 200. Review comments about formatting, from a sample of 200: 24, or 12%; target near zero once R1 is live.
Now you
You are the staff engineer at Cumin, a 110-person mortgage origination platform with 40 engineers in seven teams: six product teams and one platform team. Origination services and the broker portal are TypeScript; credit decisioning is Python. Three TypeScript teams use different ESLint configurations and one uses none. In a sample of 300 pull requests from last quarter, the median wait for a first review was two days; one team requires two approvals, the rest one. Last month fee totals on borrower disclosure documents were summed as floating-point numbers and 312 loans went out a cent wrong. Greta, the CTO, has asked for an engineering standards document before the company grows to 60 engineers next year. Two complications: Adwoa, who leads the decisioning team, says Python model code is different and wants it out of scope; and a partner bank’s audit asks for evidence that every change was reviewed by someone other than its author. Write the standard: the rules, how each is enforced, the review section, the baseline for existing code, and how it changes.
Self-check
You are the staff engineer at Cumin, a 40-engineer mortgage origination platform. After borrower disclosures on 312 loans went out a cent wrong, you propose a rule: monetary amounts in the TypeScript money-handling packages use the shared decimal Money type, never the number type. A quick search finds 140 existing violations. Adwoa, who leads credit decisioning, objects that a lint rule will be noisy because the Python risk models use floats legitimately, and suggests adding the rule to the review checklist instead. Bongani, whose closing team owns most of the violations, has a release in three weeks. How do you enforce the rule?
- BOOK Software Engineering at Google, chapter 9: Code Review Tom Manshreck and Caitlin Sadowski, in Winters, Manshreck and Wright (eds.), 2020
What review is for beyond finding bugs, why one reviewer is usually enough, and how ownership and readability split the approval. The source for most of this chapter's review model. Read: Chapter 9, free online; read the sections on the three approvals, code consistency and best practices.
- BOOK Software Engineering at Google, chapter 8: Style Guides and Rules Shaindel Schwartz, 2020
Rules versus guidance, why rules must pull their weight, style arbiters and waivers, and the case for automated enforcement with gofmt as the example. Read: Chapter 8, free online; read the guiding principles and the section on enforcing the rules.
- BOOK Software Engineering at Google, chapter 22: Large-Scale Changes Hyrum Wright, 2020
What a new rule costs the code that predates it, who should pay, and how tooling prevents backsliding once a migration is done. Read: Chapter 22, free online; read the sections on heterogeneity, the LSC process and cleanup.
- DOC Google Engineering Practices: code review Google
The public reviewer and author guides. Read The Standard of Code Review, Speed of Code Reviews and Small CLs; they are short enough to adopt wholesale and cite in your own standard.
- POST Hyrum's Law Hyrum Wright
The one-paragraph observation that every observable behaviour of a widely used interface is depended on. Read it before you write the review rule for shared libraries.
- PAPER Modern Code Review: A Case Study at Google Caitlin Sadowski, Emma Söderberg, Luke Church, Michal Sipko, Alberto Bacchelli, 2018
Measured data from nine million reviews on why review exists, how small changes are and how fast review can be. Useful when someone claims review is only about defects. Read: ICSE SEIP 2018; read section 4 on motivations and the review size and speed results.
- DOC Conventional Comments
A labelling convention for review comments: praise, nitpick, suggestion, issue, with blocking and non-blocking decorations. Cheap to adopt and removes most of the tone problems in written review.
- DOC About code owners GitHub
How CODEOWNERS files request and require review, the precedence rules, and why the file itself needs an owner. The practical form of Google's owner approval.
All companies and people in these examples are fictional. Any resemblance to a real business or person is unintended.