# Microservices Patterns

> Microservices architecture patterns including service discovery, circuit breakers, event-driven architecture, API gateways, and distributed systems. Use when designing microservices, implementing inter-service communication, or managing distributed systems.

- **Type:** Skill
- **Install:** `agentstack add skill-jonathan0823-opencode-config-microservices-patterns`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [Jonathan0823](https://agentstack.voostack.com/s/jonathan0823)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [Jonathan0823](https://github.com/Jonathan0823)
- **Source:** https://github.com/Jonathan0823/opencode-config/tree/main/skills/microservices-patterns

## Install

```sh
agentstack add skill-jonathan0823-opencode-config-microservices-patterns
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Microservices Patterns Skill

## Overview

This skill provides comprehensive microservices architecture patterns including service discovery, circuit breakers, event-driven architecture, saga patterns, API gateways, and distributed data management.

## Quick Start

### Microservices Checklist

- [ ] Service boundaries clearly defined
- [ ] Database per service
- [ ] API Gateway for external communication
- [ ] Async messaging between services
- [ ] Circuit breakers for resilience
- [ ] Distributed tracing implemented
- [ ] Centralized logging
- [ ] Health checks and monitoring

### Communication Patterns

**Synchronous (REST/gRPC):**
- Simple request/response
- Tight coupling
- Blocking
- Use for: Queries, simple operations

**Asynchronous (Message Queue):**
- Event-driven
- Loose coupling
- Non-blocking
- Use for: Commands, long operations, event sourcing

## Core Patterns

### API Gateway

```yaml
# Kong Gateway configuration
services:
  - name: user-service
    url: http://user-service:8080
    routes:
      - name: user-routes
        paths:
          - /api/users
    plugins:
      - name: rate-limiting
        config:
          minute: 100
      - name: jwt
      - name: cors
```

### Circuit Breaker

```python
from circuitbreaker import circuit
import requests

@circuit(failure_threshold=5, recovery_timeout=30, expected_exception=requests.RequestException)
def call_external_service():
    response = requests.get('http://external-service/api')
    return response.json()

# Usage
try:
    result = call_external_service()
except circuitbreaker.CircuitBreakerError:
    # Circuit is open, use fallback
    result = fallback_data()
```

### Service Discovery

```yaml
# Consul service registration
service:
  name: order-service
  tags:
    - orders
    - v1
  port: 8080
  check:
    http: http://localhost:8080/health
    interval: 10s
```

### Saga Pattern

```python
# Choreography-based saga
class OrderSaga:
    def __init__(self, event_bus):
        self.event_bus = event_bus
    
    def start_order(self, order_data):
        # Step 1: Create order (pending)
        order = create_pending_order(order_data)
        
        # Step 2: Reserve inventory
        self.event_bus.publish('InventoryReservationRequested', {
            'order_id': order.id,
            'items': order.items
        })
    
    def on_inventory_reserved(self, event):
        # Step 3: Process payment
        self.event_bus.publish('PaymentRequested', {
            'order_id': event.order_id,
            'amount': event.total
        })
    
    def on_payment_completed(self, event):
        # Step 4: Complete order
        complete_order(event.order_id)
        self.event_bus.publish('OrderCompleted', {
            'order_id': event.order_id
        })
    
    def on_inventory_failed(self, event):
        # Compensate: Cancel order
        cancel_order(event.order_id)
```

## Detailed References

See comprehensive guides in references/:

- **[Service Communication](references/service-communication.md)** - REST, gRPC, GraphQL, message queues
- **[Resilience Patterns](references/resilience.md)** - Circuit breakers, retries, bulkhead, timeouts
- **[Event-Driven Architecture](references/event-driven.md)** - Event sourcing, CQRS, saga patterns
- **[Data Management](references/data-management.md)** - Database per service, distributed transactions, eventual consistency

## When to Use This Skill

Use this skill when:
- Decomposing monolith into microservices
- Designing service boundaries and APIs
- Implementing inter-service communication
- Managing distributed data consistency
- Building resilient service architectures
- Setting up service discovery and load balancing
- Implementing API gateways
- Handling distributed transactions

## Related Skills

- `@kubernetes-patterns` - Container orchestration for microservices
- `@docker-patterns` - Containerization
- `@api-rest-design` - API design for services
- `@observability-monitoring` - Distributed tracing and monitoring
- `@security-best-practices` - Service-to-service security
- `@performance-optimization` - Service performance

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [Jonathan0823](https://github.com/Jonathan0823)
- **Source:** [Jonathan0823/opencode-config](https://github.com/Jonathan0823/opencode-config)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** yes
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-jonathan0823-opencode-config-microservices-patterns
- Seller: https://agentstack.voostack.com/s/jonathan0823
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
