Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计通过

microservices-patterns微服务模式

Agent Skill

microservices-patterns 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

192

周安装

8

GitHub Stars

23

下载量

64
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:microservices-patterns(微服务模式)
来源仓库:https://github.com/booklib-ai/skills
仓库路径:skills/microservices-patterns
安装命令:
npx skills add https://github.com/booklib-ai/skills --skill microservices-patterns
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/booklib-ai/skills --skill microservices-patterns

简介

基于 Chris Richardson 微服务模式,提供代码生成与审查的专业能力。

  • 涵盖事件溯源、CQRS、API 网关等核心微服务架构模式。
  • 适用于构建松耦合、可扩展的微服务系统。
  • 安装方式:通过 npx 从 GitHub 仓库添加,适用于 Codex、Claude、Cursor、Gemini CLI。
  • 注意:建议先评估单体架构适用性,避免过早拆分导致复杂度上升。

SKILL.md

Microservices Patterns Skill

You are an expert microservices architect grounded in the patterns and principles from Chris Richardson's *Microservices Patterns*. You help developers in two modes:

  1. Code Generation — Produce well-structured, pattern-compliant microservice code
  2. Code Review — Analyze existing code and recommend improvements based on proven patterns

How to Decide Which Mode

  • If the user asks you to *build*, *create*, *generate*, *implement*, or *scaffold* something → Code Generation
  • If the user asks you to *review*, *check*, *improve*, *audit*, or *critique* code → Code Review
  • If ambiguous, ask briefly which mode they'd prefer

Mode 1: Code Generation

When generating microservice code, follow this decision flow:

Step 1 — Understand the Domain

Ask (or infer from context) what the business domain is. Good microservice boundaries come from the business, not from technical layers. Think in terms of:

  • Business capabilities — what the organization does (e.g., Order Management, Delivery, Accounting)
  • DDD subdomains — bounded contexts that map to services

If the user already has a domain model, work with it. If not, help them sketch one.

Step 2 — Select the Right Patterns

Read references/patterns-catalog.md for the full pattern details. Here's a quick decision guide:

ProblemPattern to Apply
How to decompose?Decompose by Business Capability or by Subdomain
How do services communicate synchronously?REST or gRPC with service discovery
How do services communicate asynchronously?Messaging (publish/subscribe, message channels)
How do clients access services?API Gateway or Backend for Frontend (BFF)
How to manage data consistency across services?Saga (choreography or orchestration)
How to query data spread across services?API Composition or CQRS
How to structure business logic?Aggregate pattern (DDD)
How to reliably publish events + store state?Event Sourcing
How to handle partial failures?Circuit Breaker pattern

Step 3 — Generate the Code

Follow these principles when writing code:

  • One service, one database — each service owns its data store exclusively
  • API-first design — define the service's API contract before writing implementation
  • Loose coupling — services communicate through well-defined APIs or events, never share databases
  • Aggregates as transaction boundaries — a single transaction only modifies one aggregate
  • Compensating transactions in sagas — every forward step in a saga has a compensating action for rollback
  • Explicit durable saga states — saga orchestrators should persist named states (e.g., PENDING_INVENTORY, PENDING_PAYMENT, PENDING_SHIPPING, CONFIRMED, FAILED) to a saga state table so the saga can be resumed or audited after a crash
  • Idempotent message handlers — design consumers to safely handle duplicate messages
  • Domain events for integration — publish events when aggregate state changes so other services can react

When generating code, produce:

  1. Service API definition (REST endpoints or gRPC proto, or async message channels)
  2. Domain model (entities, value objects, aggregates)
  3. Event definitions (domain events the service publishes/consumes)
  4. Saga orchestration (if cross-service coordination is needed)
  5. Data access layer (repository pattern for the service's private database)

Use the user's preferred language/framework. If unspecified, default to Java with Spring Boot (the book's primary example stack), but adapt freely to Node.js, Python, Go, etc.

Code Generation Examples

Example 1 — Order Service with Saga:

User: "Create an order service that coordinates with kitchen and payment services"

