How to build customizable multitenant web applications - IPC11 Spring Edition

  • 9,734 views
Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
9,734
On Slideshare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
237
Comments
0
Likes
8

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. How to build customizablemultitenant web applications
  • 2. Multitenant web applications About me  Stephan Hochdörfer, bitExpert AG  Department Manager Research Labs  enjoying PHP since 1999  S.Hochdoerfer@bitExpert.de  @shochdoerfer
  • 3. Multitenant web applications Single Tenancy
  • 4. Multitenant web applications Developer vs. Businessman
  • 5. Multitenant web applications Single Tenancy – more customers
  • 6. Multitenant web applications Single Tenancy – even more customers
  • 7. Multitenant web applications Where will this lead to?
  • 8. Multitenant web applications Maintenance nightmare!
  • 9. Multitenant web applications Single Tenancy Tenant 1 Application Database Hardware
  • 10. Multitenant web applications Single Tenancy Tenant 1 Tenant 2 Tenant 3 Application Application Application Database Database Database Hardware Hardware Hardware
  • 11. Multitenant web applications Multi Tenancy Tenant 1 Tenant 2 Tenant 3 Application Database Hardware
  • 12. Multitenant web applications What should be customizable?
  • 13. Multitenant web applications What should be customizable? Tenant 1 Tenant 2 Tenant 3 Application Database Hardware
  • 14. Multitenant web applications What should be customizable? Tenant 1 Tenant 2 Tenant 3 Application Database Hardware
  • 15. Multitenant web applications How to skin an application?
  • 16. Multitenant web applications How to skin an application? Remember: It`s a web application!
  • 17. Multitenant web applications How to skin an application? HTML
  • 18. Multitenant web applications How to skin an application? HTML + CSS
  • 19. Multitenant web applications
  • 20. Multitenant web applications
  • 21. Multitenant web applications
  • 22. Multitenant web applications How to customize? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>My App</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="css/styles/myapp.css" /> </head> <body> </body> </html>
  • 23. Multitenant web applications How to customize? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>My App</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="css/styles/<?php echo $tenant ?>.css" /> </head> <body> </body> </html>
  • 24. Multitenant web applications How to customize? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>My App</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="css/styles/myapp.css" /> <link rel="stylesheet" type="text/css" href="css/styles/<?php echo $tenant ?>.css" /> </head> <body> </body> </html>
  • 25. Multitenant web applications Feature driven CSS Wait, there`s more...
  • 26. Multitenant web applications Feature driven CSS display: none
  • 27. Multitenant web applications This is not an security advice!
  • 28. Multitenant web applications Next level...
  • 29. Multitenant web applications Menubar generation <?php if($user->hasEnabled(Module::ORDERMANAGEMENT)) { if($user->canAccess(OrderManagement::LIST_ORDERS)) { $this->renderLink(OrderManagement::LIST_ORDERS); } if($user->canAccess(OrderManagement::ADD_ORDER)) { $this->renderLink(OrderManagement::ADD_ORDER); } }
  • 30. Multitenant web applications Menubar generation <?php if($tenant->hasModule(Module::ORDERMANAGEMENT) { if($user->hasEnabled(Module::ORDERMANAGEMENT)) { if($user->canAccess(OrderManagement::LIST_ORDERS)) { $this->renderLink(OrderManagement::LIST_ORDERS); } if($user->canAccess(OrderManagement::ADD_ORDER)) { $this->renderLink(OrderManagement::ADD_ORDER); } } }
  • 31. Multitenant web applications Menubar generation Modularize!
  • 32. Multitenant web applications Menubar generation Module 1 Module 2 Module 3 register at start up Application core
  • 33. Multitenant web applications Menubar generation Module 1 Module 2 Module 3 register at start up Application core
  • 34. Multitenant web applications Menubar generation Module 1 Module 2 Module 3 register at start up Application core
  • 35. Multitenant web applications Optimize workflows
  • 36. Multitenant web applications Optimize workflows <?php if(CC == $paymentType) { // handle credit card payment } else if(COD == $paymentType) { // handle cash on delivery payment }
  • 37. Multitenant web applications Optimize workflows <?php if(CC == $paymentType) { // handle credit card payment for some tenants! if(in_array($tenant->getName(), array(tenant1, tenant2)) { // insert logic here... } } else if(COD == $paymentType) { // handle cash on delivery payment for some tenants! }
  • 38. Multitenant web applications Optimize workflows Decouple functionality!
  • 39. Multitenant web applications Optimize workflows <?php $paymentType = CC; // set via request $payment = PaymentFactory::create($paymentType); $payment->execute($order);
  • 40. Multitenant web applications Optimize workflows <?php $paymentType = CC; // set via request $payment = PaymentFactory::create($paymentType, $tenant); $payment->execute($order);
  • 41. Multitenant web applications Optimize workflows How to add custom logic?
  • 42. Multitenant web applications Custom logic - Subclassing? Abstract Payment CC Payment CCPayment CCPayment Tenant 1 Tenant 2
  • 43. Multitenant web applications Custom logic Any alternatives?
  • 44. Multitenant web applications Custom logic Let`s add hooks...
  • 45. Multitenant web applications Custom logic - Hooks <?php $paymentType = CC; // set via request $payment = PaymentFactory::create($paymentType, $tenant); $payment->execute($order); if($this->paymentPostProcessor instanceof IPaymentPostProcessor) { $this->paymentPostProcessor->run($payment, $tenant, $order); }
  • 46. Multitenant web applications Custom logic How to set the dependencies?
  • 47. Multitenant web applications Custom logic Dependency Injection!
  • 48. Multitenant web applications Custom logic – Dependency Injection <?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.bitexpert.de/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bitexpert.de/schema/ http://www.bitexpert.de/schema/bitFramework- beans.xsd"> <bean id="Service.Order" class="MyAppServiceOrder.php"> </bean> <bean id="Tenant1.Order" class="MyAppServiceOrder.php"> <property name="paymentPostProcessor" ref="Tentant1.Payment.SendOrderMail" /> </bean> </beans>
  • 49. Multitenant web applications Custom logic – Dependency Injection <?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.bitexpert.de/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bitexpert.de/schema/ http://www.bitexpert.de/schema/bitFramework- beans.xsd"> <bean id="Tenant2.Order" class="MyAppServiceOrder.php"> <property name="paymentPostProcessor" ref="Tentant1.Payment.PushToERP" /> </bean> </beans>
  • 50. Multitenant web applications Custom logic Any further improvements?
  • 51. Multitenant web applications Custom logic <?php $paymentType = CC; // set via request $payment = PaymentFactory::create($paymentType, $tenant); $payment->execute($order); if($this->paymentPostProcessor instanceof IPaymentPostProcessor) { $this->paymentPostProcessor->run($payment, $tenant, $order); }
  • 52. Multitenant web applications Custom logic <?php $paymentType = CC; // set via request $payment = PaymentFactory::create($paymentType, $tenant); $payment->execute($order); if($this->paymentPostProcessor instanceof IPaymentPostProcessor) { $this->paymentPostProcessor->run($payment, $tenant, $order); }
  • 53. Multitenant web applications Custom logic Aspect-oriented programming
  • 54. Multitenant web applications Custom logic – Aspects for the masses! /** * @aspect */ class CustomPaymentProcessingAspect { /** * @around MyAppServiceOrder->processPayment */ public function customFilter(JoinPointInterface $jP) { $result = $jP->getAdviceChain()->proceed($jP); // @TODO: implement post-processing logic return $result; } }
  • 55. Multitenant web applications Custom logic - Result <?php $paymentType = CC; // set via request $payment = PaymentFactory::create($paymentType, $tenant); $payment->execute($order);
  • 56. Multitenant web applications Next level...
  • 57. Multitenant web applications Database – Where to store the data?
  • 58. Multitenant web applications Database – Where to store the data? We need to store data for a tenant!
  • 59. Multitenant web applications Database – Where to store the data? Database per Tenant?
  • 60. Multitenant web applications Database – Where to store the data? Database per Tenant? Schema per Tenant?
  • 61. Multitenant web applications Database – Where to store the data? Database per Tenant? Schema per Tenant? Tenant Id per Row?
  • 62. Multitenant web applications Database – How to access the data? vs. ORM dynamic statements
  • 63. Multitenant web applications Generalize you should!
  • 64. Multitenant web applications No single solution!
  • 65. Multitenant web applications Softwaresystemfamily
  • 66. Multitenant web applications A factory for mass production!
  • 67. Multitenant web applications Multi Tenancy – Single Instance Tenant 1 Tenant 2 Tenant 3 Application Database Hardware
  • 68. Multitenant web applications Multi Tenancy – Multi Instance Tenant 1 Tenant 2 Tenant 3 Application Database Hardware
  • 69. Multitenant web applications Multi Tenancy – Multi Instance Generative Programming
  • 70. Multitenant web applications Generative Programming Generator Generator
  • 71. Multitenant web applications Generative Programming Configuration Configuration (DSL) (DSL) Generator Generator
  • 72. Multitenant web applications Generative Programming Configuration Configuration (DSL) (DSL) Implementation- Implementation- components Generator Generator components
  • 73. Multitenant web applications Generative Programming Configuration Configuration (DSL) (DSL) 1..n Implementation- Implementation- components Generator Generator Product components Product
  • 74. Multitenant web applications Generative Programming Configuration Configuration (DSL) (DSL) Implementation- Implementation- components Generator Generator Tenant 11 components Tenant
  • 75. Multitenant web applications Generative Programming Configuration Configuration (DSL) (DSL) Tenant 22 Tenant Implementation- Implementation- components Generator Generator Tenant 11 components Tenant
  • 76. Multitenant web applications Generative Programming Tenant 33 Tenant Configuration Configuration (DSL) (DSL) Tenant 22 Tenant Implementation- Implementation- components Generator Generator Tenant 11 components Tenant
  • 77. Multitenant web applications Generative Programming - Goal Create an optimized application!
  • 78. Multitenant web applications Generative Programming - Goal Create an optimized application for one tenant!
  • 79. Multitenant web applications Generative Programming – Bonus points
  • 80. Multitenant web applications Generative Programming – Bonus points Reduce application complexity
  • 81. Multitenant web applications Generative Programming – Bonus points <?php $paymentType = CC; // set via request $payment = PaymentFactory::create($paymentType, $tenant); $payment->execute($order); <!{PostProcessor}!>
  • 82. Multitenant web applications Generative Programming – Bonus points public class PostProcessorFrame extends SimpleFrameController { public void execute(Frame frame, FeatureConfig config) { if(config.hasFeature("order_send_mail")) { frame.setSlot("PostProcessor", "..."); } if(config.hasFeature("order_push_to_erp")) { frame.setSlot("PostProcessor", "..."); } } }
  • 83. Multitenant web applications Generative Programming – Bonus points Reduce maintenance support
  • 84. Multitenant web applications Generative Programming – Bonus points Implementation Feature component
  • 85. Multitenant web applications Generative Programming – Bonus points Feature Tenant
  • 86. Multitenant web applications Generative Programming – Bonus points Tenant Feature Implementation component
  • 87. Multitenant web applications Generative Programming – The book
  • 88. http://joind.in/3517
  • 89. Flickr Creditshttp://www.flickr.com/photos/andresrueda/3452940751/http://www.flickr.com/photos/andresrueda/3455410635/