agentleFS
G1JoshiG1Joshi/Agent-Skills/skills/architecture/microservices/SKILL.md

microservices

Skill15 starsChanged 42 days agoMITView on GitHub

Expert Microservices architecture assistance covering service decomposition, service discovery, distributed tracing, circuit breakers, and database-per-service isolation. Use when refactoring monoliths, designing distributed microservice systems, or orchestrating service communications.

8 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use api-design.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • MicrosoftSkill

    api-design

    Guide for designing and documenting RESTful APIs. Use when asked to design an API, create endpoints, or document an API.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 6 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use Contract Testing (Pact): Validate API compatibility between consumer and provider services in CI/CD without running end-to-end clusters.

    line 111
  2. Distinctive:

    Start with microservices on day one: Start with a well-structured Modular Monolith until organizational scale warrants extraction.

    line 116

“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Microservices

Microservices architecture structures an application as a collection of loosely coupled, independently deployable services. Ideally, each service corresponds to a Bounded Context (DDD).

When to Use

  • Independent Scaling & Deployment: Different business capabilities (e.g. video processing vs user authentication) require independent scaling.
  • Autonomous Multi-Team Velocity: Large engineering organizations where decoupled cross-functional teams need to deploy without stepping on each other.
  • Polyglot Technology Requirements: Leveraging specific runtimes for specific workloads (Python for ML, Go/Rust for networking, Node for APIs).
  • Fault Domain Isolation: Preventing an out-of-memory crash in a non-critical feature from bringing down the core payment pipeline.

Quick Start

# docker-compose.yml (Simulated Microservices)
services:
  order-service:
    build: ./services/order
    ports: ["3001:3000"]
    environment:
      - DB_HOST=order-db

  inventory-service:
    build: ./services/inventory
    ports: ["3002:3000"]

  api-gateway:
    image: nginx
    ports: ["80:80"]
    depends_on:
      - order-service
      - inventory-service

Core Concepts

Database-Per-Service Isolation

Each microservice owns its private database. No service can directly query another service's database tables:

[ Orders Service ] ──→ ( Orders DB )
        │ (Async Events / gRPC)
        ▼
[ Customers Service ] ──→ ( Customers DB )

Distributed Tracing (W3C Trace Context)

Correlates requests across multiple network hops using standardized trace IDs:

// Injected into outgoing HTTP/gRPC calls
headers: {
  "traceparent": "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
}

Circuit Breakers & Graceful Degradation

Fails fast when downstream services become unresponsive, preventing cascading thread exhaustion:

import CircuitBreaker from "opossum";

const breaker = new CircuitBreaker(callRecommendationService, {
  timeout: 1000,
  errorThresholdPercentage: 50,
  resetTimeout: 10000,
});

breaker.fallback(() => [/* Fallback cached generic recommendations */]);
const recommendations = await breaker.fire(userId);

Common Patterns

Circuit Breaker Pattern

Problem: Cascading failures when a downstream dependency experiences degraded response times.
Solution: Wrap external calls in a circuit breaker to fail fast and shed load.

import CircuitBreaker from "opossum";

async function fetchPaymentGateway(payload: PaymentPayload) {
  return await http.post("https://payment.example.com/charge", payload);
}

const breaker = new CircuitBreaker(fetchPaymentGateway, {
  timeout: 3000, // 3s timeout
  errorThresholdPercentage: 50, // Open breaker if 50% calls fail
  resetTimeout: 10000, // Wait 10s before attempting half-open state
});

breaker.fallback(() => ({ status: "QUEUED_FOR_RETRY", cached: true }));
const result = await breaker.fire(paymentData);

Best Practices

Do:

  • Enforce Database-per-Service: Never share a database instance between microservices; communicate via APIs or events.
  • Implement Comprehensive Observability: Instrument all services with OpenTelemetry traces, Prometheus metrics, and structured JSON logs.
  • Use Contract Testing (Pact): Validate API compatibility between consumer and provider services in CI/CD without running end-to-end clusters.
  • Adopt Service Meshes for Mesh Security: Leverage Envoy / Istio for automated mTLS encryption and traffic steering.

Don't:

  • Start with microservices on day one: Start with a well-structured Modular Monolith until organizational scale warrants extraction.
  • Build distributed monoliths: Avoid deep synchronous HTTP chains (Service A calls B, which calls C, which calls D).
  • Ignore distributed transactions: Use Saga patterns or eventual consistency rather than two-phase commits.

Troubleshooting

ErrorCauseSolution
Cascading FailureOne service down takes down others.Use Circuit Breakers and Timeouts.
Data inconsistencyAsync updates failed.Implement Sagas and Idempotent consumers.
LatencyToo many hops (service -> service -> service).Use Caching, Aggregation at Gateway, or Event-Driven data replication.

References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.