Categorygithub.com/authzed/consistent
modulepackage
0.1.0
Repository: https://github.com/authzed/consistent.git
Documentation: pkg.go.dev

# README

consistent

GoDoc Discord Server Twitter

This package implements a gRPC Balancer that routes requests based upon a consistent hashring. The hashing algorithm is customizable, but xxhash is recommended. It was originally built to serve SpiceDB, but has been extracted from that repository to be made available for other projects.

In order to use this balancer, you must:

  1. Register the balancer (typically in main):
balancer.Register(consistent.NewBuilder(xxhash.Sum64))
  1. Configure the connections:
// This is using the defaults, but you can create your own config.
grpc.Dial(addr, grpc.WithDefaultServiceConfig(consistent.DefaultServiceConfigJSON))

Acknowledgements

This project is a community effort fueled by contributions from both organizations and individuals. We appreciate all contributions, large and small, and would like to thank all those involved.

A large portion of the structure of this library is based off of the example implementation in grpc-go. That original work is copyrighted by the gRPC authors and licensed under the Apache License, Version 2.0.

# Packages

Package hashring implements a thread-safe consistent hashring with a pluggable hashing algorithm.

# Functions

NewBuilder allocates a new gRPC balancer.Builder that will route traffic according to a hashring configured with the provided hash function.

# Constants

BalancerName is the name used to identify this implementation of a consistent-hashring balancer to gRPC.
CtxKey is the key that will be present in each gRPC request's context that points to the value that will be hashed in order to map the request to the hashring.
DefaultReplicationFactor is the value that will be used when parsing a service config provides an invalid value.
DefaultSpread is the value that will be used when parsing a service config provides an invalid value.

# Variables

DefaultServiceConfigJSON is a helper to easily leverage the defaults.

# Structs

BalancerConfig exposes the configurable aspects of the balancer.

# Interfaces

Builder combines both of gRPC's `balancer.Builder` and `balancer.ConfigParser` interfaces.