# Microservices Patterns

> Microservices Architecture Patterns

- Skill: `j4flmao/microservices-patterns` (Agent Skill)
- Install (CLI): `npx skillmds@latest add j4flmao/microservices-patterns`
- Raw SKILL.md: https://api.skillmd.com/api/skills/j4flmao/microservices-patterns/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: j4flmao (https://skillmd.com/u/j4flmao)
- Updated: 2026-09-21
- Page: https://skillmd.com/skills/j4flmao/microservices-patterns

---

# Microservices Architecture Patterns

## Core Design Patterns

Designing resilient microservices requires managing distributed state, failures, and complex communication networks.

### 1. The Saga Pattern (Distributed Transactions)
In a microservices world, you cannot use ACID database transactions across multiple services. Instead, use Sagas.
- **Choreography:** Services publish events when they complete their local transaction. Other services listen and react.
- **Orchestration:** A central "Saga Orchestrator" commands services to execute local transactions and coordinates rollbacks (compensating transactions) if any step fails.

### 2. Circuit Breaker Pattern
If a downstream service is struggling, hitting it repeatedly will cause a cascading failure. A Circuit Breaker detects failures and "trips" (opens) to block requests, returning a fast fallback error until the service recovers.

### Saga Orchestration Map

```mermaid
%%{init: {"theme": "default", "flowchart": {"useMaxWidth": true}}}%%
flowchart TD
    subgraph Client ["Frontend"]
        A["Checkout Request"]
    end
    
    subgraph Orchestrator ["Order Saga Orchestrator"]
        B["Start Saga"]
        C["Compensating Action (Rollback)"]
    end
    
    subgraph Services ["Microservices"]
        D["Inventory Service (Deduct)"]
        E["Payment Service (Charge)"]
        F["Shipping Service (Schedule)"]
    end
    
    A --> B
    B -->|"1. Command"| D
    D -->|"Success"| B
    B -->|"2. Command"| E
    E -.->|"Failed (Insufficient Funds)"| B
    B -->|"3. Compensating Command"| C
    C -->|"Restore Inventory"| D
```

