go-micro.dev/v5@v5.12.0/internal/website/docs/guides/comparison.md (about)

     1  ---
     2  layout: default
     3  ---
     4  
     5  # Framework Comparison
     6  
     7  How Go Micro compares to other Go microservices frameworks.
     8  
     9  ## Quick Comparison
    10  
    11  | Feature | Go Micro | go-kit | gRPC | Dapr |
    12  |---------|----------|--------|------|------|
    13  | **Learning Curve** | Low | High | Medium | Medium |
    14  | **Boilerplate** | Low | High | Medium | Low |
    15  | **Plugin System** | Built-in | External | Limited | Sidecar |
    16  | **Service Discovery** | Yes (mDNS, Consul, etc) | No (BYO) | No | Yes |
    17  | **Load Balancing** | Client-side | No | No | Sidecar |
    18  | **Pub/Sub** | Yes | No | No | Yes |
    19  | **Transport** | HTTP, gRPC, NATS | BYO | gRPC only | HTTP, gRPC |
    20  | **Zero-config Dev** | Yes (mDNS) | No | No | No (needs sidecar) |
    21  | **Production Ready** | Yes | Yes | Yes | Yes |
    22  | **Language** | Go only | Go only | Multi-language | Multi-language |
    23  
    24  ## vs go-kit
    25  
    26  ### go-kit Philosophy
    27  - "Just a toolkit" - minimal opinions
    28  - Compose your own framework
    29  - Maximum flexibility
    30  - Requires more decisions upfront
    31  
    32  ### Go Micro Philosophy
    33  - "Batteries included" - opinionated defaults
    34  - Swap components as needed
    35  - Progressive complexity
    36  - Get started fast, customize later
    37  
    38  ### When to Choose go-kit
    39  - You want complete control over architecture
    40  - You have strong opinions about structure
    41  - You're building a custom framework
    42  - You prefer explicit over implicit
    43  
    44  ### When to Choose Go Micro
    45  - You want to start coding immediately
    46  - You prefer conventions over decisions
    47  - You want built-in service discovery
    48  - You need pub/sub messaging
    49  
    50  ### Code Comparison
    51  
    52  **go-kit** (requires more setup):
    53  ```go
    54  // Define service interface
    55  type MyService interface {
    56      DoThing(ctx context.Context, input string) (string, error)
    57  }
    58  
    59  // Implement service
    60  type myService struct{}
    61  
    62  func (s *myService) DoThing(ctx context.Context, input string) (string, error) {
    63      return "result", nil
    64  }
    65  
    66  // Create endpoints
    67  func makeDo ThingEndpoint(svc MyService) endpoint.Endpoint {
    68      return func(ctx context.Context, request interface{}) (interface{}, error) {
    69          req := request.(doThingRequest)
    70          result, err := svc.DoThing(ctx, req.Input)
    71          if err != nil {
    72              return doThingResponse{Err: err}, nil
    73          }
    74          return doThingResponse{Result: result}, nil
    75      }
    76  }
    77  
    78  // Create transport (HTTP, gRPC, etc)
    79  // ... more boilerplate ...
    80  ```
    81  
    82  **Go Micro** (simpler):
    83  ```go
    84  type MyService struct{}
    85  
    86  type Request struct {
    87      Input string `json:"input"`
    88  }
    89  
    90  type Response struct {
    91      Result string `json:"result"`
    92  }
    93  
    94  func (s *MyService) DoThing(ctx context.Context, req *Request, rsp *Response) error {
    95      rsp.Result = "result"
    96      return nil
    97  }
    98  
    99  func main() {
   100      svc := micro.NewService(micro.Name("myservice"))
   101      svc.Init()
   102      svc.Handle(new(MyService))
   103      svc.Run()
   104  }
   105  ```
   106  
   107  ## vs gRPC
   108  
   109  ### gRPC Focus
   110  - High-performance RPC
   111  - Multi-language support via protobuf
   112  - HTTP/2 transport
   113  - Streaming built-in
   114  
   115  ### Go Micro Scope
   116  - Full microservices framework
   117  - Service discovery
   118  - Multiple transports (including gRPC)
   119  - Pub/sub messaging
   120  - Pluggable components
   121  
   122  ### When to Choose gRPC
   123  - You need multi-language services
   124  - Performance is critical
   125  - You want industry-standard protocol
   126  - You're okay managing service discovery separately
   127  
   128  ### When to Choose Go Micro
   129  - You need more than just RPC (pub/sub, discovery, etc)
   130  - You want flexibility in transport
   131  - You're building Go-only services
   132  - You want integrated tooling
   133  
   134  ### Integration
   135  
   136  You can use gRPC with Go Micro for native gRPC compatibility:
   137  ```go
   138  import (
   139      grpcServer "go-micro.dev/v5/server/grpc"
   140      grpcClient "go-micro.dev/v5/client/grpc"
   141  )
   142  
   143  svc := micro.NewService(
   144      micro.Server(grpcServer.NewServer()),
   145      micro.Client(grpcClient.NewClient()),
   146  )
   147  ```
   148  
   149  See [Native gRPC Compatibility](grpc-compatibility.md) for a complete guide.
   150  
   151  ## vs Dapr
   152  
   153  ### Dapr Approach
   154  - Multi-language via sidecar
   155  - Rich building blocks (state, pub/sub, bindings)
   156  - Cloud-native focused
   157  - Requires running sidecar process
   158  
   159  ### Go Micro Approach
   160  - Go library, no sidecar
   161  - Direct service-to-service calls
   162  - Simpler deployment
   163  - Lower latency (no extra hop)
   164  
   165  ### When to Choose Dapr
   166  - You have polyglot services (Node, Python, Java, etc)
   167  - You want portable abstractions across clouds
   168  - You're fully on Kubernetes
   169  - You need state management abstractions
   170  
   171  ### When to Choose Go Micro
   172  - You're building Go services
   173  - You want lower latency
   174  - You prefer libraries over sidecars
   175  - You want simpler deployment (no sidecar management)
   176  
   177  ## Feature Deep Dive
   178  
   179  ### Service Discovery
   180  
   181  **Go Micro**: Built-in with plugins
   182  ```go
   183  // Zero-config for dev
   184  svc := micro.NewService(micro.Name("myservice"))
   185  
   186  // Consul for production
   187  reg := consul.NewRegistry()
   188  svc := micro.NewService(micro.Registry(reg))
   189  ```
   190  
   191  **go-kit**: Bring your own
   192  ```go
   193  // You implement service discovery
   194  // Can be 100+ lines of code
   195  ```
   196  
   197  **gRPC**: No built-in discovery
   198  ```go
   199  // Use external solution like Consul
   200  // or service mesh like Istio
   201  ```
   202  
   203  ### Load Balancing
   204  
   205  **Go Micro**: Client-side, pluggable strategies
   206  ```go
   207  // Built-in: random, round-robin
   208  selector := selector.NewSelector(
   209      selector.SetStrategy(selector.RoundRobin),
   210  )
   211  ```
   212  
   213  **go-kit**: Manual implementation
   214  ```go
   215  // You implement load balancing
   216  // Using loadbalancer package
   217  ```
   218  
   219  **gRPC**: Via external load balancer
   220  ```bash
   221  # Use external LB like Envoy, nginx
   222  ```
   223  
   224  ### Pub/Sub
   225  
   226  **Go Micro**: First-class
   227  ```go
   228  broker.Publish("topic", &broker.Message{Body: []byte("data")})
   229  broker.Subscribe("topic", handler)
   230  ```
   231  
   232  **go-kit**: Not provided
   233  ```go
   234  // Use external message broker directly
   235  // NATS, Kafka, etc
   236  ```
   237  
   238  **gRPC**: Streaming only
   239  ```go
   240  // Use bidirectional streams
   241  // Not traditional pub/sub
   242  ```
   243  
   244  ## Migration Paths
   245  
   246  See specific migration guides:
   247  - [From gRPC](migration/from-grpc.md)
   248  
   249  **Coming Soon:**
   250  - From go-kit
   251  - From Standard Library
   252  
   253  ## Decision Matrix
   254  
   255  Choose **Go Micro** if:
   256  - ✅ Building Go microservices
   257  - ✅ Want fast iteration
   258  - ✅ Need service discovery
   259  - ✅ Want pub/sub built-in
   260  - ✅ Prefer conventions
   261  
   262  Choose **go-kit** if:
   263  - ✅ Want maximum control
   264  - ✅ Have strong architectural opinions
   265  - ✅ Building custom framework
   266  - ✅ Prefer explicit composition
   267  
   268  Choose **gRPC** if:
   269  - ✅ Need multi-language support
   270  - ✅ Performance is primary concern
   271  - ✅ Just need RPC (not full framework)
   272  - ✅ Have service discovery handled
   273  
   274  Choose **Dapr** if:
   275  - ✅ Polyglot services
   276  - ✅ Heavy Kubernetes usage
   277  - ✅ Want portable cloud abstractions
   278  - ✅ Need state management
   279  
   280  ## Performance
   281  
   282  Rough benchmarks (requests/sec, single instance):
   283  
   284  | Framework | Simple RPC | With Discovery | With Tracing |
   285  |-----------|-----------|----------------|--------------|
   286  | Go Micro | ~20k | ~18k | ~15k |
   287  | gRPC | ~25k | N/A | ~20k |
   288  | go-kit | ~22k | N/A | ~18k |
   289  | HTTP std | ~30k | N/A | N/A |
   290  
   291  *Benchmarks are approximate and vary by configuration*
   292  
   293  ## Community & Ecosystem
   294  
   295  - **Go Micro**: Active, growing plugins
   296  - **gRPC**: Huge, multi-language
   297  - **go-kit**: Mature, stable
   298  - **Dapr**: Growing, Microsoft-backed
   299  
   300  ## Recommendation
   301  
   302  Start with **Go Micro** if you're building Go microservices and want to move fast. You can always:
   303  - Use gRPC transport: `micro.Transport(grpc.NewTransport())`
   304  - Integrate with go-kit components
   305  - Mix and match as needed
   306  
   307  The pluggable architecture means you're not locked in.