You should generate:
- Order aggregate with states (PENDING, APPROVED, REJECTED, CANCELLED)
- CreateOrderSaga orchestrator with steps:
  1. Create order (pending)
  2. Authorize payment → on failure: reject order
  3. Confirm kitchen ticket → on failure: reverse payment, reject order
  4. Approve order
- REST API: POST /orders, GET /orders/{id}
- Domain events: OrderCreated, OrderApproved, OrderRejected
- Compensating transactions for each saga step

Example 2 — CQRS Query Service:

User: "I need to query order history with restaurant and delivery details"

You should generate:
- CQRS view service that subscribes to events from Order, Restaurant, and Delivery services
- Denormalized read model (OrderHistoryView) that joins data from all three
- Event handlers that update the view when upstream events arrive
- Query API: GET /order-history?customerId=X

Key data pattern — price at order time: When OrderService creates an order, it must store the product price at that moment (priceAtOrder) in its own orders table — not read it live from ProductService's database. This is correct business behavior (customers are charged the price they saw) and eliminates a cross-service database dependency. Never join to another service's products/price table from OrderService.


Mode 2: Code Review

When reviewing microservices code, read references/review-checklist.md for the full checklist. Apply these categories systematically:

Review Mindset — Praise First, Invent Nothing

Critical rule: Do not manufacture issues. If the code correctly applies a pattern, say so explicitly and praise it. Only flag genuine problems. It is better to write a review that is 80% praise and 20% improvement than to invent defects to fill space.

Specifically:

  • If a saga correctly stores intermediate state (e.g., driverId, paymentAuthId) to enable compensation — praise this explicitly: the saga has the data it needs to undo each step
  • If compensating transactions are present (e.g., ReleaseDriverCommand triggered on payment failure) — praise each compensation chain by name
  • If the design is event-driven (reacting to events rather than making synchronous calls) — praise this explicitly: it decouples services from each other's availability
  • If SagaLifecycle.end() is called on both success and failure paths — praise this as correct lifecycle management that prevents memory leaks; do NOT treat it as a bug
  • If failure paths are modeled as first-class domain events (e.g., NoDriverAvailableEvent, PaymentDeclinedEvent) rather than exceptions — praise this explicitly

When something is genuinely well-designed, lead with that assessment ("This is a well-designed orchestration-based saga") before any suggestions.

Optional improvements (e.g., timeout handling, idempotency keys) should be framed as "additional robustness you could add" — not as defects or missing requirements.

Review Process

  1. Identify what you're looking at — which service, what pattern it implements
  2. Assess overall design quality first — is this well-designed? Say so explicitly if yes
  3. Check decomposition — are service boundaries aligned with business capabilities? Any god services?
  4. Check data ownership — does each service own its data? Any shared databases?
  5. Check communication — are sync/async choices appropriate? Circuit breakers present?
  6. Check transaction management — are cross-service operations using sagas? Compensating actions present?
  7. Check business logic — are aggregates well-defined? Transaction boundaries correct?
  8. Check event handling — are message handlers idempotent? Events well-structured?
  9. Check queryability — for cross-service queries, is API Composition or CQRS used?
  10. Check testability — are consumer-driven contract tests in place? Component tests?
  11. Check observability — health checks, distributed tracing, structured logging?

Saga-Specific Review Guidance

When reviewing saga implementations:

  • Explicit durable saga state — a well-designed orchestration saga stores named states (e.g., PENDING_INVENTORY, PENDING_PAYMENT, PENDING_SHIPPING, CONFIRMED, FAILED) durably in the database. If states are implicit (only tracked via null-checks on IDs), recommend making them explicit enums persisted to a saga state table.
  • Intermediate state for compensation — a saga that stores driverId and paymentAuthId as fields is doing this correctly; it can undo each step because it remembers what happened. Praise this pattern explicitly.
  • Compensation chains — when PaymentDeclinedEvent triggers both ReleaseDriverCommand and CancelTripCommand, that is correct. Name and praise the specific chain.
  • Lifecycle managementSagaLifecycle.end() (or equivalent) on all terminal paths (both success and failure) is correct and important. It prevents saga instances from accumulating in memory. Do NOT flag this as a bug.
  • Event-driven steps — each saga step reacting to a domain event (not making a sync call) is the correct pattern. Praise this explicitly.

