Top Related Projects
Quick Overview
Go Kit is a toolkit for microservices in Go. It provides a set of packages and best practices to help developers build robust, scalable, and maintainable distributed systems. Go Kit focuses on solving common problems in microservices architecture, such as service discovery, load balancing, and observability.
Pros
- Modular design allows for easy integration and customization
- Implements best practices for microservices architecture
- Supports various transport protocols (HTTP, gRPC, NATS)
- Extensive documentation and examples
Cons
- Steep learning curve for beginners
- Can be overkill for simple applications
- Requires additional boilerplate code compared to simpler frameworks
- Some users report that it's overly complex for certain use cases
Code Examples
- Creating a simple service:
type StringService interface {
Uppercase(string) (string, error)
Count(string) int
}
type stringService struct{}
func (stringService) Uppercase(s string) (string, error) {
if s == "" {
return "", ErrEmpty
}
return strings.ToUpper(s), nil
}
func (stringService) Count(s string) int {
return len(s)
}
- Implementing endpoint for the service:
func makeUppercaseEndpoint(svc StringService) endpoint.Endpoint {
return func(_ context.Context, request interface{}) (interface{}, error) {
req := request.(uppercaseRequest)
v, err := svc.Uppercase(req.S)
if err != nil {
return uppercaseResponse{v, err.Error()}, nil
}
return uppercaseResponse{v, ""}, nil
}
}
- Setting up HTTP transport:
func main() {
svc := stringService{}
uppercaseHandler := httptransport.NewServer(
makeUppercaseEndpoint(svc),
decodeUppercaseRequest,
encodeResponse,
)
http.Handle("/uppercase", uppercaseHandler)
log.Fatal(http.ListenAndServe(":8080", nil))
}
Getting Started
To start using Go Kit, first install it using:
go get github.com/go-kit/kit
Then, import the necessary packages in your Go code:
import (
"github.com/go-kit/kit/endpoint"
"github.com/go-kit/kit/transport/http"
)
Define your service interface and implementation, create endpoints, and set up the desired transport layer (HTTP, gRPC, etc.) as shown in the code examples above.
Competitor Comparisons
A dependency injection based application framework for Go.
Pros of fx
- Simpler and more lightweight, focusing on dependency injection
- Built-in support for graceful shutdown and lifecycle management
- More intuitive API for beginners
Cons of fx
- Less comprehensive than kit, lacking features like service discovery and circuit breaking
- Smaller community and ecosystem compared to kit
- May require additional libraries for full microservices functionality
Code Comparison
fx example:
func main() {
fx.New(
fx.Provide(NewHTTPServer),
fx.Invoke(func(*http.Server) {}),
).Run()
}
kit example:
func main() {
svc := service.New(logger, ...)
endpoints := endpoint.New(svc, ...)
httpHandler := transport.NewHTTPHandler(endpoints, ...)
http.ListenAndServe(":8080", httpHandler)
}
Summary
fx is a lightweight dependency injection framework, while kit is a more comprehensive microservices toolkit. fx offers simplicity and built-in lifecycle management, but lacks some advanced features provided by kit. kit provides a fuller set of tools for building microservices but may have a steeper learning curve. The choice between the two depends on project requirements and developer preferences.
A Go microservices framework
Pros of go-micro
- More opinionated and structured, providing a complete microservices framework
- Includes built-in service discovery, load balancing, and message encoding
- Offers a CLI tool for faster development and prototyping
Cons of go-micro
- Steeper learning curve due to its comprehensive nature
- Less flexibility for custom implementations compared to go-kit
- Potentially more challenging to integrate with existing systems
Code Comparison
go-micro example:
service := micro.NewService(
micro.Name("greeter"),
micro.Version("latest"),
)
service.Init()
go-kit example:
svc := myservice.NewService()
endpoints := myendpoints.NewEndpointSet(svc)
httpHandler := httptransport.NewServer(endpoints.Endpoint)
Both go-micro and go-kit are popular choices for building microservices in Go. go-micro provides a more comprehensive, out-of-the-box solution with built-in features for service discovery and communication. It's well-suited for projects that align with its opinionated approach. go-kit, on the other hand, offers more flexibility and is designed as a toolkit, allowing developers to pick and choose components as needed. It's better for projects requiring custom implementations or integration with existing systems. The choice between the two depends on project requirements, team expertise, and desired level of control over the microservices architecture.
A Microservice Toolkit from The New York Times
Pros of Gizmo
- More opinionated and structured, providing a clear path for building services
- Includes built-in support for metrics and health checks
- Offers integrated support for AWS services
Cons of Gizmo
- Less flexible and modular compared to Kit
- Smaller community and fewer third-party integrations
- More focused on specific use cases, potentially limiting for some projects
Code Comparison
Kit example:
func main() {
svc := service.New(myService{})
http.ListenAndServe(":8080", svc)
}
Gizmo example:
func main() {
cfg := &config.Server{HTTPPort: 8080}
server.Run(cfg, service.NewConfig(cfg), svc.New())
}
Both Kit and Gizmo are Go microservices toolkits, but they differ in their approach and focus. Kit is more modular and flexible, allowing developers to pick and choose components, while Gizmo provides a more structured and opinionated framework. Kit has a larger community and more third-party integrations, making it suitable for a wide range of projects. Gizmo, developed by The New York Times, offers built-in support for metrics, health checks, and AWS services, making it particularly useful for projects that align with its design philosophy.
Your ultimate Go microservices framework for the cloud-native era.
Pros of Kratos
- More opinionated and structured, providing a full-featured framework
- Built-in support for gRPC and HTTP protocols
- Includes tools for code generation and project scaffolding
Cons of Kratos
- Less flexible and modular compared to Kit
- Steeper learning curve for developers new to the framework
- Potentially more challenging to integrate with existing projects
Code Comparison
Kit example:
type Service interface {
Count(s string) int
}
type stringService struct{}
func (stringService) Count(s string) int {
return len(s)
}
Kratos example:
type Service struct {
pb.UnimplementedGreeterServer
}
func (s *Service) SayHello(ctx context.Context, req *pb.HelloRequest) (*pb.HelloReply, error) {
return &pb.HelloReply{Message: "Hello " + req.Name}, nil
}
Kit focuses on providing a set of loosely coupled packages that developers can use to build microservices. It offers more flexibility but requires more setup and configuration. Kratos, on the other hand, provides a more comprehensive framework with built-in features and conventions, making it easier to get started but potentially less flexible for complex use cases.
Both frameworks have their strengths, and the choice between them depends on the specific requirements of the project and the development team's preferences.
⚡️ Express inspired web framework written in Go
Pros of Fiber
- Faster performance and lower memory footprint
- Simpler API and easier learning curve for beginners
- Express-like syntax familiar to Node.js developers
Cons of Fiber
- Less focus on microservices architecture
- Fewer built-in features for complex distributed systems
- Less emphasis on observability and instrumentation
Code Comparison
Fiber example:
app := fiber.New()
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello, World!")
})
app.Listen(":3000")
Kit example:
svc := service.New(logger, ...)
endpoints := endpoint.New(svc, ...)
httpHandler := transport.NewHTTPHandler(endpoints, ...)
http.ListenAndServe(":3000", httpHandler)
Summary
Fiber is a lightweight, Express-inspired web framework focused on simplicity and performance. It's ideal for building straightforward web applications and APIs quickly.
Kit is a more comprehensive toolkit for building microservices, offering features like service discovery, load balancing, and observability. It's better suited for complex distributed systems and enterprise applications.
Choose Fiber for simpler web projects with a focus on speed and ease of use. Opt for Kit when building scalable microservices architectures that require advanced features and robustness.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Go kit
Go kit is a programming toolkit for building microservices (or elegant monoliths) in Go. We solve common problems in distributed systems and application architecture so you can focus on delivering business value.
- Website: gokit.io
- Mailing list: go-kit
- Slack: gophers.slack.com #go-kit (invite)
Sponsors
Click here or Sponsor, above, for more information on sponsorship.
Motivation
Go has emerged as the language of the server, but it remains underrepresented in so-called "modern enterprise" companies like Facebook, Twitter, Netflix, and SoundCloud. Many of these organizations have turned to JVM-based stacks for their business logic, owing in large part to libraries and ecosystems that directly support their microservice architectures.
To reach its next level of success, Go needs more than simple primitives and idioms. It needs a comprehensive toolkit, for coherent distributed programming in the large. Go kit is a set of packages and best practices, which provide a comprehensive, robust, and trustable way of building microservices for organizations of any size.
For more details, see the website, the motivating blog post and the video of the talk. See also the Go kit talk at GopherCon 2015.
Goals
- Operate in a heterogeneous SOA â expect to interact with mostly non-Go-kit services
- RPC as the primary messaging pattern
- Pluggable serialization and transport â not just JSON over HTTP
- Operate within existing infrastructures â no mandates for specific tools or technologies
Non-goals
- Supporting messaging patterns other than RPC (for now) â e.g. MPI, pub/sub, CQRS, etc.
- Re-implementing functionality that can be provided by adapting existing software
- Having opinions on operational concerns: deployment, configuration, process supervision, orchestration, etc.
Contributing
Please see CONTRIBUTING.md. Thank you, contributors!
Dependency management
Go kit is modules aware, and we encourage users to use the standard modules tooling. But Go kit is at major version 0, so it should be compatible with non-modules environments.
Code generators
There are several third-party tools that can generate Go kit code based on different starting assumptions.
- RecoLabs/microgen
- GrantZheng/kit
- kujtimiihoxha/kit (unmaintained)
- nytimes/marvin
- sagikazarmark/mga
- sagikazarmark/protoc-gen-go-kit
- metaverse/truss
- goadesign/goakit
Related projects
Projects with a â have had particular influence on Go kit's design (or vice-versa).
Service frameworks
- gizmo, a microservice toolkit from The New York Times â
- go-micro, a distributed systems development framework â
- gotalk, async peer communication protocol & library
- Kite, a micro-service framework
- gocircuit, dynamic cloud orchestration
Individual components
- afex/hystrix-go, client-side latency and fault tolerance library
- armon/go-metrics, library for exporting performance and runtime metrics to external metrics systems
- codahale/lunk, structured logging in the style of Google's Dapper or Twitter's Zipkin
- eapache/go-resiliency, resiliency patterns
- sasbury/logging, a tagged style of logging
- grpc/grpc-go, HTTP/2 based RPC
- inconshreveable/log15, simple, powerful logging for Go â
- mailgun/vulcand, programmatic load balancer backed by etcd
- mattheath/phosphor, distributed system tracing
- pivotal-golang/lager, an opinionated logging library
- rubyist/circuitbreaker, circuit breaker library
- sirupsen/logrus, structured, pluggable logging for Go â
- sourcegraph/appdash, application tracing system based on Google's Dapper
- spacemonkeygo/monitor, data collection, monitoring, instrumentation, and Zipkin client library
- streadway/handy, net/http handler filters
- vitess/rpcplus, package rpc + context.Context
- gdamore/mangos, nanomsg implementation in pure Go
Web frameworks
Additional reading
- Architecting for the Cloud â Netflix
- Dapper, a Large-Scale Distributed Systems Tracing Infrastructure â Google
- Your Server as a Function (PDF) â Twitter
Top Related Projects
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot