Microservices Architecture
Focus: Extreme scalability and team autonomy.
Strengths: Granular scaling and polyglot freedom.
Weaknesses: High operational complexity and technical challenges in managing distributed data integrity.
1. CORE DESIGN PRINCIPLES
- Database per Service: Every service owns its private data. No shared schemas.
- High Cohesion/Loose Coupling: Group related functions; minimize inter-service dependencies.
- API-First Contract: Define interfaces (OpenAPI/AsyncAPI) before implementation.
- Event-Driven Preference: Prioritize asynchronous communication for state changes to ensure system resilience.
- Observability by Design: Mandatory Distributed Tracing (Correlation IDs) for all cross-service requests.
2. EXECUTION FRAMEWORK
A. Strategic Decomposition
- Analyze the domain to identify Bounded Contexts.
- Map Aggregates and their boundaries.
- Define the Context Map (Upstream/Downstream, Customer-Supplier, etc.).
B. Communication Modeling
- Edge Gateway: Define entry points, Authentication (JWT/OIDC), Rate Limiting, and Request Routing.
- Sync (REST/gRPC): Use for reads operations or where immediate consistency is a hard requirement. Must include Circuit Breaker and Retry patterns.
- Async (Pub/Sub): Use for commands and side effects to ensure eventual consistency.
- Saga Pattern: Propose Choreography or Orchestration for transactions spanning multiple services.
C. Service Technical Specification
For each microservice identified, generate the following structure:
- Service Name: [e.g., Order-Management-Service]
- Business Capability: The specific "Job to be Done".
- Data Store: Specific DB engine (e.g., NoSQL for high-write, Relational for complex queries).
- Primary Adapters (Inbound): REST Controllers, Message Listeners.
- Secondary Adapters (Outbound): Repository Impls, Event Producers, External Gateway Clients.
- Strategic Pattern: (e.g., CQRS, Event Sourcing, or Simple CRUD).
3. Event-Driven Design (EDD)
A. Event Classification
The agent must distinguish between different types of events to avoid "API-over-the-wire" anti-patterns:
- Domain Events: Fine-grained events used within a Bounded Context (e.g., OrderValidated).
- Integration Events: Coarse-grained events used to communicate between different microservices (e.g., OrderPlaced).
- State Transfer Events (Event Carried State Transfer): Events containing the full snapshot of data so the consumer doesn't need to "call back" the producer for details.
B. Interaction Patterns
The skill should propose the best choreography based on the use case:
- Pub/Sub Pattern: One producer, multiple independent consumers.
- Event Sourcing: Storing the state as a sequence of events rather than just the current snapshot.
- Command Query Responsibility Segregation (CQRS): Separating the write model (Event Store) from the read model (Projections/Elasticsearch).
C. Reliability & Consistency Patterns
When designing EDD, the agent must include:
- Transactional Outbox Pattern: Ensuring an event is only published if the database transaction succeeds.
- Idempotency: Designing consumers to handle the same event multiple times without side effects.
- Dead Letter Queues (DLQ): Handling malformed or unprocessable events without blocking the pipeline.
D. Strategic Tooling Selection
The agent should recommend tools based on throughput and requirements:
- Kafka: For high-throughput, log-based streaming and event replayability.
- RabbitMQ/SQS: For complex routing and traditional task queuing.
- Redis Streams: For lightweight, low-latency eventing.
4. GUARDRAILS & OBSERVABILITY
- Anti-Pattern Alert: Explicitly refuse "Shared Databases" or "Distributed Transactions (2PC)".
- Granularity Check: Warn if a service is a "Nano-service" (too small) or a "Distributed Monolith" (too coupled).
- Standardized Health: Every service must implement
/health, /metrics (Prometheus), and /ready endpoints.
- Tracing: All logs and spans must propagate the
Correlation-ID.
1---2name: microservices-architecture3description: Guardian of Microservices Architecture and Event-Driven Design (EDD).4---56# Microservices Architecture78**Focus:** Extreme scalability and team autonomy.9**Strengths:** Granular scaling and polyglot freedom.10**Weaknesses:** High operational complexity and technical challenges in managing distributed data integrity.1112---1314## 1. CORE DESIGN PRINCIPLES15- **Database per Service:** Every service owns its private data. No shared schemas.16- **High Cohesion/Loose Coupling:** Group related functions; minimize inter-service dependencies.17- **API-First Contract:** Define interfaces (OpenAPI/AsyncAPI) before implementation.18- **Event-Driven Preference:** Prioritize asynchronous communication for state changes to ensure system resilience.19- **Observability by Design:** Mandatory Distributed Tracing (Correlation IDs) for all cross-service requests.2021---2223## 2. EXECUTION FRAMEWORK2425### A. Strategic Decomposition26- Analyze the domain to identify **Bounded Contexts**.27- Map **Aggregates** and their boundaries.28- Define the **Context Map** (Upstream/Downstream, Customer-Supplier, etc.).2930### B. Communication Modeling31- **Edge Gateway:** Define entry points, Authentication (JWT/OIDC), Rate Limiting, and Request Routing.32- **Sync (REST/gRPC):** Use for reads operations or where immediate consistency is a hard requirement. **Must** include Circuit Breaker and Retry patterns.33- **Async (Pub/Sub):** Use for commands and side effects to ensure eventual consistency.34- **Saga Pattern:** Propose Choreography or Orchestration for transactions spanning multiple services.3536### C. Service Technical Specification37For each microservice identified, generate the following structure:38- **Service Name:** [e.g., Order-Management-Service]39- **Business Capability:** The specific "Job to be Done".40- **Data Store:** Specific DB engine (e.g., NoSQL for high-write, Relational for complex queries).41- **Primary Adapters (Inbound):** REST Controllers, Message Listeners.42- **Secondary Adapters (Outbound):** Repository Impls, Event Producers, External Gateway Clients.43- **Strategic Pattern:** (e.g., CQRS, Event Sourcing, or Simple CRUD).4445---4647## 3. Event-Driven Design (EDD)4849### A. Event Classification50The agent must distinguish between different types of events to avoid "API-over-the-wire" anti-patterns:51* **Domain Events:** Fine-grained events used within a Bounded Context (e.g., OrderValidated).52* **Integration Events:** Coarse-grained events used to communicate between different microservices (e.g., OrderPlaced).53* **State Transfer Events (Event Carried State Transfer):** Events containing the full snapshot of data so the consumer doesn't need to "call back" the producer for details.5455### B. Interaction Patterns56The skill should propose the best choreography based on the use case:57* **Pub/Sub Pattern:** One producer, multiple independent consumers.58* **Event Sourcing:** Storing the state as a sequence of events rather than just the current snapshot.59* **Command Query Responsibility Segregation (CQRS):** Separating the write model (Event Store) from the read model (Projections/Elasticsearch).6061### C. Reliability & Consistency Patterns62When designing EDD, the agent must include:63* **Transactional Outbox Pattern:** Ensuring an event is only published if the database transaction succeeds.64* **Idempotency:** Designing consumers to handle the same event multiple times without side effects.65* **Dead Letter Queues (DLQ):** Handling malformed or unprocessable events without blocking the pipeline.6667### D. Strategic Tooling Selection68The agent should recommend tools based on throughput and requirements:69* **Kafka:** For high-throughput, log-based streaming and event replayability.70* **RabbitMQ/SQS:** For complex routing and traditional task queuing.71* **Redis Streams:** For lightweight, low-latency eventing.7273---7475## 4. GUARDRAILS & OBSERVABILITY76* **Anti-Pattern Alert:** Explicitly refuse "Shared Databases" or "Distributed Transactions (2PC)".77* **Granularity Check:** Warn if a service is a "Nano-service" (too small) or a "Distributed Monolith" (too coupled).78* **Standardized Health:** Every service must implement `/health`, `/metrics` (Prometheus), and `/ready` endpoints.79* **Tracing:** All logs and spans must propagate the `Correlation-ID`.