How lukasz-antoniak/grpc-etcd works
Main components
• gRPC Server:
• Represents the primary service endpoint.
• Uses a “ListenableServerState” (see classes like ListenableServerStateImpl and ServerStateListener) to decorate the gRPC server lifecycle.
• Integrates with ETCD by notifying server startup and shutdown events.
• ETCD Cluster:
• An external service discovery/data store that holds the service keys and configuration.
• Stores both service configuration (as JSON) and each service endpoint key registered by running servers.
• gRPC Client:
• Configured to use a custom NameResolverProvider (i.e., EtcdNameResolverProvider) that connects to ETCD.
• Uses the resolved endpoint data and service configuration for client-side load balancing.
• ETCD Service Registry & Name Resolver:
• On the server side, the EtcdServiceRegistry is responsible for registering/deregistering service instances in ETCD.
• On the client side, the EtcdNameResolver handles querying ETCD for updates on available service endpoints.
Relationships and interactions
• Server Lifecycle & Registration:
• When a server starts, the ListenableServerState is used to listen for server lifecycle events.
• The server notifies its ETCD service registry (EtcdServiceRegistry) upon startup, which writes its endpoint key (using the common keyPrefix) to ETCD.
• When the server shuts down, the service is deregistered similarly.
• Client Service Discovery:
• The client initializes by registering the EtcdNameResolverProvider with the gRPC NameResolverRegistry.
• It then builds a ManagedChannel that targets the “etcd://…” URI.
• The custom NameResolver polls ETCD for active service instances and updates the client channel with changes.
• Data Flow:
Important architectural patterns and design principles
• Separation of concerns is evident: the server handles its own registration via lifecycle events, while the client is agnostic about server details and relies on ETCD for endpoint resolution.
• The “lookaside” load balancing pattern is central: ETCD acts as an intermediary for service discovery.
• There is a clear distinction between control and data flow—server branches are responsible for registering with ETCD, and client branches for resolving endpoints based on dynamically updated ETCD keys.
• The system uses a modular design where ETCD-based functionality is encapsulated in dedicated components such as EtcdServiceRegistry, EtcdNameResolver, and their providers.
Relevant technologies and frameworks
• Java (as the programming language)
• gRPC (for both server and client communication)
• ETCD (as the service discovery mechanism)
• Maven (as the build and dependency management tool)
• Additional libraries or frameworks like the ETCD client library used to connect to an ETCD cluster
Final advice for the principal software engineer
• Be detailed in capturing each individual component that plays a role in the load balancing system.
• Don’t oversimplify; include the internal interaction between lifecycle management and service registration, as well as the client’s use of a custom NameResolver.