|
| 1 | +--- |
| 2 | +description: Vibe coding guidelines and architectural constraints for Microservices within the backend domain. |
| 3 | +technology: Microservices |
| 4 | +domain: backend |
| 5 | +level: Architect |
| 6 | +complexity: Architect |
| 7 | +topic: Microservices |
| 8 | +vibe_coding_ready: true |
| 9 | +version: Agnostic |
| 10 | +tags: [best-practices, clean-code, architecture-patterns, vibe-coding, microservices, distributed-systems, system-design, solid-principles, production-ready, scalable-code] |
| 11 | +ai_role: Senior Microservices Architect |
| 12 | +last_updated: 2026-03-27 |
| 13 | +last_evolution: 2026-03-27 |
| 14 | +--- |
| 15 | + |
| 16 | +<div align="center"> |
| 17 | + <img src="https://raw.githubusercontent.com/tandpfun/skill-icons/main/icons/Docker.svg" width="100" alt="Microservices Logo"> |
| 18 | + |
| 19 | + # 🧩 Microservices Production-Ready Best Practices |
| 20 | +</div> |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +This document establishes **best practices** for designing and maintaining a Microservices architecture. These constraints guarantee a scalable, highly secure, and clean system suitable for an enterprise-level, production-ready backend. |
| 25 | + |
| 26 | +# ⚙️ Context & Scope |
| 27 | +- **Primary Goal:** Provide an uncompromising set of rules and architectural constraints for distributed system environments. |
| 28 | +- **Target Tooling:** AI-agents (Cursor, Windsurf, Copilot, Antigravity) and System Architects. |
| 29 | +- **Tech Stack Version:** Agnostic |
| 30 | + |
| 31 | +> [!IMPORTANT] |
| 32 | +> **Architectural Standard (Contract):** Ensure loose coupling and high cohesion. Each microservice must own its domain data. Use asynchronous messaging (e.g., Kafka, RabbitMQ) for inter-service communication to prevent cascading failures. |
| 33 | +
|
| 34 | +--- |
| 35 | + |
| 36 | +## 🏗️ 1. Architecture & Design |
| 37 | + |
| 38 | +### Domain-Driven Design (DDD) |
| 39 | +- Define clear Bounded Contexts for every service to avoid spaghetti dependencies. |
| 40 | +- Implement the API Gateway pattern to route external requests to internal microservices, handling cross-cutting concerns (auth, rate limiting). |
| 41 | + |
| 42 | +### 🔄 Data Flow Lifecycle |
| 43 | + |
| 44 | +```mermaid |
| 45 | +sequenceDiagram |
| 46 | + participant Client |
| 47 | + participant Gateway as API Gateway |
| 48 | + participant Auth as Auth Service |
| 49 | + participant User as User Service |
| 50 | + participant Msg as Message Broker (Kafka) |
| 51 | + participant Notification as Notification Service |
| 52 | +
|
| 53 | + Client->>Gateway: POST /users (Create User) |
| 54 | + Gateway->>Auth: Validate Token |
| 55 | + Auth-->>Gateway: Token Valid |
| 56 | + Gateway->>User: Create User Request |
| 57 | + User-->>User: Persist User to DB |
| 58 | + User->>Msg: Publish "UserCreated" Event |
| 59 | + User-->>Gateway: Return 201 Created |
| 60 | + Gateway-->>Client: Respond with Success |
| 61 | +
|
| 62 | + Msg->>Notification: Consume "UserCreated" Event |
| 63 | + Notification-->>Notification: Send Welcome Email |
| 64 | +``` |
| 65 | + |
| 66 | +## 🔒 2. Security Best Practices |
| 67 | + |
| 68 | +### Service-to-Service Authentication |
| 69 | +- Implement Zero Trust architecture. Internal services must authenticate each other using mTLS (Mutual TLS) or signed JWTs. |
| 70 | +- Secrets must never be hardcoded. Utilize a secret manager (HashiCorp Vault, AWS Secrets Manager). |
| 71 | + |
| 72 | +### Data Isolation |
| 73 | +- Enforce "Database per Service" pattern. Services must never share a single database to ensure independent scaling and deployment. |
| 74 | + |
| 75 | +## 🚀 3. Reliability Optimization |
| 76 | + |
| 77 | +### Resilience Patterns |
| 78 | +- Implement Circuit Breakers (e.g., resilience4j) to fail fast and recover when a dependent service goes down. |
| 79 | +- Implement retries with exponential backoff for transient network errors. |
| 80 | +- Ensure Idempotency for critical operations to handle duplicated requests gracefully. |
| 81 | + |
| 82 | +### Observability |
| 83 | +- Distributed Tracing is mandatory (OpenTelemetry). All requests must pass a Correlation ID across service boundaries. |
| 84 | +- Centralized Logging (ELK, Datadog) is required for debugging complex distributed issues. |
| 85 | + |
| 86 | +## 📚 Specialized Documentation |
| 87 | +- [architecture.md](./architecture.md) |
| 88 | +- [security-best-practices.md](./security-best-practices.md) |
| 89 | +- [api-design.md](./api-design.md) |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +[Back to Top](#) |
0 commit comments