Slide 1

Slide 1 text

MUHAMMAD ZESHAN KHATTAK https://pinkary.com/@zeshan77

Slide 2

Slide 2 text

Modularising the Monolith LaravelLive Pakistan 2024

Slide 3

Slide 3 text

SHIP THE PRODUCT TO THE MARKET

Slide 4

Slide 4 text

BENEFITS OF MONOLITH • Single repository • Single CI/CD pipeline • Single set of infrastructure • Easy to handle DB transactions

Slide 5

Slide 5 text

BIG BALL OF MUD • Tight coupling between functionalities • No domain boundaries • All code is globally accessible • Need to understand the entire codebase

Slide 6

Slide 6 text

MICROSERVICES User Interface Microservice Microservice Microservice HTTP HTTP

Slide 7

Slide 7 text

BENEFITS OF MICROSERVICES • Clear boundaries between services • Deployed independently • Can be scaled independently • Freedom of tech stack

Slide 8

Slide 8 text

CHALLENGES OF MICROSERVICES • Multiple repositories • Multiple CI/CD pipelines • Network overhead • Complex cross-service transactions

Slide 9

Slide 9 text

TECHNICAL DECISIONS ARE ALWAYS TRADE-OFF

Slide 10

Slide 10 text

OUR GOALS • Maximise teams’ productivity • Scalable architecture

Slide 11

Slide 11 text

OUR APPROACH • Modularise the monolith • De f ine domain boundaries

Slide 12

Slide 12 text

MODULAR MONOLITH Contracts Implementation Tests Contracts Implementation Tests Contracts Implementation Tests Inventory module Order module Payment module

Slide 13

Slide 13 text

INCREMENTAL MIGRATION MICROSERVICES Contracts Implementation Tests Contracts Implementation Tests Contracts Implementation Tests Inventory service Order module Payment module

Slide 14

Slide 14 text

MICROSERVICES ARE EXPENSIVE TO CHANGE User Interface Microservice Microservice Microservice HTTP HTTP

Slide 15

Slide 15 text

MODULAR MONOLITH IS EASIER TO CHANGE Contracts Implementation Tests Contracts Implementation Tests Contracts Implementation Tests Inventory module Order module Payment module

Slide 16

Slide 16 text

MODULES & TEAM STRUCTURE Inventory Module Order Module Payment Module Shipping Module Auth Module

Slide 17

Slide 17 text

DEFAULT STRUCTURE

Slide 18

Slide 18 text

MODULAR STRUCTURE

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

COMMUNICATION BETWEEN MODULE

Slide 21

Slide 21 text

COMMUNICATION THROUGH CONTRACT Module A Module B Downstream Upstream Contract Implementation

Slide 22

Slide 22 text

CROSS-MODULE FOREIGN KEY LEADS TO A TIGHT COUPLING Order module Inventory module Products Cart Items product_id id

Slide 23

Slide 23 text

HOW CAN WE ENFORCE DOMAIN BOUNDARIES?

Slide 24

Slide 24 text

STATIC ANALYSIS • Deptrac • De f ine layers based on PHP classes • De f ine rulesets on layers access • Detect violation of the rulesets • Visualize dependency graph

Slide 25

Slide 25 text

THANK YOU https://pinkary.com/@zeshan77