awesome-everything RU
↑ Back to the climb

Engineering Practice

Trunk-based: code and config reading

Crux Read real diffs and a CI config, predict the trunk-based behaviour, and pick the highest-leverage fix — flag wrapping, branch by abstraction, and the green gate.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at senior altitude — in orbit
◷ 14 min

Trunk-based discipline shows up in the diff and the CI config, not the manifesto. Read each snippet, predict how it behaves on a shared trunk, and choose the fix a senior engineer would make first.

Goal

Practise reading the artefacts that decide whether a team is actually trunk-based: how unfinished work is wrapped to ship dark, how a big change rides trunk via abstraction, and how the gate is configured to keep trunk green.

Snippet 1 — shipping unfinished work to trunk

// New checkout flow isn't finished, but it must merge to trunk today.
export async function handleCheckout(cart: Cart, user: User) {
  if (flags.isEnabled("checkout-v2", { userId: user.id })) {
    return newCheckout(cart, user);   // half-built, still missing tax calc
  }
  return legacyCheckout(cart, user);  // current production path
}
Quiz

The flag 'checkout-v2' defaults to off in production. With this code merged to trunk daily, what is true?

Snippet 2 — a six-week ORM swap on trunk

interface UserStore {                 // the abstraction
  find(id: string): Promise<User>;
  save(u: User): Promise<void>;
}

class LegacyOrmStore implements UserStore { /* current, in use */ }
class NewOrmStore    implements UserStore { /* built incrementally, dark */ }

// wired once, flipped at the boundary when NewOrmStore is ready
export const userStore: UserStore =
  flags.isEnabled("orm-v2") ? new NewOrmStore() : new LegacyOrmStore();
Quiz

Why is this branch-by-abstraction shape the trunk-based answer to a migration too big to ship in a day?

Snippet 3 — the CI gate config

# .ci/trunk-gate.yml — runs on every PR
on: pull_request
jobs:
  gate:
    steps:
      - run: make unit-tests          # ~2 min, blocks merge
      - run: make lint typecheck      # ~1 min, blocks merge
  e2e:
    steps:
      - run: make e2e-suite           # ~40 min
        if: github.event_name == 'schedule'   # nightly only, never blocks
Quiz

Reading this gate, which statement is the correct senior assessment?

Snippet 4 — a stale flag left behind

// shipped 14 months ago, "search-v2" has been at 100% the entire time
function rankResults(q: Query, results: Result[]) {
  if (flags.isEnabled("search-v2")) {
    return rankV2(q, results);        // the live path
  }
  return rankV1(q, results);          // never runs, never updated since launch
}
Quiz

search-v2 has been at 100% for 14 months. What is the highest-leverage action, and why?

Recap

Trunk-based discipline is legible in the artefacts. A flag conditional on trunk lets unfinished work ship dark so it integrates daily with no drift; an abstraction interface lets a six-week migration ride trunk as small green commits with a single flip-and-delete; a tiered CI gate stays fast by blocking on unit/lint/typecheck and running slow e2e off the critical path; and a release flag still on at a stable 100% is a long-lived branch hiding in an if that you delete — flag and dead path together — as the closing step of the rollout.

Continue the climb ↑Trunk-based: run one full cycle
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.