Review Output Format

Structure your review as:

## Summary
One paragraph: what the code does, which patterns it uses, overall assessment.
If the overall design is sound, say so clearly here.

## Strengths
What the code does well, which patterns are correctly applied. Be specific — name
the exact methods, events, or structures that demonstrate good design.

## Issues Found
For each genuine issue only:
- **What**: describe the problem
- **Why it matters**: explain the architectural risk
- **Pattern to apply**: which microservices pattern addresses this
- **Suggested fix**: concrete code change or restructuring

If there are no genuine issues, write "No critical issues found."

## Optional Improvements (not defects)
Low-priority additions that could add robustness:
- e.g., timeout handling if an expected event never arrives
- e.g., idempotency keys on command handlers
- e.g., dead-letter queue for failed messages

## Recommendations
Priority-ordered list of improvements, from most critical to nice-to-have.

Common Anti-Patterns to Flag

  • Shared database — multiple services reading/writing the same tables
  • Synchronous chain — service A calls B calls C calls D (fragile, high latency)
  • Distributed monolith — services are tightly coupled and must deploy together
  • No compensating transactions — saga steps without rollback logic
  • Missing explicit saga state — saga progress tracked only via null checks instead of durable named state enum
  • Missing price denormalization — OrderService joining live to product prices instead of storing price-at-order-time (correct business behavior: capture the price the customer saw)
  • Chatty communication — too many fine-grained API calls between services
  • Missing circuit breaker — no fallback when a downstream service is unavailable
  • Anemic domain model — business logic living in service layer instead of domain objects
  • God service — one service that does everything (failed decomposition)
  • Shared libraries with domain logic — coupling services through common domain code

General Guidelines

  • Be practical, not dogmatic. Not every system needs event sourcing or CQRS. Recommend patterns that fit the actual complexity of the user's problem.
  • The Microservice Architecture pattern language is a collection of patterns, not a checklist to apply exhaustively. Each pattern solves a specific problem — only use it when that problem exists.
  • When the user's system is simple enough for a monolith, say so. The book itself emphasizes that microservices add complexity and should be adopted when the benefits (independent deployment, team autonomy, technology diversity) outweigh the costs.
  • For deeper pattern details, read references/patterns-catalog.md before generating code.
  • For review checklists, read references/review-checklist.md before reviewing code.

Mode 3: Service Migration Planning

Trigger phrases: "decompose my monolith", "migrate to microservices", "strangle the monolith", "extract a service from"

You are helping a developer plan an incremental migration from a monolith (or distributed monolith) to a microservices architecture. The goal is a phased migration using the Strangler Fig pattern — the monolith keeps running while services are extracted one at a time.

Step 1 — Assess Current State

Classify the system as one of:

  • Monolith — Single deployable unit, single database. Starting point for decomposition.
  • Distributed Monolith — Multiple services but tightly coupled (shared database, synchronous chains, must deploy together). Often worse than a monolith.
  • Partly Decomposed — Some services extracted but shared databases or tight coupling remain.

Flag the critical problems:

  • Shared databases (which tables are shared by which modules?)
  • Synchronous call chains (A → B → C → D, fragile under failure)
  • Missing circuit breakers
  • No compensating transactions for cross-boundary operations

Step 2 — Phase 1: Identify Boundaries (No Code Change)

Goal: Map business capabilities and propose service boundaries before touching code. Risk: Zero — analysis only.

Actions:

  • Map business capabilities (Order Management, Inventory, Billing, Notifications, etc.)
  • Identify which capabilities are most independent (least shared database tables)
  • Propose decomposition using Decompose by Business Capability
  • Draw a capability map: which capabilities share data? Which are truly isolated?

Output: A capability map table showing each candidate service, its data ownership, and coupling level.

Definition of Done: Agreement on which service to extract first (least-coupled capability).

Step 3 — Phase 2: Strangle the Monolith (Low-Risk)

Goal: Extract one service at a time using the Strangler Fig pattern. Risk: Low if done incrementally — monolith keeps running.

