SlideShare a Scribd company logo
D R S T R A N G L E R 

& M R H Y P E
S T R A N G L E R PAT T E R N I N P R A C T I C E
Michał Kurzeja
CTO @ Accesto
TW: @michalKurzeja
michal@accesto.com
T H I S TA L K S I S A B O U T
• Where legacy comes from?
• Why it is worth to get rid of legacy…
• … and how to make it properly?
• How not to hurt yourself
• Examples
T H I S TA L K I S N O T A B O U T
• How to test
• How to refactor classes/methods
• Silver bullet step-by-step approach
Bad practices
„Mr Hype”
Good practices

„Dr Strangler”
L E G A C Y C O D E
L E G A C Y ! = I N H E R I T E D C O D E
E X P E C TAT I O N S
R E A L I T Y
Q U A L I T Y D E C R E A S E S I N T I M E
- L A C K O F T H E „ B O Y S C O U T ” R U L E
0
17,5
35
52,5
70
2010 2011 2012 2013
R E S U LT S ? I S S U E S :
• Complicated code
• Harder to write tests
• Difficult deployment
• Reluctance of developers
• Hard to develop
H O W T O C O N V I N C E B U S I N E S S
• Slower development
• competitors might be faster
• increased costs
• HR issues: harder recruitment, more people leaving
• Lots of bugs, angry customers
• It might explode at any time ;)
2 0 1 2 , K N I G H T C A P I TA L G R O U P
$460 mln loss in 45 minutes
W H AT C A N W E D O ?
R E W R I T E F R O M S C R AT C H
F R O M 9 0 % T O 0 %
O F M A R K E T S H A R E
D E C L I N E O F N E T S C A P E
L O S T I T T O I N T E R N E T E X P L O R E R !
K E E P O N G O I N G
R E FA C T O R ?
Rewrite from scratchKeep on going
Refactor STRANGLE!
FUN
RISK
S T R A N G L E R PAT T E R N
G AT E WAY / FA C A D E
G AT E WAY - B U I L D I T L E A N
server {

listen 80;

server_name domain.com;



location /profile {

proxy_pass http://10.0.3.10:80;

}



location /news {

proxy_pass http://10.0.3.10:80;

}



proxy_pass http://10.0.3.20:80;

}
G AT E WAY - P O S S I B L E S O L U T I O N S
• API - Open Source
• Kong
• API - Paid
• AWS API Gateway
• WWW
• HaProxy
• Nginx/Apache/…
S TA R T W I T H C AT C H A L L
S H A R E D D ATA B A S E
D I S T R I B U T E D S H I T
S P L I T D ATA B A S E S
• Scheduled sync (cron)
• Events (required change in legacy)
• DB Triggers
• Transaction log (Binlog -> Kafka)
A P I
B O U N D A R I E S
ANTI-CORRUPTION LAYER
A C L
L E G A C Y I N A B O X
I N P R A C T I C E
L O N G T I M E A G O …
• Market leader
• Project started in 2010, we took over in 2016
• Customers: banks, political parties - no downtime
allowed ;)
N O F R O N T- C O N T R O L L E R
„ C U T E ” V E R S I O N I N G
„ M A G I C ” S T R U C T U R E
„ B U L L E T P R O O F ” C O N F I G
It was $_SERVER[SERVER_NAME];
„ R E A D A B L E ” C O D E
Generally….
S E V E R A L G R AY H A I R L AT E R
• Monorepo
• Apache as facade
• Anti-Corruption Layer -> API
• JSON Web Token
• Configuration by env variables
• 100% automated deployment (on Kubernetes)
• Business is very happy
• Programmers are still alive (and work for us)
M I S TA K E S 

