Slide 1

Slide 1 text

Pusheando en master, que es gerundio (Trunk-Based Development 101) CSTechHub 9 de julio de 2020 El vídeo de la charla

Slide 2

Slide 2 text

Ego slide Hemos venido a jugar... Desarrollador de software/producto @islomar islomar@gmail.com Teleco, Psicología, Antropología Social y Cultural, Executive MBA…

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

#NoTools #NoCode

Slide 8

Slide 8 text

What is Trunk-Based Development about? Just always push directly to your main (and only) branch Easy-peasy!!

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Agenda ● Continuous X ● Basic branching strategies & Pull/Merge Requests ● “Why” and “what for”: SW development principles ● Trunk-Based Development for the win! ● My personal experience ● When NOT to use it ● How to start with TBD ● Recommended people, books and resources ● Q&A

Slide 11

Slide 11 text

Continuous X ● Continuous Integration ● Continuous Delivery ● Continuous Deployment ● Continuous Release

Slide 12

Slide 12 text

Continuous Integration “Integrate and test changes after no more than a couple of hours.” “The integration step is unpredictable, but can easily take more time than the original programming.” “Continuous integration should be complete enough that the eventual first deployment of the system is no big deal” (“Extreme Programming Explained, Second Edition”, Kent Beck - 2005)

Slide 13

Slide 13 text

Continuous Delivery “Every push” (Isi©) leaves your code continuously ready to be deployed to Production with one single and simple manual step. ● Continuous Integration is a prerequisite ● Probably you will need feature flags (among other techniques) ● Deployments need to be automated

Slide 14

Slide 14 text

Continuous Delivery “Software delivers no revenue until it is in the hands of its users” “How long would it take your organization to deploy a change that involves just one single line of code?” “Branching should, in most circumstances, be avoided” (“Continuous Delivery: Reliable Software Releases through Build, Test, and Deployment Automation”, Jez Humble and David Farley - 2010)

Slide 15

Slide 15 text

Continuous Deployment Every change/push goes through the pipeline and automatically gets put into production. ● Continuous Delivery is a prerequisite ● No human intervention You need: ● Great safety net (different kind of automated tests, statics analysis, monitoring, etc.) ● You will certainly need feature flags (plus other parallel changes techniques) ● Easy way to rollback

Slide 16

Slide 16 text

https://opensenselabs.com/blog/articles/continuous-deployment-drupal

Slide 17

Slide 17 text

Continuous Release DEPLOYMENT != RELEASE ● Released: visible to the users ● Deployed: the code is “put” in the Production systems, maybe not visible. ○ With a feature toggle, or an unknown URL or a hidden HTML element or ● Decouple “deployment” and release!

Slide 18

Slide 18 text

Continuous Release Deploying to Production (without releasing) has value in itself: ● The whole pipeline works fine (e.g. tests, infrastructure, etc.) ● You check that nothing breaks (even not being active). ● You might want to partially activate it (e.g. with feature toggles/flags). ● You learn about the HOW.

Slide 19

Slide 19 text

How often is “continuous enough”? Online browser editor which triggers the deployment pipeline after clicking a specific button… why not? ● E.g. Dark ○ “A holistic programming language, editor and infrastructure for serverless backends” ○ “Deployless means that anything you type is instantly deployed and immediately usable in production.” ○ Native Continuous Delivery, using feature flags ○ https://darklang.com/ ○ https://medium.com/darklang/how-dark-deploys-code-in-50ms-771c6dd60671

Slide 20

Slide 20 text

Source Code Management (SCM) tools 1. No Version Control System (VCs) at all. 2. Floppy disks. 3. CVS (no branches at all) 4. SubVersion a. Creating a branch was highly costly 5. Git a. Feature branching: https://martinfowler.com/bliki/FeatureBranch.html b. GitFlow i. Master, Develop, Feature, Release and Hotfix branches

Slide 21

Slide 21 text

Branching strategies (over-simplified) ● Feature branching ○ One branch per feature (sometimes it means per developer) ● GitFlow ● Other combined strategies ○ Feature + Main + Release branches ○ Release trains

Slide 22

Slide 22 text

GitFlow ● Develop branch ● Feature branches ● Release branches ● Master branch ● Hotfix branches https://nvie.com/posts/a-successful-git-branching-model/

