Trunk-Based Development
Trunk-Based Development (TBD) is the branching strategy used by Google, Facebook, and Netflix. It eliminates long-lived branches by keeping all developers committing directly to main — enabled by feature flags and automated testing.
TBD Principles
- All developers commit to main (trunk) at least once per day
- Branches last maximum 1-2 days — no long-lived feature branches
- Feature flags hide incomplete features in production
- Automated tests run on every commit — the safety net
- CI runs in seconds, not minutes — fast feedback is critical
- Result: no merge conflicts, continuous integration actually means 'integrated constantly'
TBD with Feature Flags
// Feature Flag implementation for Trunk-Based Development
// React feature flag hook
const useFeatureFlag = (flagName: string): boolean => {
const flags = {
"new-checkout-flow": process.env.NEXT_PUBLIC_FF_NEW_CHECKOUT === "true",
"ai-recommendations": process.env.NEXT_PUBLIC_FF_AI_RECS === "true",
"beta-dashboard": process.env.NEXT_PUBLIC_FF_BETA_DASH === "true",
};
return flags[flagName as keyof typeof flags] ?? false;
};
// Use the feature flag in your component
function CheckoutPage() {
const newCheckout = useFeatureFlag("new-checkout-flow");
if (newCheckout) {
return <NewCheckoutFlow />; // New implementation
}
return <LegacyCheckoutFlow />; // Old implementation
}
// Environment variables per environment:
// Development: NEXT_PUBLIC_FF_NEW_CHECKOUT=true (visible to devs)
// Staging: NEXT_PUBLIC_FF_NEW_CHECKOUT=true (QA testing)
// Production: NEXT_PUBLIC_FF_NEW_CHECKOUT=false (off until ready)
// Launch day: NEXT_PUBLIC_FF_NEW_CHECKOUT=true (flip the flag)
// This is how Netflix and Facebook ship code before it's ready
console.log("TBD = ship FAST, reveal SAFELY");Quick Quiz
Tip
Tip
Practice TrunkBased Development in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Choose based on team size, release cadence, and deployment model
Practice Task
Note
Practice Task — (1) Write a working example of TrunkBased Development from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Common Mistake
Warning
A common mistake with TrunkBased Development is skipping edge case testing — empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready devops code.
Key Takeaways
- Trunk-Based Development (TBD) is the branching strategy used by Google, Facebook, and Netflix.
- All developers commit to main (trunk) at least once per day
- Branches last maximum 1-2 days — no long-lived feature branches
- Feature flags hide incomplete features in production