マイクロサービスを適切に構築するには、分散システムの課題に対処する確立されたパターンを通じて対処する必要があります — サービス通信、データ管理、レジリエンス、および可観測性のためです。これらのパターンはマイクロサービスの本来的な複雑性を管理するのに役立ちます。
通信とAPIパターン
✓ API GATEWAY → single entry point; centralizes cross-cutting concerns (routing, auth, etc.)
✓ SERVICE DISCOVERY → services find each other dynamically (registry) as instances change
✓ Sync (REST/gRPC) for request/response; ASYNC (events/queues) for decoupling → prefer
async/events to reduce coupling where possible
✓ BFF (Backend for Frontend) → tailored gateways per client type
データ管理パターン
✓ DATABASE PER SERVICE → each service owns its data (no shared database) → independence,
but data is distributed (no cross-service joins/transactions)
✓ SAGA → manage transactions ACROSS services without distributed transactions:
→ a sequence of local transactions + compensating actions on failure (eventual consistency)
✓ EVENT SOURCING / CQRS → event-based state and separate read/write models
✓ Eventual consistency across services (embrace it; avoid distributed transactions)
