guh.me - gustavo's personal blog

Monolith To Microservices

These are my notes on the book Monolith to Microservices by Sam Newman.

Monolith to Microservices - Key Concepts

Chapter 1: Just Enough Microservices

Definition and Core Concepts

Architecture Principles

Summary

Chapter 2: Planning a Migration

Understanding the Goal

Three Key Questions

  1. What are you hoping to achieve? This should be aligned to what the business is trying to achieve, articulated as benefit to end users.
  2. Have you considered alternatives to using microservices? There are often many other ways to achieve the same benefits.
  3. How will you know if the transition is working? How will you know if you’re going in the right direction?

Why Choose Microservices?

Improve Team Autonomy

Reduce Time to Market

Scale Cost-Effectively for Load

Improve Robustness

Scale the Number of Developers

Embrace New Technology

When Microservices Might Be a Bad Idea

Unclear Domain

Customer-Installed and Managed Software

Not Having a Good Reason

Importance of Incremental Migration

Cost of Change

Domain Modeling

Event Storming

Measuring Success

Regular Checkpoints

Quantitative Measures

Qualitative Measures

Avoiding the Sunk Cost Fallacy

Being Open to New Approaches

Chapter 3: Splitting the Monolith

Incremental Migration

Pattern: Strangler Fig Application

Pattern: UI Composition

Pattern: Parallel Run

N-Version Programming

Pattern: Decorating Collaborator

Pattern: Change Data Capture

Chapter 4: Decomposing the Database

Pattern: The Shared Database

Coping Patterns

Pattern: Database View

Pattern: Database Wrapping Service

Pattern: Database-as-a-Service Interface

Transferring Ownership

Pattern: Aggregate Exposing Monolith

Data Synchronization

Pattern: Synchronize Data in Application

Pattern: Tracer Write

Approaches to resolve inconsistency:
  1. Write to one source: All writes go to one source of truth, then synchronize to the other
  2. Send writes to both sources: All write requests sent to both sources (either by client or intermediary)

Splitting Apart the Database

Physical vs. Logical Database Separation

Pattern: Split Table

Pattern: Move Foreign-Key Relationship to Code

Transactions

Saga Characteristics

Recovery approaches:
  1. Backward recovery: Reverting failures and cleaning up (rollback)
    • Requires defining compensating actions to undo previously committed transactions
  2. Forward recovery: Continuing from failure point
    • Requires ability to retry transactions
    • System must persist enough information to allow retry

Saga Implementation Patterns

  1. Orchestrated sagas:

    • Use central coordinator (orchestrator) to define execution order and trigger compensating actions
    • Command-and-control approach with good visibility into saga status
  2. Choreographed sagas:

    • Distribute responsibility among multiple collaborating services
    • “Trust-but-verify” architecture
    • Often use events for service collaboration
    • Events broadcast via message broker to interested services
    • Challenge: harder to understand what’s happening
    • Solution: Use correlation IDs to track saga state across events