Slide 23

Slide 23 text

https://nvie.com/posts/a-successful-git-branching-model/

Slide 24

Slide 24 text

Why do people do Pull/Merge Requests? ● For feeling safer ○ Peer review: Someone else can take a look to it and detect problems ● For rising the code quality (e.g. design solution) ● For sharing/spreading knowledge ● For getting the control: ○ "Safe" way to accept contributions from other people/teams ○ Final review centralized in a few people (e.g. QA, PM, committee, etc.)

Slide 25

Slide 25 text

Problems with Pull/Merge Requests ● It completely breaks the flow ○ Increased lead time: no Continuous Delivery/Deployment ○ You better wait for that PR to be merged before creating a new one… or fight with Git ● Increased risk ○ It’s too late: someone already worked several hours (days?) on it…. Waste. ○ More probability of things breaking or not fitting… or not being needed anymore.

Slide 26

Slide 26 text

Problems with Pull/Merge Requests (cont.) ● Code reviews: ○ you don’t have the context of the person for every decision made. ○ tenths/hundreds of lines changed... are you kidding? SOURCE OF INEFFICIENCIES AND HUMAN CONFLICTS

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

(IMO) When do pull/merge requests make sense? ● Distributed team with very different time zones ○ Not really possible to do pair programming ● OSS: very async, worldwide distributed people ● Contributions between teams inside a company ○ Though, even better: pair with someone from the other team ● For some exceptional reason, someone worked on their own

Slide 29

Slide 29 text

https://martinfowler.com/articles/branching-patterns.html#continuous-integration This is what it REALLY happens when branching... https://twitter.com/jahnnie/status/937917022247120898

Slide 30

Slide 30 text

But wait… let’s take several steps back...

Slide 31

Slide 31 text

Why and what for do we develop software professionally? ● From an individual/personal level: para ganarnos la vida, para divertirnos, para sentirnos útiles, para evitar el horror vacui vital... ● From a company perspective: to earn money, to “make the world a better place” (Silicon Valley dixit) Para resolver problemas que no resulta igual de óptimo/eficiente resolver sin software

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

● “Early and continuous” ○ How “early”? ○ How “continuous”? (“... from a couple of weeks…”) ● “Working software” + “Valuable software” ○ Does it break? ○ Fits business requirements? ○ Is it used? ○ Does it satisfy the customer/user? ○ Does it generate “profit”?

Slide 34

Slide 34 text

“agile” is about… ● Focus on people ○ Communication ○ Needs and expectations ● Risk management ○ “Short” feedback cycles, in order to improve in either: ■ Business (WHAT): user feedback ■ Technology (HOW): system feedback ○ Learn fast (not “fail fast”)

Slide 35

Slide 35 text

Which branching strategy would “better” fit with reducing the risk management, continuous learning and the continuous delivery of value? (and less people suffering!!)

Slide 36

Slide 36 text

Trunk-Based Development for the win!! https://unsplash.com/photos/abkEAOjnY0s

Slide 37

Slide 37 text

https://twitter.com/CodelyTV/status/1248216553138552834

Slide 38

Slide 38 text

https://svgsilh.com/image/2028004.html Technical excellence Continuous delivery of value to the business https://freesvg.org/unicorn-vector-clipart-pdv “Agile” People first! Make the world a better place!

Slide 39

Slide 39 text

Trunk-Based Development is about... Pushing to master

Slide 40

Slide 40 text

https://unsplash.com/photos/MggK54YixfU

Slide 41

Slide 41 text

Trunk-Based Development is about... Keeping one single branch “by default” and pushing your code there

Slide 42

Slide 42 text

Trunk-Based Development is about… (cont.) + Pair/mob programming + Parallel changes techniques + TDD (or at least “test first”, including baby commits) + A proper product management vision

Slide 43

Slide 43 text

Trunk-Based Development is about… (cont.) A “safe”, easy and automated deployment/release pipeline (CD) + Easy way to rollback + “Loosely-coupled” teams/services + An engineering culture which supports it + etc...

Slide 44

Slide 44 text

