
Overview
17 個 Kubernetes 服務組成的微服務架構,涵蓋 API Gateway、服務間通訊、分散式監控、訊息佇列、快取、資料庫。完整實作從開發到部署的全流程。
Architecture
Client Request
→ Kong API Gateway (路由/限流/認證)
→ Auth Service (FastAPI, JWT/OAuth)
→ Post Service (FastAPI, CRUD/搜索)
→ User Service (FastAPI, 會員管理)
→ ... (其他業務服務)
→ PostgreSQL (持久化)
→ Redis (快取/Session)
→ RabbitMQ (非同步訊息)
Observability Stack:
Prometheus → Grafana (Metrics 儀表板)
Fluent-bit → Loki (Log 聚合)
Tempo (Distributed Tracing)
Services (17)
| Category | Service | Description |
|---|---|---|
| Gateway | Kong | API 路由、Rate Limiting、JWT 驗證、Plugin 擴充 |
| 業務 | Auth Service | JWT 發行/驗證、OAuth 整合、Token Refresh |
| 業務 | Post Service | 文章 CRUD、全文搜索、分類標籤 |
| 業務 | User Service | 會員管理、Profile、權限 |
| 資料 | PostgreSQL | 主資料庫,每服務獨立 Schema |
| 資料 | Redis | 分散式快取、Session Store、Rate Limit Counter |
| 訊息 | RabbitMQ | 服務間非同步通訊、Event-Driven 架構 |
| 監控 | Prometheus | Metrics 採集、Alert Rules |
| 監控 | Grafana | 視覺化儀表板、多資料源整合 |
| 監控 | Loki | Log 聚合查詢 |
| 監控 | Tempo | 分散式追蹤 |
| 監控 | Fluent-bit | Log 收集轉發 |
Key Features
| Feature | Description |
|---|---|
| Service Mesh | Kong 統一入口,服務間透過內部 DNS 通訊 |
| 分散式監控 | Metrics + Logs + Tracing 三大支柱完整覆蓋 |
| Event-Driven | RabbitMQ 解耦服務,支援 Pub/Sub 與 Work Queue |
| K8s 原生 | Deployment / Service / ConfigMap / Secret / HPA 完整配置 |
| Health Check | 每服務提供 /health endpoint,K8s Liveness/Readiness Probe |
| 環境隔離 | dev / staging / production 三套環境,Namespace 隔離 |
架構說明
- API Gateway (Kong):所有外部請求經過 Kong 統一路由,支援 JWT 驗證 Plugin、Rate Limiting、Request/Response Transform
- 服務通訊:同步請求走 HTTP/gRPC,非同步事件走 RabbitMQ,避免服務間強耦合
- 資料隔離:每個微服務擁有獨立的 PostgreSQL Schema,禁止跨服務直接查詢資料庫
- 監控告警:Prometheus 採集所有服務 Metrics,Grafana 設定 Dashboard + Alert,Loki 集中日誌查詢
- 分散式追蹤:Tempo 收集跨服務 Trace,可視化請求在各服務間的流轉路徑與延遲
Tech Stack
FastAPI + Uvicorn ・ Kong API Gateway ・ PostgreSQL + Redis + RabbitMQ ・ Prometheus + Grafana + Loki + Tempo + Fluent-bit ・ Docker + Kubernetes ・ Helm Charts