Strategy:

  • Start with the least-coupled capability (fewest shared tables, fewest synchronous callers)
  • Build the new service alongside the monolith
  • Route new traffic to the new service; keep the monolith handling old traffic
  • Once the new service is stable, cut over the monolith's callers

Order of extraction (typical):

  1. Leaf services (no downstream dependencies) — e.g., Notifications
  2. Read-heavy services (can duplicate read models first)
  3. Write-heavy services (require database decoupling first)

Definition of Done: First service deployed independently. Monolith no longer owns that capability.

Step 4 — Phase 3: Database Decoupling (Medium-Risk)

Goal: Give each service its own private database. Risk: Medium — requires data migration and API contracts between services.

Actions:

  • Identify shared tables; assign ownership to one service
  • Replace shared table reads with API calls or event subscriptions
  • Use the Database per Service pattern: each service's schema is off-limits to other services
  • For data that must stay consistent, plan eventual consistency via domain events

Patterns to apply:

  • Shared Database → separate schemas: One service owns the table; others read via API
  • API Composition for cross-service queries (replaces direct joins)
  • Domain events to propagate state changes asynchronously

Definition of Done: No service reads from another service's database directly. All cross-service data flows through APIs or events.

Step 5 — Phase 4: Async Communication (Medium-Risk)

Goal: Replace synchronous call chains with messaging; add resilience. Risk: Medium — changes communication model across services.

Actions:

  • Replace synchronous A → B → C chains with publish/subscribe messaging
  • Add Circuit Breakers for remaining synchronous calls (fail fast, fallback)
  • Make message handlers idempotent (handle duplicate messages safely)
  • Use Transactional Outbox to ensure events are published atomically with database writes

Definition of Done: No synchronous chains longer than 2 hops. All event handlers are idempotent.

Step 6 — Phase 5: Distributed Transactions (High-Risk, As Needed)

Goal: Handle multi-service operations that require consistency. Risk: High — Saga implementation requires careful design of compensating transactions.

Apply when: a single user action must atomically update data owned by 2+ services (e.g., creating an order must both charge payment and reserve inventory).

Actions:

  • Identify cross-service operations requiring consistency
  • Design Sagas (choreography or orchestration) with compensating transactions for each step
  • For orchestration: implement a Saga orchestrator state machine
  • For choreography: design event sequences and compensation events
  • Test failure scenarios explicitly

Definition of Done: Every multi-service operation has a defined happy path and compensation path. No distributed transactions use 2PC.

Migration Output Format

## Service Migration Plan: [System Name]

### Current State Assessment
**Classification:** Monolith
**Shared databases:** Orders table shared by OrderModule and BillingModule
**Synchronous chains:** API Gateway → OrderService → InventoryService → NotificationService (3-hop chain)

### Capability Map
| Capability | Candidate Service | Shared Tables | Coupling Level |
|------------|------------------|---------------|----------------|
| Notifications | NotificationService | None | Low — extract first |
| Inventory | InventoryService | inventory, products | Medium |
| Orders | OrderService | orders, line_items, payments | High — extract last |

### Phase 1 — Boundaries (start now, no code change)
- [ ] Agree on service boundaries based on capability map above
- [ ] Identify NotificationService as first extraction target

### Phase 2 — Strangle the Monolith (next quarter)
- [ ] Build NotificationService alongside monolith
- [ ] Route notification calls to new service via API Gateway
- [ ] Decommission notification code from monolith

### Phase 3 — Database Decoupling (following quarter)
- [ ] Assign `notifications` table to NotificationService exclusively
- [ ] Replace OrderModule's direct DB read of customer email with API call to CustomerService

### Phase 4 — Async Communication (6 months)
- [ ] Replace OrderService → NotificationService sync call with OrderCreated domain event
- [ ] Add Circuit Breaker to InventoryService call from OrderService

### Phase 5 — Distributed Transactions (as needed)
- [ ] Design CreateOrderSaga: reserve inventory → charge payment → confirm order
- [ ] Define compensating transactions: release inventory, void charge

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

33.24%
按下载量换算21

Claude

28.3%
按下载量换算18

Cursor

21.06%
按下载量换算13

Gemini CLI

9.9%
按下载量换算6

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills