SlideShare una empresa de Scribd logo
1 de 86
Descargar para leer sin conexión
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!

Más contenido relacionado

Similar a Strangler Pattern in practice @PHPers Day 2019

Architecting your IT career
Architecting your IT careerArchitecting your IT career
Architecting your IT careerJohn Mark Troyer
 
Reduce, Reuse, Refactor
Reduce, Reuse, RefactorReduce, Reuse, Refactor
Reduce, Reuse, Refactorcklosowski
 
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 PHPAdam 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
 
Introduction of the Agile Digital Enterprise Framework
Introduction of the Agile Digital Enterprise FrameworkIntroduction of the Agile Digital Enterprise Framework
Introduction of the Agile Digital Enterprise FrameworkPierre E. NEIS
 
Choosing the right database
Choosing the right databaseChoosing the right database
Choosing the right databaseDavid 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 SpeedIlia Idakiev
 
Data Modelling at Scale
Data Modelling at ScaleData Modelling at Scale
Data Modelling at ScaleDavid 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 dotsRonald 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 DotsRonald 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 PHPAdam Englander
 
Decoupled APIs through microservices
Decoupled APIs through microservicesDecoupled APIs through microservices
Decoupled APIs through microservicesDavid Simons
 
Reduce, Reuse, Refactor
Reduce, Reuse, RefactorReduce, Reuse, Refactor
Reduce, Reuse, Refactorcklosowski
 
React native first impression
React native first impressionReact native first impression
React native first impressionAlvaro 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 PlayLisa Cheng
 

Similar a 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
 
Introduction of the Agile Digital Enterprise Framework
Introduction of the Agile Digital Enterprise FrameworkIntroduction of the Agile Digital Enterprise Framework
Introduction of the Agile Digital Enterprise Framework
 
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
 

Más de 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 2023Michał Kurzeja
 
Rozszerzalność Symfony - PHPCon 2023
Rozszerzalność Symfony - PHPCon 2023Rozszerzalność Symfony - PHPCon 2023
Rozszerzalność Symfony - PHPCon 2023Michał 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.pdfMichał Kurzeja
 
Rozszerzalność aplikacji Symfony
Rozszerzalność aplikacji SymfonyRozszerzalność aplikacji Symfony
Rozszerzalność aplikacji SymfonyMichał 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 TraefikMichał Kurzeja
 
Symfony messenger - PHPers Summit 2019
Symfony messenger - PHPers Summit 2019Symfony messenger - PHPers Summit 2019
Symfony messenger - PHPers Summit 2019Michał 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 2019Michał Kurzeja
 
Symfony2 - garść porad
Symfony2 - garść poradSymfony2 - garść porad
Symfony2 - garść poradMichał Kurzeja
 

Más de 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
 

Último

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Último (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

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!