# Architecture: Microservices Expert

> **⚠️ Consolidado em `skills/architecture-patterns/SKILL.md`.** Este pack legado foi superado pelo formato novo (SKILL.md com frontmatter + Quando usar/Stack/Workflow/Regras de ouro/Checklist/Anti-padrões/Composição). Mantido por compatibilidade; para tarefas novas, use `skills/architecture-patterns/SKILL.md` como fonte primária.

> Version 1.0.0 | Priority: High
> Dependencies: Software Architect, DevOps Engineer, API Designer
> Compatibility: ">=1.0.0"

---

## Identity

Microservices Expert designs systems of independently deployable services communicating via APIs or events. Identifies bounded contexts (DDD), defines service contracts, and handles interservice communication, data consistency, and observability.

---

## When to Use

```yaml
use_microservices:
  - Multiple teams working independently
  - Different scaling requirements per domain
  - Polyglot persistence (different DBs per service)
  - Independent deployment cycles needed

prefer_monolith:
  - Single team < 5 developers
  - Simple CRUD application
  - Early-stage product (MVP)
  - No clear bounded context boundaries yet
```

---

## Key Patterns

```yaml
communication:
  sync: REST/gRPC for queries, command responses
  async: Events (RabbitMQ/Kafka) for commands, notifications

data:
  database_per_service: each service owns its data
  saga: distributed transaction (choreography or orchestration)
  CQRS: separate read/write models per service

deployment:
  containerized: Docker + Kubernetes
  per_service_pipeline: each service has its own CI/CD
  blue_green: zero-downtime deployments

observability:
  logging: structured JSON, correlation ID per request
  metrics: RED metrics (Rate, Errors, Duration) per service
  tracing: distributed tracing (OpenTelemetry + Jaeger)
```

---

## Service Template

```yaml
service:
  name: "user-service"
  language: "PHP / Laravel"
  database: "postgresql:16"
  communication: "REST (internal) + Events (RabbitMQ)"
  
  endpoints:
    - "POST /api/v1/users"
    - "GET /api/v1/users/{id}"
  
  events_publishes:
    - "user.created"
    - "user.updated"
  
  events_subscribes:
    - "order.completed → update user stats"
```

---

## Changelog

### 1.0.0 — Initial release. Patterns, when to use/avoid, template.
