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

Moduliths

Dimitri
October 21, 2022

 Moduliths

Tech talk about Spring Boot Moduliths, given for Optis

Dimitri

October 21, 2022
Tweet

More Decks by Dimitri

Other Decks in Programming

Transcript

  1. Notification Microservice Prescription Microservice Schedule Microservice Medication Microservice User Microservice

    Inventory Microservice Until one day, the Architect Wizard™ arrived, and transformed it into microservices…. User Inventory Medication Schedule Notification Prescription Mediminder gateway Event bus
  2. Notification Microservice Prescription Microservice Schedule Microservice Medication Microservice User Microservice

    Inventory Microservice Peace returned, until one day a microservice caught fire… User Inventory Medication Schedule Notification Prescription Mediminder gateway Event bus ❌ ❌
  3. Notification Microservice Prescription Microservice Schedule Microservice Medication Microservice User Microservice

    Inventory Microservice The fire spread… User Inventory Medication Schedule Notification Prescription Mediminder gateway Event bus ❌ ❌ ❌ ❌ ❌ ❌ ❌ ❌
  4. Notification Microservice Prescription Microservice Schedule Microservice Medication Microservice User Microservice

    Inventory Microservice The DevOps Heroes™ quickly restarted the microservice… User Inventory Medication Schedule Notification Prescription Mediminder gateway Event bus
  5. Notification Microservice Prescription Microservice Schedule Microservice Medication Microservice User Microservice

    Inventory Microservice And added extra infrastructure to prevent future problems User Inventory Medication Schedule Notification Prescription Mediminder gateway Event bus
  6. What did we learn? • High coupling is evil •

    Microservices can help • Extra resources • Extra code • Less focus on business code
  7. Spring Data Events? @Entity // Extend from AbstractAggregateRoot public class

    Schedule extends AbstractAggregateRoot<Schedule> { @OneToMany private List<CompletedEvent> completedEvents; public void addCompletedEvent(LocalDate eventDate) { this.completedEvents.add(CompletedEvent.of(this, eventDate)); // Call registerEvent() registerEvent(MedicationTakenEvent.of(this, eventDate)); } }
  8. Spring Data Events? @Component @RequiredArgsConstructor public class MedicationTakenEventListener { private

    final InventoryFacade facade; @TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT) public void subtractFromInventory(MedicationTakenEvent event) { facade.removeQuantity(event.userId(), event.medicationId(), event.quantity()); } }
  9. Structure your code… 2. Put exposed classes in a module

    package 1. Create a new package for each module
  10. Structure your code… 3. Put implementation details in a subpackage

    2. Put exposed classes in a module package 1. Create a new package for each module
  11. Pro’s & Con’s • Developed by Spring Data lead •

    Favours conventions over configuration • Easy integration with Spring Boot • Only bootstraps module during tests • Small community • Does not replace microservices