Modular Monolith

Balancing Simplicity, Flexibility, and Scalability



@kemalelmizan
IDSW.dev
17 Nov 2024

Microservices - KRAZAM
Microservices - KRAZAM

>The software industry is learning once again that complexity kills

Death by 1000 Microservices
- Andrei Taranchenko

What Comes After Microservices? - Matt Ranney
What Comes After Microservices? - Matt Ranney What Comes After Microservices? - Matt Ranney
What Comes After Microservices? - Matt Ranney

a microservice

  • small
  • focused on one task
  • bounded context
  • autonomous
  • independently deployable
  • loosely coupled

Continuous Delivery - Dave Farley

> At the heart of microservices, we find ...
modules.

You want Modules, not Microservices
- Neward and Associates

Modules or Objects?

Model modules, components, connectors, ports, component assemblies, styles, invariants, responsibility allocations, design decisions, rationales, protocols, quality attributes, and models (e.g., security policies, concurrency models)
Code packages, classes, methods, variables, functions, procedures, statements

Just Enough Software Architecture: Model-code gap
- George Fairbanks

distributed system

collection of independent components, located on networked systems, that communicate and coordinate their actions by passing messages to achieve a common objective

Resiliency in Distributed Systems 1 - Rajeev B
Resiliency in Distributed Systems - Rajeev Bharshetty
Resiliency in Distributed Systems 2 - Rajeev B
Resiliency in Distributed Systems 2 - Rajeev B
Service-level Fault Injection Testing - Christopher Meiklejohn

Service-level Fault Injection Testing, ACM SoCC 2021
- Christopher Meiklejohn

> socio-technical challenges

Resilient Microservice Applications, by Design, and without the Chaos - Christopher Meiklejohn

Misconceptions about Microservices

  • Solution to all Scaling Issues
  • Believing Microservices will Simplify the Codebase
  • Shortcut to Address Legacy Code Issues

Reasons not to do Microservices

  • Avoiding Team Collaboration and Communication
  • Desire for Autonomy; Silo Work and Limit Scrutiny
  • Over-Focus on Service-Level Implementation Details
  • Isolating Technical Debt Instead of Fixing It

you're not creating microservices,
you're creating a distributed monolith

Monolith vs Microservices by Simon Brown

Monolith vs Microservices - Simon Brown

Modular Monolith vs Microservices
- Milan Jovanović

n+1 query problem

  • Occurs when you fetch a parent entity and then need to fetch its child entities separately
  • Results in 1 query for the parent + N queries for N children
N+1 Query Problem

N+1 Queries - Sentry

N+1 Query Resolved

Scenario: e-commerce platform with these services

  • UserService: Manages user profiles and account data.
  • OrderService: Stores all order information, including items ordered, status, and user association.
  • ProductService: Contains product details, such as price, availability, and descriptions.
  • InventoryService: Tracks product stock levels across multiple warehouses.

want to create a reporting tool that gathers these data:

  • User's profile information
  • Each order the user has placed
  • Details of the products in each order
  • Inventory status for each product

in most monolith systems...


SELECT u.*, o.*, p.*, i.*
FROM Users u
JOIN Orders o ON u.UserId = o.UserId
JOIN OrderItems oi ON o.OrderId = oi.OrderId
JOIN Products p ON oi.ProductId = p.ProductId
JOIN Inventory i ON p.ProductId = i.ProductId;
					

... make sure to use indexes and query to replica DB for optimization

unoptimized solution in microservices:

  • 1: Retrieve users from UserService
  • 2: Retrieve orders from OrderService associated with their UserId
  • 3: Retrieve products from ProductService using the ProductId list in the order
  • 4: Check inventory from InventoryService using the product's ID to get current stock levels.

Microservice Optimization Options

  • create a service acting as aggregation layer
  • create a service for data duplication acting as caching layer
  • use event driven architecture!

Inside Event-Driven Architectures - David Boyne

Data infrastructure at Gojek - Ravi Suhag

Modular Monolith in Practice

Modular Monolith Architecture
- Milan Jovanović

Communication Patterns

Data Isolation

Modular Monolith Balances:

  • Simplicity for Maintainability
  • Flexibility without Fragmentation
  • Quick Iteration and Gradual Scaling

Real life Monolithic Software Architectures

Stack Overflow Shopify WhatsApp
Torvalds first Linux Announcement

First Linux Announcement - Torvalds

Tanenbaum-Torvalds Debate

LINUX is obsolete - AST

Monolithic vs. Microkernel

Monolithic vs. Microkernel

Loadable Kernel Module

  • an object file that contains code to extend the running kernel of an operating system
    • kernel loadable module (kld) in FreeBSD
    • kernel extension (kext) in macOS
    • kernel-mode driver in Windows NT
    • kernel extension module in AIX
    • dynamically loadable kernel module in HP-UX
  • located in /lib/modules or /usr/lib/modules and have had the extension .ko ("kernel object")
  • Enables Rust for Linux

> Linux is the largest software development project on the planet
- Greg Kroah-Hartman

4,000 developers and at least 440 different companies contribution

The Battle: Why Linux Won

  • Performance and Overhead
  • Simplicity and Ease of Development
  • User and Developer Adoption
  • Scalability

The Lesson for Modern Software Architecture: When Monolithic Wins

In a similar way to Linux, modern monolithic applications are often chosen when:

  • Low Latency and High Performance are Essential
  • Simplicity and Development Speed Matter
  • Developer Coordination is Key
  • Scalability at the Organizational Level is not Needed

> Keep things as simple as possible,
for as long as possible

Microservices vs. Monolith
- David Heinemeier Hansson

Thank you IDSW 2024!

This deck is available online at http://kemal.elmizan.com/modular-monolith

QR Code