“A proper product management vision” ● Product Manager working in the day by day with the rest of the team ● Vertical slicing: ○ Simplified and small end-to-end chunks ○ Business (user stories): GREAT (release) > we learn the WHAT ○ Technical: good (deployment) > we learn the HOW ● Continuous prioritization ● Focus on value (aligned with “higher company goals”) ○ Measure the “value” delivered ● Pull system (keep it flowing!!) ○ Guided by the system/team capacity + JIT (last responsible moment)

Slide 45

Slide 45 text

Some other IMPORTANT practices (not only) for TBD ● Canary releases ○ https://martinfowler.com/bliki/CanaryRelease.html ○ First, deployed only to some representative environment ● Feature toggles (a.k.a “feature flags”) ○ https://martinfowler.com/articles/feature-toggles.html ● Other parallel changes techniques ○ https://martinfowler.com/bliki/ParallelChange.html ○ Branch by abstraction ○ Postel’s law: “Be conservative in what you do, be liberal in what you accept from others” ○ Strangler Application ○ Anti-Corruption Layer

Slide 46

Slide 46 text

What if I can not do ALL of that? ● Keep calm and do not push to master (yet) ● It is sometimes a sign of deeper inefficiencies and improvement opportunities, it just makes them “explicit” (if we have enough self-critic and humility) Congratulations! We have a great opportunity of improvement ahead!

Slide 47

Slide 47 text

If TBD is not about “pushing to master”... what is it about? ● Lean Product Management ○ Risk management ○ “Fast” feedback ● REALLY continuous and sustainable delivery of value ● Technical excellence (e.g. many XP/DevOps principles and practices)

Slide 48

Slide 48 text

We want a feedback cycle “as short as possible” Longer delay between deployments https://www.goodreads.com/book/show/34695798-release-it Higher risk of bugs and downtime More changes in each deployment Review processes A great vicious cycle

Slide 49

Slide 49 text

Another way of saying it... Reduce your lead time: from a customer making a request to the customer being satisfied. Reduce your product delivery lead time: from code committed to code successfully running in production. https://www.goodreads.com/book/show/35747076-accelerate

Slide 50

Slide 50 text

https://cloud.google.com/blog/products/devops-sre/the-2019-accelerate-state-of-devops-elite-performance-productivity-and-scaling

Slide 51

Slide 51 text

https://cloud.google.com/blog/products/devops-sre/the-2019-accelerate-state-of-devops-elite-performance-productivity-and-scaling

Slide 52

Slide 52 text

Code is not an asset, it is liability! ● The best line of code is the one not written. ○ “Fewest elements”: https://martinfowler.com/bliki/BeckDesignRules.html ● Code needs to be maintained. ● Code needs to be tested. ● Code needs to be understood. ● A line of code is one more possible point of failure. ● Software has a COST. https://wiki.c2.com/?SoftwareAsLiability Dan North: Microservices software that fits in your head

Slide 53

Slide 53 text

Code is not an asset, it is liability! “Between the time a developer commits code to the repository and the time it runs in production, code is a pure liability. Undeployed code is unfinished inventory. It has unknown bugs. It may break scaling or cause production downtime. It might be a great implementation of a feature nobody wants.” (“Release it! Second Edition”, Michael T. Nygard - 2018)

Slide 54

Slide 54 text

Does it require to work with monorepo? NOT at all Previous session in this Meetup: Monorepo: uno para gobernarlos a todos

Slide 55

Slide 55 text

My personal experience ● Two full years at Alea Soluciones ○ TDD + pairing + feature toggles + vertical slicing simplification (EVERYDAY) ○ Canary releases ○ Multiple services (multirepo) ○ TBD was the way to work (only a couple of branches for spikes or something like that) ○ Lucky me, I forgot how to use Git beyond commit, pull and push ● Six months at Spotify ○ Context: pure backend. People working with PRs all the time. ○ I started introducing TDD + pairing + baby-commits. No need for feature toggles. ○ That enabled to start experimenting TBD in a a couple of simple services (not too critical).

Slide 56

Slide 56 text

My personal experience ● Currently (last 3 months) ○ TDD + pair/mob + baby-commits + vertical slicing + TBD (EVERYDAY) ○ … but still not released to users (client needs). ○ Hopefully we’ll start with Continuous Delivery

Slide 57

Slide 57 text

