Architecture
The microservices-app consists of 6 independent services that communicate via gRPC (using Connect protocol) and REST APIs. The architecture is designed to demonstrate various microservice patterns including service-to-service communication, circuit breakers, retry budgets, and both synchronous and asynchronous database patterns.Service Catalog
Greeter Service
Go-based gRPC service that orchestrates calls to external APIs via the Caller service
Caller Service
Go-based gRPC service that makes HTTP calls to external URLs
Gateway Service
Go-based gRPC service with circuit breaker and retry logic for custom language service
Auth Service
Node.js REST API providing JWT-based authentication with RSA signing
Custom Language Service
Node.js REST API for custom invocation logic with configurable response codes
Technology Stack
Go Services (greeter, caller, gateway)
- Framework: Connect-Go (gRPC-compatible protocol)
- HTTP/2: h2c handler for efficient communication
- Database: PostgreSQL via pgx/v5
- Observability: OpenTelemetry with automatic tracing
- Protocol: Protocol Buffers for service definitions
Node.js Services (auth-service, custom-lang-service)
- Framework: Express
- Database: PostgreSQL via pg driver
- Authentication: JWT with RSA-256 signing
- Observability: OpenTelemetry instrumentation
Service Communication
Database Architecture
Each service has its own PostgreSQL database following the database-per-service pattern:| Service | Database | Pattern | Purpose |
|---|---|---|---|
| Greeter | greeter_db | Synchronous writes | Stores greeting logs with external API status |
| Caller | caller_db | Asynchronous writes | Logs external API calls (fire-and-forget) |
| Gateway | gateway_db | Synchronous writes | Records invocation history including failures |
| Auth | auth_db | Synchronous writes | User accounts and credentials |
| Custom Lang | lang_db | Synchronous writes | Execution logs |
Service Patterns
Synchronous DB Pattern (Greeter, Gateway, Auth, Custom Lang)
Database writes complete before sending the response. Guarantees data persistence but adds latency.Asynchronous DB Pattern (Caller)
Database writes happen in a goroutine after returning the response. Lower latency but risk of data loss.Circuit Breaker Pattern (Gateway)
The Gateway service uses thegobreaker library to prevent cascading failures:
- Max Requests: 3 requests allowed in half-open state
- Timeout: 30 seconds before transitioning to half-open
- Trip Threshold: 5 consecutive failures
- Interval: 10 seconds for counting failures
Retry Budget Pattern (Gateway)
Limits retry attempts to prevent retry storms:- Capacity: 20 tokens
- Refill Rate: 10 tokens per second
- Retryable Errors: 429, 502, 503, 504, network timeouts
Common Configuration
All services support these standard environment variables:HTTP server port (8080 for greeter, 8081 for caller, 8082 for gateway, 8090 for auth, 3000 for custom-lang)
PostgreSQL connection string. Services run without DB if not provided.Format:
postgresql://user:pass@host:port/dbnameOpenTelemetry collector endpoint for traces and metrics
Service name for OpenTelemetry spans and metrics
Health Checks
All services expose a/healthz endpoint:
- Returns
200 OKif service is healthy - Returns
503 Service Unavailableif database health check fails - Go services: Check database ping
- Node.js services: Execute
SELECT 1query
Development Ports
When running locally via Docker Compose:| Service | Internal Port | External Access |
|---|---|---|
| Traefik | 80 | localhost:30081 |
| Greeter | 8080 | via Traefik |
| Caller | 8081 | internal only |
| Gateway | 8082 | via Traefik |
| Auth | 8090 | via Traefik |
| Custom Lang | 3000 | internal only |
| PostgreSQL | 5432 | localhost:5432 |
Next Steps
Greeter Service
Learn about the main greeting service
Gateway Service
Explore circuit breaker patterns
Auth Service
Implement authentication
Deployment
Deploy the services