92
Always ship trunk Managing change in complex websites Paul Hammond

Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Always ship trunkManaging change in complex websites

Paul Hammond

Page 2: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches
Page 3: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Revision Control

Page 4: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

version 1version 2version 3version 4

Page 5: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches
Page 6: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

If youʼre not using any revision control system leave now and start using one

Page 7: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

But...

Page 8: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Coordinating many people working on many things

at the same time is still hard

Page 9: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

“Just use branching”

Page 10: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

...which means merging

Page 11: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

“Branching causes problems in Subversion because Subversion doesnʼt store enough information to make merging work. In Mercurial, merging is painless and easy, and so branching is commonplace and harmless.”

—Joel Spolsky, http://hginit.com/00.html

Page 12: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

“Git will allow you to have multiple local branches ... the creation, merging and deletion of those lines of development take seconds ... Git makes this process incredibly easy and it changes the way most developers work when they learn it”

— Scott Chacon, http://whygitisbetterthanx.com/

Page 13: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Distributed branching & merging is awesome

Page 14: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

But...

Page 15: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches
Page 16: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

“What the !#*$ is going on?”“What the !#*$ just went wrong?”

“What the !#*$ is running on www34?”

Page 17: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

All existing revision control systems were built by people who build installed software

Page 18: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

1. Installed software2. Open source installed software3. Web applications & Software as a Service

Three kinds of software:

Page 19: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Web apps are not like installed apps

Page 20: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

“In the online world, a software product drives a service to which users have access. There is, most often, a single copy of the actual software product in use. There is one consumer of the software: you. The users are consumers of the service built atop the software.”

– Theo Schlossnagehttp://omniti.com/seeds/online-application-

deployment-reducing-risk

Page 21: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Does your team admin every computer your software is installed on?

Page 22: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Each new release happens exactly once

Page 23: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Once an upgrade has happened, the old code will never be run again

Page 24: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

1.0 1.1 1.2

1.0.1

1.1.1

1.0.2

Page 25: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

r2301 r2302 r2306

Page 26: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Well, kind of...

Page 27: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Upgrades are not deployed to all servers simultaneously

Page 28: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Staging/QA environments

Page 29: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Beta environments

Page 30: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Upgrades are not deployed to all users simultaneously

Page 31: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

A/B testing

Page 32: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Public betas

Page 33: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches
Page 34: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Configuration managementApplication code

Page 35: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Installed library dependenciesWeb service dependencies

Page 36: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Coordinating many people working on many things

and running them all at the same timeis hard

Page 37: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches
Page 38: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

But nobody knows you just deployed(unless you tell them)

Page 39: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Idea one: separate feature launches from infrastructure launches

Page 40: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

You can deploy the code for a feature long before you launch it

and nobody will know

Page 41: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

You can completely rewrite your infrastructure and keep the UI the sameand nobody will know

Page 42: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Idea two: run multiple versions of your code at once

Page 43: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

You can repeatedly switch between two backend systems and keep the UI the same

and nobody will know

Page 44: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

You can deploy a non-user facing change to only a small percentage of servers

and nobody will know

Page 45: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

You can offer different user interfacesto different users

and nobody will know

Page 46: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Need a revision control system that allows us to manage multiple parallel versions of the code and

switch between them at runtime

Page 47: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Branches?

Page 48: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Branches donʼt help you switch between versions at runtime

Page 49: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Branches donʼt help you managedependency changes that need to happen

on all versions at once

Page 50: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Need a revision control system that allows us to manage multiple parallel versions of the code

and switch between them at runtime

Page 51: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Need a revision control system that allows us to manage multiple parallel versions of the code

and switch between them at runtime

Page 52: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Need a revision control system that allows us to manage multiple parallel versions of the code

and switch between them at runtime

Page 53: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Manage the different versions within your application

Page 54: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Branch in code

Page 55: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

if ($cfg['use_snowflake_ticket_server']) {

# new hotness $ticket = snowflake_ticket();

} else {

# old and boring $ticket = db_generate_ticket();

}

Page 56: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

# hardcoded to not run$cfg['use_snowflake_ticket_server'] = false;

Page 57: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

# only in certain environmentsif ($cfg['environment'] == 'dev') { $cfg['use_snowflake_ticket_server'] = true;} else { $cfg['use_snowflake_ticket_server'] = false;}

Page 58: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

# only for a percentage of usersif (($user->id % 100) < 3) { $cfg['use_snowflake_ticket_server'] = true;} else { $cfg['use_snowflake_ticket_server'] = false;}

Page 59: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

# only for a percentage of requests$rand = rand(0,99);if ($rand < 3) { $cfg['use_snowflake_ticket_server'] = true;} else { $cfg['use_snowflake_ticket_server'] = false;}

Page 60: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

# only for a percentage of requestsif ($cfg['environment'] == 'dev') { $cfg['use_snowflake_percentage'] = 100;} else { $cfg['use_snowflake_percentage'] = 2;}

$rand = rand(0,99);if ($rand < $cfg['use_snowflake_percentage']) { $cfg['use_snowflake_ticket_server'] = true;} else { $cfg['use_snowflake_ticket_server'] = false;}

Page 61: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

# done testing, let’s launch$cfg['use_snowflake_ticket_server'] = true;

Page 62: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

# uh oh...$cfg['use_snowflake_ticket_server'] = false;

Page 63: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

# ok, it works again$cfg['use_snowflake_ticket_server'] = true;

Page 64: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Feature testing on production servers

Page 65: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

# team testing$team = array(41,287,5806,5930);if (in_array($user->id, $team)) { $cfg['use_new_context_widget'] = true;} else { $cfg['use_new_context_widget'] = false;}

Page 66: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

# private staff alpha testingif ($user->is_admin()) { $cfg['use_new_context_widget'] = true;} else { $cfg['use_new_context_widget'] = false;}

Page 67: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

# opt-in private staff alpha testing$has_cookie = isset($_COOKIE['new_context']);if ($user->is_admin() && $has_cookie) { $cfg['use_new_context_widget'] = true;} else { $cfg['use_new_context_widget'] = false;}

Page 69: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

# opt-in public betasif ($user->has_pref('new_context')) { $cfg['use_new_context_widget'] = true;} else { $cfg['use_new_context_widget'] = false;}

Page 70: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

# opt-in public betas via groupsif ($user->in_group('new_context')) { $cfg['use_new_context_widget'] = true;} else { $cfg['use_new_context_widget'] = false;}

Page 71: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

# user tagging (ala dopplr)if ($user->has_tag('context_widget')) { $cfg['use_new_context_widget'] = true;} else { $cfg['use_new_context_widget'] = false;}

Page 72: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Flexibility

Page 73: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

# dark launches can be ramped upif ($cfg['front_page_dark_launch']) { # notice we're not keeping the data get_some_really_complex_data()}

Page 74: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

1. Development on user facing features2. Development on infrastructure3. Kill-switches

Three types of feature flags:

Page 75: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

# killswitchif ($cfg['disable_login']) { error('Sorry, login is unavailable'); exit;}

Page 76: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Usually need multiple flags at onceduring development and testing

Page 77: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

# for development$cfg['disable_search_tests_all'] = false;$cfg['disable_search_ui_beta_test'] = false;$cfg['disable_search_darklaunch'] = false;

# for post launch$cfg['disable_search'] = false;

Page 78: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Complexity

Page 79: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Separate operational controls from development flags

Page 80: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Be disciplined about removing unused feature flags

Page 81: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Always deploy trunk to every server on every deploy

and manage versions through config

Page 82: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

# integrate with configuration managementif (in_array('beta', $node['roles']) { # …} else { # …}

# or generate the application config file # from configuration management system…

Page 83: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches
Page 84: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

“I canʼt tell you how many Subversion users have told me the following story: “We tried to branch our code, and that worked fine. But when it came time to merge back, it was a complete nightmare and we had to practically reapply every change by hand, and we swore never again and we developed a new way of developing software using if statements instead of branches.

“Sometimes theyʼre even kind of proud of this new, single-trunk invention of theirs. As if itʼs a virtue to work around the fact that your version control tool is not doing what itʼs meant to do.”

—Joel Spolsky, http://www.joelonsoftware.com/items/2010/03/17.html

Page 85: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Distributed branching & merging is awesome

Page 86: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Use branches for early development

Branches merged into trunk

Use flags for rollout of almost-finished code

Page 87: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

“I canʼt tell you how many Subversion users have told me the following story: “We tried to branch our code, and that worked fine. But when it came time to merge back, it was a complete nightmare and we had to practically reapply every change by hand, and we swore never again and we developed a new way of developing software using if statements instead of branches.

“Sometimes theyʼre even kind of proud of this new, single-trunk invention of theirs. As if itʼs a virtue to work around the fact that your version control tool is not doing what itʼs meant to do.”

—Joel Spolsky, http://www.joelonsoftware.com/items/2010/03/17.html

Page 88: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

“I canʼt tell you how many Subversion users have told me the following story: “We tried to branch our code, and that worked fine. But when it came time to merge back, it was a complete nightmare and we had to practically reapply every change by hand, and we swore never again and we developed a new way of developing software using if statements instead of branches.

“Sometimes theyʼre even kind of proud of this new, single-trunk invention of theirs. As if itʼs a virtue to work around the fact that your version control tool is not doing what itʼs meant to do.”

—Joel Spolsky, http://www.joelonsoftware.com/items/2010/03/17.html

Page 89: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

All existing revision control systems were built by people who build installed software

Page 90: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

Web apps are not like installed apps

Page 91: Managing change in complex websites Paul …assets.en.oreilly.com/1/event/44/Always Ship Trunk...and we developed a new way of developing software using if statements instead of branches

What would a revision control system built for supporting deployed web applications be like?