$ show zeromicro/go-zero
go-zero is a full-stack Go microservices framework with an integrated code generation toolchain (goctl). In production, it provides a production-grade HTTP/REST server (rest/) with a middleware chain for authentication, tracing, rate limiting, circuit breaking, and load shedding; a gRPC server/client framework (zrpc/) with interceptors for observability, auth, and timeout; an API gateway (gateway/) that translates HTTP requests to gRPC; and a CLI tool (goctl) that generates Go, TypeScript, Dart, Java, and Swagger code from API definitions, SQL schemas, and protobuf files. The core library (core/) delivers building blocks: configuration loading (YAML/JSON/TOML), structured logging with rotation, Prometheus metrics, OpenTelemetry tracing, circuit breaker (Google SRE algorithm), adaptive load shedding, rate limiting (token bucket, period limit), distributed caching (Redis, in-memory), SQL/NoSQL data access with caching, service discovery (etcd, Kubernetes), concurrency primitives (singleflight, mapreduce, stream processing), and data structures (rolling window, timing wheel, safe map). The architecture is modular, with each package providing clean interfaces and option patterns. The codebase is well-tested, actively maintained, and demonstrates strong engineering craftsmanship.
The LLM identified 8 files worth highlighting for reuse:
Provides generic MapReduce, ForEach, and Finish functions with configurable worker count, context propagation, panic recovery, and guarded writers. The implementation handles cancellation gracefully and can be extracted as a standalone concurrent processing utility for any Go project.
Implements a hierarchical timing wheel for managing millions of delayed tasks with O(1) insertion/cancellation. Uses a bucket list and ticker goroutine. Reusable as a general-purpose timer scheduler in any Go application needing efficient deferred execution.
Implements Google SRE's circuit breaker algorithm using a sliding window of requests and a probability-based rejection formula. Provides Accept/Reject promise pattern and configurable thresholds. Clean interface that can be extracted for any RPC or database client.
Adaptive load shedder that uses CPU usage, rolling window of request rate and latency to dynamically calculate max in-flight requests. Includes cooling-off period and overload factor. A sophisticated, self-contained load protection component.
Implements a cache-aside pattern with singleflight (request coalescing) and not-found placeholder to prevent cache stampede and repeated DB queries for missing keys. Includes async retry deletion and statistics. Can be reused as a Redis + DB caching layer.
Functional stream processing library providing From, Map, Filter, Reduce, Walk, Parallel, and other operations on channels. Uses buffered channels and goroutine pools. Reusable as a general-purpose stream processing toolkit for concurrent data pipelines.
Deduplicates concurrent calls to the same key by sharing the result among callers. Uses a map of in-flight calls with mutex and sync.WaitGroup. A clean, minimal implementation that can be extracted to prevent thundering herd problems in any caching layer.
Implements a distributed mutex lock using Redis SET NX EX with Lua script for atomic unlock. Supports automatic expiry, blocking acquire with timeout, and spin interval. A self-contained, production-ready distributed lock component.