|
| 1 | +# Branch versions(Part 1) |
| 2 | + |
| 3 | +This article introduces a software development paradigm, which has been implemented and used on Verizon Media Group's Video syndication teams for the past 3 years. |
| 4 | + |
| 5 | +The 'Branch versions' concept allows stakeholders to test and verify different code variants without affecting production. |
| 6 | + |
| 7 | +On our teams, every code change, creates a branch version which allows product managers, QA teams and different customers to test and verify changes, without merging it to master. |
| 8 | + |
| 9 | +The impact is huge, just consider some of the following scenarios: |
| 10 | + |
| 11 | +1. A product manager has a preliminary idea, but to assess its value and refine requirements, more data is required. |
| 12 | +Serving a branch version to a group of users with a POC can contribute ideas for a better design and better product planning. |
| 13 | + |
| 14 | +2. A bug is reported - use branch versions to inspect, and before deploying the fix, assign the branch version to a user/PM/QA to verify the fix. |
| 15 | +Only then, you update your tests, submit a PR and merge to master. |
| 16 | + |
| 17 | +3. Easy rollback - A critical bug was deployed, requiring a fast rollback. Now, thanks to branch versions, we're storing every version created by every branch, including master branch, which allows you to easily transition all of your users to a specific version in a matter of seconds. |
| 18 | + |
| 19 | +(TBH - Scenario 3 never happened. avg. 90% unit tests coverage and branch versions) |
| 20 | + |
| 21 | +So, what defines a branch version? |
| 22 | + |
| 23 | +1. Isolation - The modified code is not part of master branch. |
| 24 | +2. Debug - Branch versions contain sourcemaps, debug info developers can inspect the code on multiple environments(extremely useful for cross-browser issues) |
| 25 | +3. Protected - A branch version can be used only by specific people. (recommended) |
| 26 | + |
| 27 | +The core concept is that a branch version simply represents a different deployment path. |
| 28 | + |
| 29 | +Let's dig deeper and see what it means... |
| 30 | + |
| 31 | +Webpack |
| 32 | + |
| 33 | +Let's examine [this simple React application](https://github.com/eranshapira/webpack-branch-versions). |
| 34 | + |
| 35 | +The key concepts we use in webpack are the following features: |
| 36 | + |
| 37 | +1. [dynamic imports](https://webpack.js.org/guides/code-splitting/#dynamic-imports) - each webpack entry point dynamically imports the rest of the bundle. ([js](https://github.com/eranshapira/webpack-branch-versions/blob/master/src/index.js) dynamically loads [js](https://github.com/eranshapira/webpack-branch-versions/blob/master/src/app.js)) |
| 38 | +2. [output.publicPath](https://webpack.js.org/configuration/output/#outputpublicpath) - define an absolute path for bundles, which instructs webpack to load any asset without any relative path issues. |
| 39 | + |
| 40 | +CI/CD |
| 41 | + |
| 42 | +There is only one concept that we need to maintain in our CI/CD process - Deployment must be performed to the same path specified in webpack's config.output.publicPath. |
| 43 | + |
| 44 | +Server endpoint |
| 45 | + |
| 46 | +Now that we have an infrastructure to deploy different branch versions, we need to provide a way to use these versions. |
| 47 | + |
| 48 | +Examine [this very-basic-never-to-be-used server](https://github.com/eranshapira/webpack-branch-versions/blob/master/server/index.js), In our code, the html served in the response is changing the folder from which it loads main.js. |
0 commit comments