system-microservices-design
Master engineering blueprint for designing, decomposing, orchestrating, and scaling resilient, high-throughput enterprise microservices systems. Synthesizes foundational theories of Martin Fowler (Domain-Driven Design), Sam Newman (Independent Deployability & Smart Endpoints), Chris Richardson (Transactional Outbox, Saga, CQRS), and Alex Xu (High-Scale 5-Tier Topology, Circuit Breakers, Global Observability) to coordinate thousands of sub-atomic microservices into an unbreakable distributed enterprise application.
- License 许可
- MIT
- 最近更新
- 2026-11-11
- Stars
- ★ 3
- Forks
- 0
01 前言 Front Matter
- name
- system-microservices-design
- tags
- [ "microservices", "system-design", "enterprise-architecture", "domain-driven-design", "saga-pattern", "transactional-outbox", "service-mesh", "circuit-breaker", "event-driven", "alex-xu", "martin-fowler", "sam-newman", "chris-richardson" ]
- author
- Antigravity Engineering Core
- version
- 1.0.0
- description
- Master engineering blueprint for designing, decomposing, orchestrating, and scaling resilient, high-throughput enterprise microservices systems. Synthesizes foundational theories of Martin Fowler (Domain-Driven Design), Sam Newman (Independent Deployability & Smart Endpoints), Chris Richardson (Transactional Outbox, Saga, CQRS), and Alex Xu (High-Scale 5-Tier Topology, Circuit Breakers, Global Observability) to coordinate thousands of sub-atomic microservices into an unbreakable distributed enterprise application.
- trigger_patterns
- [ "enterprise system design", "microservices architecture", "distributed system design", "saga pattern", "outbox pattern", "high scale backend", "service mesh design", "bounded context", "microservice decomposition" ]
03 SKILL.md 正文
Enterprise Microservices System Design & Orchestration Methodology
"A monolith fails when its code is tangled; a microservices system fails when its boundaries, transactions, and network boundaries are assumed rather than mathematically enforced. Macro-architecture governs the space between services."
1. Scope, Philosophy & Architecture Hierarchy
This skill provides the Distributed Inter-Service Blueprint for orchestrating distributed microservices and decomposed out-of-process services into a cohesive, fault-tolerant, high-throughput enterprise application.
The 3-Tier Systems Engineering Suite:
graph LR
subgraph Macro["Tier 1: Global Architecture"]
A["system-architecture-design"]
end
subgraph Distributed["Tier 2: Inter-Service Mesh (This Skill)"]
E["system-microservices-design"]
E --> M1["DDD Bounded Contexts (Fowler)"]
E --> M2["Smart Endpoints & Contracts (Newman)"]
E --> M3["Saga & Outbox CDC (Richardson)"]
E --> M4["5-Tier Topology & Resilience (Alex Xu)"]
end
subgraph Micro["Tier 3: Sub-Atomic Layer (Internal)"]
L["system-lifecycle-designer"]
L --> P1["Reconciliation (3-Way Diff)"]
L --> P2["Sticky Leases & Invariant State"]
L --> P3["Atomic Swap & Graceful Drain"]
end
Macro ==> Distributed ==> Micro
system-architecture-design(Tier 1 - The Blueprint): Governs global capacity planning, modular monolith boundaries, and selective service decomposition.system-microservices-design(Tier 2 - The Inter-Service Fabric): Governs inter-service data consistency, Saga transactions, service meshes, circuit breaking, and contract enforcement across out-of-process services.system-lifecycle-designer(Tier 3 - The Brick): Ensures every individual service, worker, daemon, or pool is internally deterministic, crash-safe, and self-healing.
2. Foundational Pillars of the Four Masters
Every enterprise microservice architecture governed by this skill must adhere to the unified principles established by the four pioneers of distributed systems:
quadrantChart
title Enterprise Architectural Pillars
x-axis "Loose Coupling (Autonomy)" --> "Strict Invariants (Correctness)"
y-axis "Data Consistency & Transactions" --> "Network Topology & Resilience"
quadrant-1 "Alex Xu (Scale & Mesh Topology)"
quadrant-2 "Martin Fowler (DDD & Bounded Contexts)"
quadrant-3 "Sam Newman (Deployment Autonomy)"
quadrant-4 "Chris Richardson (Distributed Transactions)"
"Fowler: Bounded Contexts": [0.35, 0.75]
"Newman: Smart Endpoints / Pact": [0.25, 0.35]
"Richardson: Saga & Outbox": [0.85, 0.30]
"Alex Xu: 5-Tier Mesh & Resilience": [0.80, 0.85]
1. Martin Fowler — Domain-Driven Design (DDD) & Bounded Contexts
- Zero Universal Data Models: Never share database tables, DTO models, or canonical classes across business boundaries. A
Customerin the Billing Context (balance, cards, invoices) is fundamentally different from aCustomerin the Fulfillment Context (shipping address, delivery notes). - Anti-Corruption Layer (ACL): External inputs must pass through an explicit schema adapter before entering the internal domain model.
- Strangler Fig Application: Migrate legacy monoliths by placing an API facade in front of the monolith and strangling legacy functionality one isolated bounded context at a time.
2. Sam Newman — Independent Deployability & Smart Endpoints
- The Core Microservices Test: “If Service A cannot be deployed to production without simultaneously deploying Service B, they are NOT microservices; they are a distributed monolith.”
- Smart Endpoints, Dumb Pipes: Never embed business logic, message transformation, or routing orchestration inside message brokers or enterprise service buses (ESB). The network pipe carries dumb bytes; the services own the intelligence.
- Consumer-Driven Contracts (Pact): API contracts are defined by consumers and enforced in provider CI pipelines to guarantee zero breaking changes across 1,000+ services without coordination meetings.
3. Chris Richardson — Distributed Data & Consistency Patterns
- Database-per-Service: Each microservice owns its private persistent datastore. Direct cross-database joins (
JOINacross schemas) are an absolute architectural violation. - Transactional Outbox + CDC: Eliminate dual-write vulnerabilities. Microservices save business entities and an
outboxevent record within a single local ACID transaction. An asynchronous Change Data Capture (CDC) agent (e.g., Debezium) tails the database transaction log (WAL) and streams events to Kafka. - Saga Pattern: Coordinate multi-service distributed transactions using choreography or orchestration with compensating transactions for rollbacks.
- CQRS (Command Query Responsibility Segregation): Separate mutating operations (
Commands) from complex reporting/search queries (Queries) using materialized read projections.
4. Alex Xu — High-Scale Topology, Resilience & Rate Limiting
- Layered Ingress Topology: Edge DNS $\rightarrow$ Anycast BGP $\rightarrow$ CDN/WAF $\rightarrow$ L4/L7 Load Balancers $\rightarrow$ API Gateway $\rightarrow$ Backend-for-Frontend (BFF) $\rightarrow$ Service Mesh (Envoy sidecars).
- Graceful Degradation & Resilience: Circuit Breakers (prevent cascading deadlocks), Bulkhead Pools (isolate resource exhaustion), and Exponential Backoff with Full Jitter (prevent thundering herd).
- W3C Distributed Tracing: OpenTelemetry distributed context propagation across every RPC boundary to make 10,000 service hops observable on a single dashboard.
3. High-Scale 5-Tier Enterprise Topology
This reference topology defines how user requests travel from global client devices down to thousands of internal microservices:
flowchart TD
subgraph Tier1["Tier 1: Global Edge & Ingress (Alex Xu)"]
Client["Mobile / Web / IoT Clients"] --> GeoDNS["Anycast BGP & GeoDNS (Route53 / Cloudflare)"]
GeoDNS --> Edge["Edge CDN & WAF (DDoS Mitigation, TLS 1.3)"]
end
subgraph Tier2["Tier 2: API Gateway & BFF Layer (Sam Newman)"]
Edge --> APIGW["Unified API Gateway (Token Bucket Rate Limiter, OAuth2 / OIDC Validator)"]
APIGW --> BFF_Web["BFF: Web Experience"]
APIGW --> BFF_Mobile["BFF: Mobile Experience (Response Trimming)"]
APIGW --> BFF_Partner["BFF: Public B2B Partner APIs"]
end
subgraph Tier3["Tier 3: Service Mesh & Traffic Plane (Envoy / Istio)"]
BFF_Web & BFF_Mobile & BFF_Partner --> IngressGateway["Mesh Ingress Controller"]
IngressGateway --> MeshDataPlane["Envoy Sidecar Mesh (mTLS Zero-Trust, Dynamic Routing, Canary 90/10)"]
end
subgraph Tier4["Tier 4: Business Domains (Martin Fowler - Bounded Contexts)"]
MeshDataPlane --> OrderSvc["Order Service (Sub-Atomic Pods)"]
MeshDataPlane --> PaymentSvc["Payment Service (Sub-Atomic Pods)"]
MeshDataPlane --> InventorySvc["Inventory Service (Sub-Atomic Pods)"]
MeshDataPlane --> NotificationSvc["Notification Service (Sub-Atomic Pods)"]
end
subgraph Tier5["Tier 5: Distributed Data & Event Highway (Chris Richardson)"]
OrderSvc --> OrderDB[("Order DB (Postgres)")]
PaymentSvc --> PaymentDB[("Payment DB (Postgres)")]
InventorySvc --> InvDB[("Inventory DB (CockroachDB)")]
OrderDB -.->|WAL / CDC| Debezium["Debezium CDC Engine"]
Debezium ==>|Guaranteed At-Least-Once| Kafka[["Apache Kafka Cluster (Event Backbone)"]]
Kafka --> SagaCoordinator["Saga Orchestrator"]
Kafka --> ReadIndexer["CQRS Projection Builder"]
ReadIndexer --> SearchCluster[("Elasticsearch / ClickHouse Read DB")]
end
4. Communication Protocol Decision Matrix
Do not standardize on a single communication protocol for all interactions. Apply the correct protocol based on the transactional nature of the payload:
| Interaction Style | Recommended Protocol | Data Format | Latency Target | Use Case |
|---|---|---|---|---|
| External Client to Gateway | HTTPS / HTTP/2 | JSON / REST | < 100 ms | Public mobile/web clients, browser compatibility |
| Internal Sync Inter-Service | gRPC (HTTP/2 multiplexing) | Protocol Buffers (Protobuf) | < 5 ms | High-throughput, strongly-typed internal RPCs |
| Async Domain Events | Apache Kafka / Apache Pulsar | Avro / Protobuf (Schema Registry) | Asynchronous | State changes, Saga triggers, Outbox CDC, auditing |
| Ultra-Low Latency Pub/Sub | NATS Core / JetStream | Binary / JSON | < 1 ms | Ephemeral signals, cache invalidations, live chat |
| Streaming / Real-Time Client | WebSocket / SSE | JSON / MsgPack | Persistent | Live order tracking, notifications, financial tickers |
5. Distributed Data Patterns & Zero-Data-Loss Standards
Pattern A: Transactional Outbox + Change Data Capture (CDC)
The Problem: Writing to a SQL database and then publishing to Kafka in application code causes the Dual-Write Hazard. If the app crashes after database commit but before Kafka send, messages are permanently lost. If it sends to Kafka first and DB fails, ghost events trigger corrupted downstream workflows.
The Solution:
sequenceDiagram
autonumber
actor Client
participant Service as Order Service
participant DB as Postgres (Order DB)
participant CDC as Debezium Engine
participant Kafka as Kafka Event Bus
Client->>Service: POST /orders (Create Order)
Note over Service,DB: Single Atomic Local ACID Transaction
Service->>DB: INSERT INTO orders (id, status, total)
Service->>DB: INSERT INTO outbox (event_id, aggregate_id, payload, created_at)
DB-->>Service: Transaction Committed OK
Service-->>Client: 201 Created (Order Pending)
Note over DB,CDC: Async Transaction Log Tailing (WAL)
CDC->>DB: Read Postgres WAL stream
CDC->>Kafka: Publish OrderCreatedEvent (Partition Key: order_id)
Kafka-->>CDC: ACK (Message Persisted)
CDC->>DB: Update replication slot offset
Pattern B: The Saga Pattern (Distributed Transactions Without 2PC)
When a business operation spans multiple services (e.g., E-Commerce Checkout), use an Orchestrated Saga with strict compensating rollbacks:
sequenceDiagram
autonumber
participant Orchestrator as Order Saga Orchestrator
participant OrderSvc as Order Service
participant PaymentSvc as Payment Service
participant InventorySvc as Inventory Service
Note over Orchestrator: Happy Path Phase
Orchestrator->>OrderSvc: Command: CreateOrder(Pending)
OrderSvc-->>Orchestrator: Reply: OrderCreated
Orchestrator->>PaymentSvc: Command: AuthorizePayment($150)
PaymentSvc-->>Orchestrator: Reply: PaymentAuthorized
Orchestrator->>InventorySvc: Command: ReserveInventory(item_42)
alt Inventory Out of Stock (Failure Scenario)
InventorySvc-->>Orchestrator: Reply: InventoryInsufficient
Note over Orchestrator: Backward Recovery (Compensating Transactions)
Orchestrator->>PaymentSvc: Compensate: RefundPayment($150)
PaymentSvc-->>Orchestrator: Reply: PaymentRefunded
Orchestrator->>OrderSvc: Compensate: CancelOrder(Reason: OutOfStock)
OrderSvc-->>Orchestrator: Reply: OrderCancelled
Note over Orchestrator: Saga Finished (Consistent Rollback)
else Inventory Reserved OK
InventorySvc-->>Orchestrator: Reply: InventoryReserved
Orchestrator->>OrderSvc: Command: ConfirmOrder(Status: Completed)
OrderSvc-->>Orchestrator: Reply: OrderConfirmed
end
6. Fault Isolation & Resiliency Engineering (Alex Xu Standard)
In a system of 1,000 microservices, if each service boasts 99.9% availability ($0.999$), overall system availability is $0.999^{1000} \approx 36.7%$. Failure is not an exception; it is the constant operational state.
1. Circuit Breaker State Transition Pattern
Wrap all inter-service outbound calls in a Circuit Breaker (e.g., Resilience4j / Envoy circuit breaking):
stateDiagram-v2
[*] --> Closed: Normal Operations
Closed --> Open: Error threshold exceeded (e.g. 50% failures over 10s)
state Open {
[*] --> FastFail: Reject all traffic immediately
FastFail --> Fallback: Return cached data or degraded response
}
Open --> HalfOpen: Sleep window elapsed (e.g. 15s)
state HalfOpen {
[*] --> TrialRequests: Allow small trial probe traffic (e.g. 5 requests)
}
HalfOpen --> Closed: All trial requests succeed
HalfOpen --> Open: Any trial request fails
2. Bulkhead Isolation
Isolate internal execution resources so that a latency surge in a non-critical downstream service (e.g., Recommendation Engine) cannot starve resources needed for critical paths (e.g., Payment Gateway):
- Thread Pool Bulkheads: Dedicated thread pool per downstream service.
- Connection Pool Bulkheads: Capped maximum connections per database and per gRPC target host.
3. Exponential Backoff with Full Jitter
Never execute immediate or uniform retries across distributed clients: $$T_{\text{sleep}} = \text{random}(0, , \min(T_{\text{max}}, , T_{\text{base}} \times 2^{\text{attempt}}))$$ Full Jitter eliminates synchronized retry waves that trigger devastating Thundering Herd cascades on recovering services.
7. Global Observability & Distributed Tracing Contract
Every microservice must propagate the W3C Distributed Trace Context across all network boundaries:
traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01
│ └────────────────┬───────────────┘ └───────┬──────┘ └─┬┘
version trace_id parent_id flags (01=sampled)
The 4 Golden Signals Contract (Google SRE Standard):
Every service must expose structured Prometheus metrics:
- Latency: Duration of request execution (histogram in milliseconds: p50, p95, p99).
- Traffic: Demand placed on the service (HTTP requests/sec or gRPC calls/sec).
- Errors: Rate of failed requests (HTTP 5xx or gRPC codes $\neq 0$).
- Saturation: Utilization of memory, CPU, socket file descriptors, and database connection pools.
8. The 20-Point Enterprise Architectural Audit Checklist
Before declaring any enterprise microservice architecture ready for production, verify compliance against this checklist:
A. Domain & Boundaries (Fowler)
- [ ] 1. Every microservice maps directly to an explicit DDD Bounded Context.
- [ ] 2. Zero shared database tables or cross-schema database queries.
- [ ] 3. Anti-Corruption Layers (ACL) sanitize all foreign upstream payloads.
- [ ] 4. Domain entities represent business workflows, not database CRUD rows.
B. Deployment & Autonomy (Newman)
- [ ] 5. Every service has its own dedicated CI/CD pipeline and can release independently.
- [ ] 6. Zero shared code libraries containing mutable domain logic (utility libs only).
- [ ] 7. Consumer-Driven Contracts (Pact) execute automatically on every PR.
- [ ] 8. Message pipes are dumb; no business logic lives inside Kafka brokers or queues.
C. Data & Transactions (Richardson)
- [ ] 9. Every state mutation publishing an event utilizes the Transactional Outbox + CDC pattern.
- [ ] 10. Multi-service transactions execute via Saga Orchestrators with verified compensating actions.
- [ ] 11. Consumers enforce strict idempotency (checking event ID before mutating state).
- [ ] 12. Complex cross-service search queries are offloaded to dedicated CQRS read projections.
D. Topology & Resilience (Alex Xu)
- [ ] 13. Public traffic enters through an Edge API Gateway with Token Bucket rate limiters.
- [ ] 14. Mobile and Web clients access the system through dedicated Backend-for-Frontend (BFF) layers.
- [ ] 15. All inter-service calls traverse an Envoy sidecar service mesh with mutual TLS (mTLS).
- [ ] 16. Outbound RPC calls are guarded by Circuit Breakers with configured fallbacks.
- [ ] 17. Retries strictly enforce Exponential Backoff with Full Jitter.
- [ ] 18. Thread pools and connection pools are isolated using the Bulkhead Pattern.
E. Sub-Atomic Invariant Compliance (Antigravity Standard)
- [ ] 19. Individual service workers and daemons strictly implement the 7 Invariant Pillars of
system-lifecycle-designer. - [ ] 20. W3C
traceparentcontext is forwarded across 100% of HTTP, gRPC, and Kafka boundaries.
04 同仓库更多 Skills
system-lifecycle-designer
Universal architectural methodology for designing granular, atomic, and sub-atomic lifecycles and end-to-end workflows for single functionality integrations across any domain (daemons, batch jobs, request transactions, resource pools). Provides patterns for deterministic identity, pre-commit validation, differential reconciliation, sticky leasing, state machines, transactional persistence, and closed-loop feedback.
style-sampling
Make a new episode in a proven video style - Collage Explainer, Finance Explainer, Animated Science Explainer, 3D Brand Explainer, 3D True Crime - on the person's topic. Use for "an episode of", "in the style of", "sample this style", 「用这个风格做一集」. One video to copy is reverse-any-video.
reverse-any-video
Rebuild any video file as an editable HyperFrames project - motion graphics, talking heads, live action or AI-generated footage - checked against the original frame by frame. Use to reverse, recreate, remake, replicate or copy a video, or 「复刻这个视频」「照着这个视频做一个」.
typescript-patterns
TypeScript patterns for strict, type-safe, maintainable code in modern TypeScript and JavaScript applications. Covers strict compiler configuration, type design, narrowing, discriminated unions, generics, async and error handling, module boundaries, dependency hygiene, and type-level testing. Use when writing or reviewing TypeScript or JavaScript code.
test-collaboration
Inventory and govern a project's test assets. Connect requirements, business rules, risks, bugs, and cross-boundary contracts to stable TEST-IDs and executable evidence in the repository's existing test registry or TESTS.md. Use for test inventory, test gap analysis, unit/integration/contract/E2E/smoke classification, bug-to-test regression protection, consumer/provider contract testing, test-necessity review, and pre-delivery evidence review.
story-lifecycle
Manage a file-based epic → story → sprint development loop without requiring an external project management tool. Creates and tracks epics, breaks them into user stories, assigns them to sprints, and drives implementation story by story. Use when starting a new feature initiative or when the team has no Jira/Linear/Taiga but needs structured delivery tracking.