W H AT C O U L D B E D O N E B E T T E R
F E AT U R E T O G G L E
J W T F R O M D AY 1 0
B E T T E R A C L
I S S U E S
P R O S
• Small risk, less stress, quick releases
• Instant effects
• Both business and developers happy
S E C O N D A P P R O A C H - A C L *
* M O D I F I E D A B I T
M O D E R N A C L L E G A C Y
https://github.com/VaughnVernon/IDDD_Samples/tree/master/iddd_collaboration/src/main/java/com/saasovation/
collaboration/port/adapter/service
M O D E R N A C L L E G A C Y
APIREPO
class Currency
{
private $isoCode;
private $default;
private $ratio;
}
M O D E R N - C U R R E N C Y M O D E L
interface CurrencyRepository
{
public function findAll();
public function getDefault();
public function find(string $isoCode);
public function save(Currency $currency);
}
M O D E R N - C U R R E N C Y R E P O S I T O RY
class Internal_CurrencyController extends Internal_Controller_InternalController
{
public function listcurrenciesAction()
{
$this->checkIp();
$this->getResponse()->setHeader('Content-type', 'application/json');
$mCurrency = new Default_Model_Currency();
/** @var Zend_Db_Table_Rowset $currencies */
$currencies = $mCurrency->fetchAll('status = "active"');
$this->getResponse()
->setBody(json_encode($currencies->toArray()))
->setHttpResponseCode(200);
}
}
L E G A C Y - C U R R E N C Y FA C A D E
interface CurrencyAdapter
{
public function findAll(): array;
}
A C L - C U R R E N C Y A P I I N T E R FA C E
class LegacyCurrencyAdapter implements CurrencyAdapter
{
public function findAll(): array
{
$response = $this->client->request('GET', 'listCurrencies');
$currencies = json_decode((string) $response->getBody(), true);
return array_map(function ($row) {
$currency = $this->currencyTranslator->createFromArray($row);
if ($exCurrency = $this->currRepo->find($currency->isoCode())) {
$currency->setRatio($exCurrency->getRatio());
$currency->setDefault($exCurrency->getDefault());
}
return $currency;
}, $currencies);
}
}
A C L - C U R R E N C Y A P I
class LegacyCurrencyTranslator implements CurrencyTranslator
{
public function createFromArray(array $data)
{
$default = filter_var($data['default'], FILTER_VALIDATE_BOOLEAN);
$ratio = filter_var($data['value'], FILTER_VALIDATE_FLOAT);
return new Currency($data['code'], $ratio, $default);
}
}
A C L - C U R R E N C Y T R A N S L AT O R
W H AT N O T T O D O
R O U T I N G I N L E G A C Y / M O D E R N
L A C K O F A N T I - C O R R U P T I O N L AY E R
P L A N F I R S T,
C O D E L AT E R
GETTING STARTED WITH DDD WHEN SURROUNDED BY
LEGACY SYSTEMS
E R I C E VA N S
W R I T E S O F T WA R E T H AT
I S E A S Y T O S T R A N G L E
Michał Kurzeja
CTO @ Accesto
@michalKurzeja
michal@accesto.com
Thanks!

More Related Content

Similar to Strangler Pattern in practice @PHPers Day 2019

Architecting your IT career
Architecting your IT careerArchitecting your IT career
Architecting your IT career
John Mark Troyer
 
Reduce, Reuse, Refactor
Reduce, Reuse, RefactorReduce, Reuse, Refactor
Reduce, Reuse, Refactor
cklosowski
 
Zend con 2016 - Asynchronous Prorgamming in PHP
Zend con 2016 - Asynchronous Prorgamming in PHPZend con 2016 - Asynchronous Prorgamming in PHP
Zend con 2016 - Asynchronous Prorgamming in PHP
Adam Englander
 
SharePoint Saturday Redmond - Building solutions with the future in mind
SharePoint Saturday Redmond - Building solutions with the future in mindSharePoint Saturday Redmond - Building solutions with the future in mind
SharePoint Saturday Redmond - Building solutions with the future in mindChris Johnson
 
Cloud Identity Deployed
Cloud Identity DeployedCloud Identity Deployed
Cloud Identity DeployedPablo Valarezo
 
Choosing the right database
Choosing the right databaseChoosing the right database
Choosing the right database
David Simons
 
Angular server side rendering with NodeJS - In Pursuit Of Speed
Angular server side rendering with NodeJS - In Pursuit Of SpeedAngular server side rendering with NodeJS - In Pursuit Of Speed
Angular server side rendering with NodeJS - In Pursuit Of Speed
Ilia Idakiev
 
Data Modelling at Scale
Data Modelling at ScaleData Modelling at Scale
Data Modelling at Scale
David Simons
 
From Content Strategy to Drupal Site Building - Connecting the dots
From Content Strategy to Drupal Site Building - Connecting the dotsFrom Content Strategy to Drupal Site Building - Connecting the dots
From Content Strategy to Drupal Site Building - Connecting the dots
Ronald Ashri
 
From Content Strategy to Drupal Site Building - Connecting the Dots
From Content Strategy to Drupal Site Building - Connecting the DotsFrom Content Strategy to Drupal Site Building - Connecting the Dots
From Content Strategy to Drupal Site Building - Connecting the Dots
Ronald Ashri
 
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHPphp[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
Adam Englander
 
Decoupled APIs through microservices
Decoupled APIs through microservicesDecoupled APIs through microservices
Decoupled APIs through microservices
David Simons
 
The Road to QA
The Road to QAThe Road to QA
The Road to QA
Benjamin Bischoff
 
Content First in Action
Content First in ActionContent First in Action
Content First in Action
Stephanie Leary
 
Reduce, Reuse, Refactor
Reduce, Reuse, RefactorReduce, Reuse, Refactor
Reduce, Reuse, Refactor
cklosowski
 
BoSUSA18 | Bob Moesta| The 5 Skills Of An Innovator
BoSUSA18 | Bob Moesta| The 5 Skills Of An InnovatorBoSUSA18 | Bob Moesta| The 5 Skills Of An Innovator
BoSUSA18 | Bob Moesta| The 5 Skills Of An Innovator
Business of Software Conference
 
React native first impression
React native first impressionReact native first impression
React native first impression
Alvaro Viebrantz
 
Creating Modern Metadata Systems [FutureStack16 NYC]
Creating Modern Metadata Systems [FutureStack16 NYC]Creating Modern Metadata Systems [FutureStack16 NYC]
Creating Modern Metadata Systems [FutureStack16 NYC]
New Relic
 
The Blockchain: an Enterprise Play
The Blockchain: an Enterprise PlayThe Blockchain: an Enterprise Play
The Blockchain: an Enterprise Play
Lisa Cheng
 
Digital Data Commons - Emergence of AI Blockchain Convergence
Digital Data Commons - Emergence of AI Blockchain ConvergenceDigital Data Commons - Emergence of AI Blockchain Convergence
Digital Data Commons - Emergence of AI Blockchain Convergence
Gokul Alex
 

Similar to Strangler Pattern in practice @PHPers Day 2019 (20)

Architecting your IT career
Architecting your IT careerArchitecting your IT career
Architecting your IT career
 
Reduce, Reuse, Refactor
Reduce, Reuse, RefactorReduce, Reuse, Refactor
Reduce, Reuse, Refactor
 
Zend con 2016 - Asynchronous Prorgamming in PHP
Zend con 2016 - Asynchronous Prorgamming in PHPZend con 2016 - Asynchronous Prorgamming in PHP
Zend con 2016 - Asynchronous Prorgamming in PHP
 
SharePoint Saturday Redmond - Building solutions with the future in mind
SharePoint Saturday Redmond - Building solutions with the future in mindSharePoint Saturday Redmond - Building solutions with the future in mind
SharePoint Saturday Redmond - Building solutions with the future in mind
 
Cloud Identity Deployed
Cloud Identity DeployedCloud Identity Deployed
Cloud Identity Deployed
 
Choosing the right database
Choosing the right databaseChoosing the right database
Choosing the right database
 
Angular server side rendering with NodeJS - In Pursuit Of Speed
Angular server side rendering with NodeJS - In Pursuit Of SpeedAngular server side rendering with NodeJS - In Pursuit Of Speed
Angular server side rendering with NodeJS - In Pursuit Of Speed
 
Data Modelling at Scale
Data Modelling at ScaleData Modelling at Scale
Data Modelling at Scale
 
From Content Strategy to Drupal Site Building - Connecting the dots
From Content Strategy to Drupal Site Building - Connecting the dotsFrom Content Strategy to Drupal Site Building - Connecting the dots
From Content Strategy to Drupal Site Building - Connecting the dots
 
From Content Strategy to Drupal Site Building - Connecting the Dots
From Content Strategy to Drupal Site Building - Connecting the DotsFrom Content Strategy to Drupal Site Building - Connecting the Dots
From Content Strategy to Drupal Site Building - Connecting the Dots
 
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHPphp[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
 
Decoupled APIs through microservices
Decoupled APIs through microservicesDecoupled APIs through microservices
Decoupled APIs through microservices
 
The Road to QA
The Road to QAThe Road to QA
The Road to QA
 
Content First in Action
Content First in ActionContent First in Action
Content First in Action
 
Reduce, Reuse, Refactor
Reduce, Reuse, RefactorReduce, Reuse, Refactor
Reduce, Reuse, Refactor
 
BoSUSA18 | Bob Moesta| The 5 Skills Of An Innovator
BoSUSA18 | Bob Moesta| The 5 Skills Of An InnovatorBoSUSA18 | Bob Moesta| The 5 Skills Of An Innovator
BoSUSA18 | Bob Moesta| The 5 Skills Of An Innovator
 
React native first impression
React native first impressionReact native first impression
React native first impression
 
Creating Modern Metadata Systems [FutureStack16 NYC]
Creating Modern Metadata Systems [FutureStack16 NYC]Creating Modern Metadata Systems [FutureStack16 NYC]
Creating Modern Metadata Systems [FutureStack16 NYC]
 
The Blockchain: an Enterprise Play
The Blockchain: an Enterprise PlayThe Blockchain: an Enterprise Play
The Blockchain: an Enterprise Play
 
Digital Data Commons - Emergence of AI Blockchain Convergence
Digital Data Commons - Emergence of AI Blockchain ConvergenceDigital Data Commons - Emergence of AI Blockchain Convergence
Digital Data Commons - Emergence of AI Blockchain Convergence
 

More from Michał Kurzeja

Kolejkowanie w systemach multi-tenant - PHPCon 2023
Kolejkowanie w systemach multi-tenant - PHPCon 2023Kolejkowanie w systemach multi-tenant - PHPCon 2023
Kolejkowanie w systemach multi-tenant - PHPCon 2023
Michał Kurzeja
 
Rozszerzalność Symfony - PHPCon 2023
Rozszerzalność Symfony - PHPCon 2023Rozszerzalność Symfony - PHPCon 2023
Rozszerzalność Symfony - PHPCon 2023
Michał Kurzeja
 
Event-driven architecture, the easy way.pdf
Event-driven architecture, the easy way.pdfEvent-driven architecture, the easy way.pdf
Event-driven architecture, the easy way.pdf
Michał Kurzeja
 
Rozszerzalność aplikacji Symfony
Rozszerzalność aplikacji SymfonyRozszerzalność aplikacji Symfony
Rozszerzalność aplikacji Symfony
Michał Kurzeja
 
Docker reverse proxy z użyciem Traefik
Docker reverse proxy z użyciem TraefikDocker reverse proxy z użyciem Traefik
Docker reverse proxy z użyciem Traefik
Michał Kurzeja
 
Symfony messenger - PHPers Summit 2019
Symfony messenger - PHPers Summit 2019Symfony messenger - PHPers Summit 2019
Symfony messenger - PHPers Summit 2019
Michał Kurzeja
 
Kubernetes - 0 do 1 - 4Developers Warszawa 2019
Kubernetes - 0 do 1 - 4Developers Warszawa 2019Kubernetes - 0 do 1 - 4Developers Warszawa 2019
Kubernetes - 0 do 1 - 4Developers Warszawa 2019
Michał Kurzeja
 
Serverless Architecture
Serverless ArchitectureServerless Architecture
Serverless Architecture
Michał Kurzeja
 
Docker workshop
Docker workshopDocker workshop
Docker workshop
Michał Kurzeja
 
Docker - introduction
Docker - introductionDocker - introduction
Docker - introduction
Michał Kurzeja
 
Symfony2 - garść porad
Symfony2 - garść poradSymfony2 - garść porad
Symfony2 - garść porad
Michał Kurzeja
 

More from Michał Kurzeja (11)

Kolejkowanie w systemach multi-tenant - PHPCon 2023
Kolejkowanie w systemach multi-tenant - PHPCon 2023Kolejkowanie w systemach multi-tenant - PHPCon 2023
Kolejkowanie w systemach multi-tenant - PHPCon 2023
 
Rozszerzalność Symfony - PHPCon 2023
Rozszerzalność Symfony - PHPCon 2023Rozszerzalność Symfony - PHPCon 2023
Rozszerzalność Symfony - PHPCon 2023
 
Event-driven architecture, the easy way.pdf
Event-driven architecture, the easy way.pdfEvent-driven architecture, the easy way.pdf
Event-driven architecture, the easy way.pdf
 
Rozszerzalność aplikacji Symfony
Rozszerzalność aplikacji SymfonyRozszerzalność aplikacji Symfony
Rozszerzalność aplikacji Symfony
 
Docker reverse proxy z użyciem Traefik
Docker reverse proxy z użyciem TraefikDocker reverse proxy z użyciem Traefik
Docker reverse proxy z użyciem Traefik
 
Symfony messenger - PHPers Summit 2019
Symfony messenger - PHPers Summit 2019Symfony messenger - PHPers Summit 2019
Symfony messenger - PHPers Summit 2019
 
Kubernetes - 0 do 1 - 4Developers Warszawa 2019
Kubernetes - 0 do 1 - 4Developers Warszawa 2019Kubernetes - 0 do 1 - 4Developers Warszawa 2019
Kubernetes - 0 do 1 - 4Developers Warszawa 2019
 
Serverless Architecture
Serverless ArchitectureServerless Architecture
Serverless Architecture
 
Docker workshop
Docker workshopDocker workshop
Docker workshop
 
Docker - introduction
Docker - introductionDocker - introduction
Docker - introduction
 
Symfony2 - garść porad
Symfony2 - garść poradSymfony2 - garść porad
Symfony2 - garść porad
 

Recently uploaded

Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 

Recently uploaded (20)

Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 

Strangler Pattern in practice @PHPers Day 2019

  • 1. D R S T R A N G L E R 
 & M R H Y P E S T R A N G L E R PAT T E R N I N P R A C T I C E
  • 2. Michał Kurzeja CTO @ Accesto TW: @michalKurzeja michal@accesto.com
  • 3. T H I S TA L K S I S A B O U T • Where legacy comes from? • Why it is worth to get rid of legacy… • … and how to make it properly? • How not to hurt yourself • Examples
  • 4. T H I S TA L K I S N O T A B O U T • How to test • How to refactor classes/methods • Silver bullet step-by-step approach
  • 5. Bad practices „Mr Hype” Good practices
 „Dr Strangler”
  • 6. L E G A C Y C O D E
  • 7.
  • 8. L E G A C Y ! = I N H E R I T E D C O D E
  • 9. E X P E C TAT I O N S
  • 10. R E A L I T Y
  • 11. Q U A L I T Y D E C R E A S E S I N T I M E - L A C K O F T H E „ B O Y S C O U T ” R U L E 0 17,5 35 52,5 70 2010 2011 2012 2013
  • 12. R E S U LT S ? I S S U E S : • Complicated code • Harder to write tests • Difficult deployment • Reluctance of developers • Hard to develop
  • 13. H O W T O C O N V I N C E B U S I N E S S • Slower development • competitors might be faster • increased costs • HR issues: harder recruitment, more people leaving • Lots of bugs, angry customers • It might explode at any time ;)
  • 14. 2 0 1 2 , K N I G H T C A P I TA L G R O U P $460 mln loss in 45 minutes
  • 15. W H AT C A N W E D O ?
  • 16. R E W R I T E F R O M S C R AT C H
  • 17. F R O M 9 0 % T O 0 % O F M A R K E T S H A R E D E C L I N E O F N E T S C A P E L O S T I T T O I N T E R N E T E X P L O R E R !
  • 18. K E E P O N G O I N G
  • 19. R E FA C T O R ?
  • 20.
  • 21. Rewrite from scratchKeep on going Refactor STRANGLE! FUN RISK
  • 22. S T R A N G L E R PAT T E R N
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29. G AT E WAY / FA C A D E
  • 30. G AT E WAY - B U I L D I T L E A N server {
 listen 80;
 server_name domain.com;
 
 location /profile {
 proxy_pass http://10.0.3.10:80;
 }
 
 location /news {
 proxy_pass http://10.0.3.10:80;
 }
 
 proxy_pass http://10.0.3.20:80;
 }
  • 31. G AT E WAY - P O S S I B L E S O L U T I O N S • API - Open Source • Kong • API - Paid • AWS API Gateway • WWW • HaProxy • Nginx/Apache/…
  • 32. S TA R T W I T H C AT C H A L L
  • 33.
  • 34. S H A R E D D ATA B A S E
  • 35. D I S T R I B U T E D S H I T
  • 36. S P L I T D ATA B A S E S • Scheduled sync (cron) • Events (required change in legacy) • DB Triggers • Transaction log (Binlog -> Kafka)
  • 37. A P I
  • 38.
  • 39. B O U N D A R I E S
  • 41. A C L
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48. L E G A C Y I N A B O X
  • 49.
  • 50.
  • 51. I N P R A C T I C E
  • 52. L O N G T I M E A G O … • Market leader • Project started in 2010, we took over in 2016 • Customers: banks, political parties - no downtime allowed ;)
  • 53. N O F R O N T- C O N T R O L L E R
  • 54. „ C U T E ” V E R S I O N I N G
  • 55. „ M A G I C ” S T R U C T U R E
  • 56. „ B U L L E T P R O O F ” C O N F I G It was $_SERVER[SERVER_NAME];
  • 57. „ R E A D A B L E ” C O D E
  • 59. S E V E R A L G R AY H A I R L AT E R
  • 60. • Monorepo • Apache as facade • Anti-Corruption Layer -> API • JSON Web Token • Configuration by env variables
  • 61.
  • 62. • 100% automated deployment (on Kubernetes) • Business is very happy • Programmers are still alive (and work for us)
  • 63. M I S TA K E S 
 W H AT C O U L D B E D O N E B E T T E R
  • 64. F E AT U R E T O G G L E
  • 65. J W T F R O M D AY 1 0
  • 66. B E T T E R A C L
  • 67. I S S U E S
  • 68. P R O S • Small risk, less stress, quick releases • Instant effects • Both business and developers happy
  • 69. S E C O N D A P P R O A C H - A C L * * M O D I F I E D A B I T
  • 70. M O D E R N A C L L E G A C Y https://github.com/VaughnVernon/IDDD_Samples/tree/master/iddd_collaboration/src/main/java/com/saasovation/ collaboration/port/adapter/service
  • 71. M O D E R N A C L L E G A C Y APIREPO
  • 72. class Currency { private $isoCode; private $default; private $ratio; } M O D E R N - C U R R E N C Y M O D E L
  • 73. interface CurrencyRepository { public function findAll(); public function getDefault(); public function find(string $isoCode); public function save(Currency $currency); } M O D E R N - C U R R E N C Y R E P O S I T O RY
  • 74. class Internal_CurrencyController extends Internal_Controller_InternalController { public function listcurrenciesAction() { $this->checkIp(); $this->getResponse()->setHeader('Content-type', 'application/json'); $mCurrency = new Default_Model_Currency(); /** @var Zend_Db_Table_Rowset $currencies */ $currencies = $mCurrency->fetchAll('status = "active"'); $this->getResponse() ->setBody(json_encode($currencies->toArray())) ->setHttpResponseCode(200); } } L E G A C Y - C U R R E N C Y FA C A D E
  • 75. interface CurrencyAdapter { public function findAll(): array; } A C L - C U R R E N C Y A P I I N T E R FA C E
  • 76. class LegacyCurrencyAdapter implements CurrencyAdapter { public function findAll(): array { $response = $this->client->request('GET', 'listCurrencies'); $currencies = json_decode((string) $response->getBody(), true); return array_map(function ($row) { $currency = $this->currencyTranslator->createFromArray($row); if ($exCurrency = $this->currRepo->find($currency->isoCode())) { $currency->setRatio($exCurrency->getRatio()); $currency->setDefault($exCurrency->getDefault()); } return $currency; }, $currencies); } } A C L - C U R R E N C Y A P I
  • 77. class LegacyCurrencyTranslator implements CurrencyTranslator { public function createFromArray(array $data) { $default = filter_var($data['default'], FILTER_VALIDATE_BOOLEAN); $ratio = filter_var($data['value'], FILTER_VALIDATE_FLOAT); return new Currency($data['code'], $ratio, $default); } } A C L - C U R R E N C Y T R A N S L AT O R
  • 78. W H AT N O T T O D O
  • 79. R O U T I N G I N L E G A C Y / M O D E R N
  • 80. L A C K O F A N T I - C O R R U P T I O N L AY E R
  • 81. P L A N F I R S T, C O D E L AT E R
  • 82.
  • 83. GETTING STARTED WITH DDD WHEN SURROUNDED BY LEGACY SYSTEMS E R I C E VA N S
  • 84.
  • 85. W R I T E S O F T WA R E T H AT I S E A S Y T O S T R A N G L E
  • 86. Michał Kurzeja CTO @ Accesto @michalKurzeja michal@accesto.com Thanks!