系统列表
Distributed Systems in Go:生产级分布式平台 SDK 与微服务实战
专栏《分布式 Go 系统工程》配套完整代码实战工程,涵盖并发模型、消息队列适配、Saga 编排、弹性容错与可观测性等生产级模式。
README.mdSYSTEM.mdcmd/auth/main.gocmd/gateway/main.gocmd/orders/main.goconfig/grafana/datasources/datasources.yamlconfig/prometheus.yamlconfig/tempo.yamldeploy/kube/orderflow-infra.yamldocker-compose.ymlgo.modgo.suminternal/auth/handler.gointernal/auth/service.gointernal/domain/events.gointernal/inventory/handler.gointernal/inventory/service.gointernal/notifications/service.gointernal/orders/handler.gointernal/orders/service.gointernal/payment/service.gomigrations/000001_init_schema.up.sqlpkg/platform/auth/auth_test.gopkg/platform/auth/claims.gopkg/platform/auth/jwks.gopkg/platform/auth/middleware.gopkg/platform/auth/password.gopkg/platform/auth/token.gopkg/platform/cli/cli_test.gopkg/platform/cli/health.gopkg/platform/concurrency/context.gopkg/platform/concurrency/shutdown.gopkg/platform/concurrency/shutdown_test.gopkg/platform/concurrency/workerpool.gopkg/platform/concurrency/workerpool_test.gopkg/platform/config/config_test.gopkg/platform/config/loader.gopkg/platform/consistency/consistency_test.gopkg/platform/consistency/idempotency.gopkg/platform/consistency/optimistic.gopkg/platform/consistency/saga.gopkg/platform/ctxutil/context.gopkg/platform/ctxutil/context_test.gopkg/platform/ctxutil/keys.gopkg/platform/database/database_test.gopkg/platform/database/errors.gopkg/platform/database/migrate.gopkg/platform/database/pool.gopkg/platform/database/retry.gopkg/platform/database/tx.gopkg/platform/messaging/fake.gopkg/platform/messaging/fake_test.gopkg/platform/messaging/interfaces.gopkg/platform/messaging/kafka/consumer.gopkg/platform/messaging/kafka/producer.gopkg/platform/messaging/nats/publisher.gopkg/platform/messaging/nats/subscriber.gopkg/platform/messaging/schema.gopkg/platform/middleware/bodyclose.gopkg/platform/middleware/chain.gopkg/platform/middleware/cors.gopkg/platform/middleware/errors.gopkg/platform/middleware/health.gopkg/platform/middleware/logging.gopkg/platform/middleware/middleware_test.gopkg/platform/middleware/recover.gopkg/platform/middleware/requestid.gopkg/platform/middleware/timeout.gopkg/platform/observability/context.gopkg/platform/observability/logger.gopkg/platform/observability/metrics.gopkg/platform/observability/observability_test.gopkg/platform/observability/tracing.gopkg/platform/orchestration/budget.gopkg/platform/orchestration/degrade.gopkg/platform/orchestration/fanout.gopkg/platform/orchestration/orchestration_test.gopkg/platform/resilience/circuit.gopkg/platform/resilience/resilience_test.gopkg/platform/resilience/retry.gotests/live_infra_test.gotests/orderflow_integration_test.go
Distributed Systems in Go
Practical implementation of distributed systems patterns and infrastructure in Go, based on Distributed Systems in Go by Joel Bryan Juliano (2026).
Architecture
This project adopts the Company Platform SDK + Monorepo Microservices architecture:
pkg/platform/: Shared infrastructure SDK built progressively across chapters.concurrency/: Bounded worker pool, graceful shutdown, context detach (Ch 2)messaging/: Pub/Sub abstractions, in-memory fake broker, NATS & Kafka adapters (Ch 3, 8)middleware/: Production HTTP middleware chain (Recover, RequestID, Logging, Timeout, CORS, Errors, Health) (Ch 4)auth/: ECDSA (ES256) JWT tokens, JWKS, scopes/roles authorization, bcrypt (Ch 5)database/: pgxpool connection management, transactions, migrations runner, error mappers (Ch 6)ctxutil/: Generic type-safe context values, typed keys, deadline narrowing (Ch 7)resilience/: Circuit breaker, exponential backoff with full jitter (Ch 9)orchestration/: Parallel fan-out with errgroup, scatter-gather, best-effort degradation, timeout budgets (Ch 10)consistency/: Idempotency store, distributed Saga orchestrator with reverse compensation, optimistic locking retry (Ch 11)observability/: slog structured logger with contextual attribute injection, Prometheus metrics exposition, W3C tracing (Ch 12)config/: Struct-tag-driven 12-Factor env config loader, .env parser, validation (Ch 14)cli/: Service health checker and operational CLI helpers (App C)
cmd/: Runnable services (API Gateway, Orders, Inventory, Payment, Notifications) (Ch 15 Capstone).book/: Extracted chapter-by-chapter Markdown reference docs.
Deployment & Infrastructure
1. Using Podman (Native play kube)
The infrastructure can be launched directly using Podman with standard Kubernetes Pod manifests:
# Launch Postgres, NATS, and Kafka as a unified local Pod
podman play kube deploy/kube/orderflow-infra.yaml
# Check running pod and containers
podman pod ps
podman ps
# Stop and tear down the infrastructure
podman play kube --down deploy/kube/orderflow-infra.yaml2. Using Docker Compose
docker compose up -dRunning Tests
1. Platform SDK & Domain Unit Tests
Run all unit tests and Saga integration tests with race detection:
go test -v -race ./pkg/...
go test -v -race ./tests/orderflow_integration_test.go2. Live Infrastructure Tests (Podman)
With podman play kube deploy/kube/orderflow-infra.yaml running:
go test -v ./tests/live_infra_test.goThis verifies:
- PostgreSQL database connectivity and connection pool retry.
- Automatic schema migration runner (
pkg/platform/database.MigrationRunner) executingmigrations/*.up.sql. - High-throughput pub/sub over NATS.
- Producer & Consumer Group pub/sub with automatic topic provisioning & resilience backoff over Apache Kafka (KRaft).