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

Midwest PHP 2020 - Web Scale System Design and Architecture

Midwest PHP 2020 - Web Scale System Design and Architecture

Let's walk through different system designs and architecture decisions for building a large scale PHP application.

We'll cover SOLID, Application Architectures, Platform Architectures, and walk through an example of scaling a system.

Ben Edmunds

April 03, 2020
Tweet

More Decks by Ben Edmunds

Other Decks in Technology

Transcript

  1. Who is this guy? Ben Edmunds Open Source Author PHP

    Town Hall Podcast Staff Eng @ Wayfair
  2. Design Principles "what I mean by 'focusing one's attention upon

    some aspect': it does not mean ignoring the other aspects, it is just doing justice to the fact that from this aspect's point of view, the other is irrelevant. It is being one- and multiple-track minded simultaneously." - Edsger W. Dijkstra
  3. SRP interface User { public function getEmail(); } interface Post

    { public function setUserId(); public function save(); }
  4. SRP interface Order { public function getTotal(); public function getProducts();

    } interface OrderPdfReport { public function setOrder(Order $order); public function getPdf(); }
  5. Design Principles OPEN
 "A module will be said to be

    open if it is still available for extension. For example, it should be possible to add fields to the data structures it contains, or new elements to the set of functions it performs." CLOSED
 "A module will be said to be closed if [it] is available for use by other modules. This assumes that the module has been given a well-defined, stable description (the interface in the sense of information hiding)" - Bertrand Meyer
  6. OCP class ProcessWorker { public function process($job) { if ($job

    instanceof OrderPdfGeneratorJob) { $job->generatePdf(); } elseif ($job instanceof OrderGeoLocatorJob) { $job->locate(); }
  7. OCP interface Job { public function process(); } class OrderPdfGenerator

    implements Job { public function process(); } class OrderGeoLocator implements Job { public function process();
  8. Design Principles 
 "Let Φ(x) be a property provable about

    objects x of type T. Then Φ(y) should be true for objects y of type S where S is a subtype of T." - Barbara Liskov
  9. Design Principles 
 "Classes that have “fat” interfaces are classes

    whose interfaces are not cohesive." - Robert C. Martin
  10. ISP interface Job { public function process(); } class OrderPdfGenerator

    implements Job { public function process(); } class OrderGeoLocator implements Job { public function process();
  11. ISP interface Job { public function process(); public function getLatLong();

    } class OrderPdfGenerator implements Job { public function save(); uhOhhhh() }
  12. ISP interface Job { public function process(); } interface Geo

    { public function getLatLng(); } class OrderGeoLocator implements Job, Geo { public function process(); public function getLatLng(); }
  13. DIP class SuperUser {} $user = new SuperUser; class Post

    { function setUser(SuperUser $user); }
  14. DIP interface User {} class SuperUser implements User {} $user

    = new SuperUser; class Post { function setUser(User $user); }
  15. DIP interface User {} class SuperUser implements User {} class

    RegularUser implements User {} $user = new RegularUser; class Post { function setUser(User $user); }
  16. Platform Architectures "Almost all the successful microservice stories have started

    with a monolith that got too big and was broken up" 
 - Martin Fowler
  17. Pastebin Scale • Writes / second • Reads / second

    • Storage 1 x 86400 50 x 86400 86400x10kb = 864MB/day
  18. Pastebin Scale (864MB/day x 30) x 6 = 155 GB

    x 1.25 = 193GB 200GB for 6 months
  19. Pastebin ⚠ Scenario ⚠ • IDs becoming too long •

    Don't want users guessing other's URLs
  20. Pastebin ⚠ Next Steps ⚠ • More Caching • Load

    Balancing • Separate reads / writes • Reporting System
  21. Pastebin CLIENT API Obj R e q u e s

    t API DB DB DB Key Serv
  22. Pastebin CLIENT API Obj R e q u e s

    t API DB DB DB Key Serv Iteration =
  23. Q/A