Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Software migration strategies

Software migration strategies

The architecture and code you write today is tomorrow's legacy. This talks discusses - besides some basics and theory - how you can safely apply big refactorings to your production environments with minimum risk. We will discuss examples of successful and failed migrations, and why this is not only a technical, but also a cultural issue.

Soenke Ruempler

November 07, 2013
Tweet

More Decks by Soenke Ruempler

Other Decks in Programming

Transcript

  1. “A [software] migration strategy must ensure that the system remains

    fully functional during the modernization effort.” http://en.wikipedia.org/wiki/Software_modernization
  2. “When you throw away code and start from scratch, you

    are throwing away all that knowledge. All those collected bug fixes. Years of programming work.” http://www.joelonsoftware.com/articles/fog0000000069.html
  3. ==

  4. 1. Isolate the component which needs to be replaced to

    in order to fulfill a business requirement
  5. Migration Steps / Code examples that are: • production-ready, •

    no feature branch involved • can be deployed as-is • not introducing any downtime will be marked with a star.
  6. Possibility 1: introduce and refactor to a new indirection layer

    Consumer Code Indirection Layer Old component to be replaced Consumer Code Consumer Code
  7. 2. Implement the new component Consumer Code Indirection Layer Old

    component to be replaced New component Consumer Code Consumer Code
  8. 3. Add a feature toggle / flip Consumer Code Indirection

    Layer Old component to be replaced New component Feature Flip Consumer Code Consumer Code
  9. 4. Remove old component and feature flip Consumer Code Indirection

    Layer New component Consumer Code Consumer Code
  10. 4a) Maybe remove the Indirection Layer as well? Consumer Code

    New component Consumer Code Consumer Code
  11. Ok, so I might not need the whole indirection layer

    in the end. So is it worth the effort?
  12. if the codebase is hard to refactor and the new

    indirection layer will get obsolete eventually anyway
  13. Consumer Code Consumer Code function doThis() { if (getconfig(‘migrate_legacy_component’) {

    // new implementation } else { // old implementation } } function doThat() { if (getconfig(‘migrate_legacy_component’) { // new implementation } else { // old implementation } } function doStuffs() { if (getconfig(‘migrate_legacy_component’) { // new implementation } else { // old implementation } } Consumer Code Feature toggles everwhere!
  14. Consumer Code Consumer Code function doThis() { // new implementation

    } function doThat() { // new implementation } function doStuffs() { // new implementation } Consumer Code
  15. Consumer Code Indirection Layer Old component to be replaced New

    component Migration Decorator Consumer Code Consumer Code
  16. Decorator pattern! class MigrationStorageProviderDecorator implements StorageProviderInterface { public function __construct(

    StorageProviderInterface $oldStorageProvider, StorageProviderInterface $newStorageProvider ) { $this->oldStorageProvider = $oldStorageProvider; $this->newStorageProvider = $newStorageProvider; } }
  17. On-the-fly data migration class MigrationStorageProviderDecorator implements StorageProviderInterface { public function

    get($id) { if ($storageItem = $this->newStorageProvider->get($id)) { // found item in new storage, migration already done return $storageItem; } if ($storageItem = $this->oldStorageProvider->get($id)) { // found item in old provider, copy to new provider, then return $this->newStorageProvider->put($storageItem); return $storageItem; } throw new StorageItemNotFoundException(); } }
  18. Verify Branch by Abstraction Consumer Code Indirection Layer Old component

    to be replaced New component Verify by comparing old and new component results Consumer Code Consumer Code http://java.dzone.com/articles/application-pattern-verify
  19. “When code runs in production, it doesn't have the protection

    of a clean environment like your tests do.” http://about.travis-ci.org/blog/2013-06-11-unit-testing-your-production-code/
  20. “Defend against the impossible, because the impossible will happen.” --

    Defensive Programming http://c2.com/cgi/wiki?DefensiveProgramming
  21. Culture Requiments analysis / QA Development Production/Rollout Cont. Deployment Gemba

    walks High level acceptance tests (e.g. cucumber) Regression tests Isolating the component / scope of the migration Branch by Abstration Verify BBA Feature Flips Metrics (Audit)Logs One-some-many rollout Feature flags Recap