When NOT to do TBD? Any time where you don’t follow “all” of the practices mentioned: ● pair/mob programming ● parallel changes techniques ● TDD (or at least “test first”) ● A proper product management vision ○ Simplified end-to-end “user stories” ○ Vertical slicing: small end-to-end chunks ■ Business: GREAT ■ Technical: good ○ Business ability to move in baby steps

Slide 58

Slide 58 text

When NOT to do TBD? ● Spikes ○ After the spike, start from scratch in the main branch ● Most OSS projects (super-async, no pairing, distributed timezones…) ● When someone worked on their own (no pair/mob) ● When the team can not work quite “independently” from other teams ○ 'No Man is an Island' (by John Donne) ● When the team doesn’t feel “comfortable enough” ○ Really hard to achieve if nobody in the team has previous experience.

Slide 59

Slide 59 text

How to start? (I) ● Get help (hire people with experience in this approach) ● Work in pairs (so much as possible; even better: do mob!!) ● Write tests (isolated + sociable, aka “unit and integration”) ● Build a continuous integration server that can monitor the main repository and run the tests automatically for every new commits pushed. ● Limit the work in progress a.k.a. WIP (e.g. half the number of developers)

Slide 60

Slide 60 text

How to start? (II) ● Automate your deployment to Production ● Get a staging/test server where to improve the safety net ○ Acceptance tests ○ End to end tests ○ Load tests, etc. ● Configure a release/deployment pipeline which breaks if the different checks/validations do not pass (Andon a.k.a. “Stop the line”) ● Make your branches ages visible and limit it to 24 hours (e.g. with Panda Pull Reminders)

Slide 61

Slide 61 text

How to start? (III) ● Start with TDD (again: get help) ● Improve your baby steps and baby commits skills ● Improve your vertical slicing and business simplification skills ● Reduce the branches lifetime to 2 hours. ● Reminder: this is not about tools or technologies!! ● Pick up a non-critical service (e.g. a simple API) and start trying Continuous Delivery (push deploy to the staging environment). In the “worst case scenario”, if TBD doesn’t “succeed”, you will have improved in many other things!!!

Slide 62

Slide 62 text

Main key points ● TBD is much more than “pushing to master” ○ Risk management ○ Reduced lead time ■ continuously delivering value to the BUSINESS ■ Fast feedback (users and systems) ● TBD is a great excuse to detect many inefficiencies: ○ why wouldn’t you be able to start working like that? ○ What should be “fixed” or “improved” to achieve it? ○ Everything is “connected”!! (systems thinking)

Slide 63

Slide 63 text

Main key points ● It requires to live together with many other practices and principles (not only technical ones, but also related with product management). ● Keep calm and start in baby steps… but start! ○ Probably your context or most of your activity is not “superexceptional” ○ Though often it requires a HUGE change in your engineering culture… everything is connected!

Slide 64

Slide 64 text

Last reflection: renaming “master”? Whatever your first or second thought is… give it a third ● IETF terminology proposal (from 2018): https://tools.ietf.org/id/draft-knodel-terminology-00.html#rfc.section.1.1 ● Probable naming origin: Bitkeeper and its master/slave ○ https://git-scm.com/book/en/v2/Getting-Started-A-Short-History-of-Git ● Easily rename your default branch from master to main

Slide 65

Slide 65 text

Recommended books

Slide 66

Slide 66 text

Recommended books

Slide 67

Slide 67 text

Resources (I) ● https://martinfowler.com/articles/branching-patterns.html ● https://martinfowler.com/articles/continuousIntegration.html ● https://martinfowler.com/bliki/ContinuousDelivery.html ● https://www.atlassian.com/continuous-delivery/principles/continuous-int egration-vs-delivery-vs-deployment ● https://wiki.c2.com/?SoftwareAsLiability ● Dan North: Microservices software that fits in your head

Slide 68

Slide 68 text

Resources (II) ● Workshops about parallel changes: ○ http://www.eferro.net/2018/03/slides-taller-parallel-changes-we-code.html ○ https://paucls.wordpress.com/2020/02/26/ci-cd-non-breaking-changes-exercise/

Slide 69

Slide 69 text

Please, give me feedback!!! :-) https://islomar.typeform.com/to/rnZ82aVu

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

No content