Polyglot Microservice Architecture Guide
This skill defines the architectural blueprint, service boundaries, inter-service communication protocols, database schema standards, and deployment targets for modern polyglot microservice systems.
1. Local Branch-First Development
main: ``bash git switch -c <developer-or-agent>/main/<feature-name> ` Never develop or modify code directly on main`.2. System Topology
┌─────────────────────────────────────────────────────────────┐
│ Next.js Frontend │
│ (Deployed on Vercel / Cloudflare Edge) │
└───────────────┬─────────────────────────────┬───────────────┘
│ REST / SSE │ REST / WebSocket
▼ ▼
┌─────────────────────────────┐ ┌─────────────────────────────┐
│ Python AI Service │ │ Go Backend API │
│ (FastAPI / LangChain) │ │ (High-Throughput Fiber) │
└───────────────┬─────────────┘ └─────────────┬───────────────┘
│ │
│ ┌─────────────────┐ │
├────►│ PostgreSQL 16+ │◄────┤
│ │ (pgvector + FTS)│ │
│ └────────┬────────┘ │
│ ▲ │
│ │ Sync / Queue │
│ ┌────────┴────────┐ │
│ │ Worker Daemon │ │
│ │ (Go CLI / Cron) │ │
│ └─────────────────┘ │
▼ ▼
┌─────────────────────────────┐ ┌─────────────────────────────┐
│ AI Model Providers │ │ Notifications & Webhooks │
│ (Multi-Key Failover Pools) │ │ (SMTP / Slack / Alert) │
└─────────────────────────────┘ └─────────────────────────────┘3. Service Boundaries & Responsibilities
Next.js Frontend (frontend/ or web/)
- Unified user interface, operational dashboards, and analytics charts.
- Interactive AI chat streaming via Server-Sent Events (SSE).
- Real-time status indicators via WebSockets.
- Human-in-the-loop (HITL) approval interfaces.
src/config/env.ts), avoiding direct process.env calls in UI components.Python AI & Observatory Service (ai-service/ or agent/)
- Autonomous multi-turn reasoning and tool invocation loops.
- Hybrid search: Full-Text Search combined with pgvector cosine similarity and Reciprocal Rank Fusion (RRF).
- Background embedding generation pipelines and vector indexing.
- Token tracking, model routing, and multi-key failover handling.
config/settings.py).Go Backend & REST APIs (backend/ or api/)
- High-throughput transaction ingestion, validation, and REST API routing.
- Real-time WebSocket event broadcasting and pub/sub distribution.
- Database telemetry, health probes, and structured metrics.
config/config.go).Background Worker Engine (worker/ or cmd/worker/)
- Scheduled batch processing, queue polling, and asynchronous job execution.
- Data ingestion, archive generation, and external API polling.
- Heartbeat reporting and error telemetry back to the database.
4. Database Schema Design & Migration Standards
- CREATE TABLE IF NOT EXISTS ...
- CREATE INDEX IF NOT EXISTS ...
- ALTER TABLE ... ADD COLUMN IF NOT EXISTS ...
DROP TABLE, TRUNCATE, or destructive column removals in automated production scripts. - jobs / tasks: Job identifiers, status transitions, payloads, timestamps, error records.
- execution_logs: Structured, timestamped step execution logs for observability.
- analytics_snapshots: Aggregated metrics and telemetry for dashboard reporting.
- ai_sessions & ai_messages: Normalized conversation records and tool invocation histories.
- embedding_chunks: Vector representations and metadata with HNSW vector indexing.