gRPC connects distributed services through remote procedure calls, carrying lightweight Protocol Buffers messages over HTTP/2. Define messages and service endpoints in .proto files, then generate language-specific clients and server interfaces. section 10.0 section 10.1
A practical gRPC service typically combines:
- A language-neutral API defining request messages, response messages, and callable endpoints. section 10.1
- Generated Go interfaces and structures that connect the API definition to implementation code. section 10.1
- An API layer that converts transport-specific values into domain objects and maps domain results back into responses. section 10.3.2
- Status-code-based error handling, returning InvalidArgument for bad input and Internal for unexpected failures. section 10.3.2
- Context propagation, integration tests, dependency injection, and small interfaces to keep service behavior testable. section 10.0 section 10.8
Habits service
A habits tracker exposes CreateHabit, ListHabits, TickHabit, and GetHabitStatus. A client can call CreateHabit with grpcurl using a JSON request, while the server validates the input, invokes domain logic, and returns a generated response or standardized status error. section 10.0 section 10.3.2 section 10.3.2
Listing 10.1 Habits service API
// Habits is a service for registering and tracking habits.
type HabitsService interface {
// CreateHabit is the endpoint that registers a habit.
CreateHabit(CreateHabitRequest) (CreateHabitResponse, error)
// ListHabits is the endpoint that returns all habits.
ListHabits(ListHabitsRequest) (ListHabitsResponse, error)
// TickHabit is the endpoint to tick a habit.
TickHabit(TickHabitRequest) (TickHabitResponse, error)
// GetHabitStatus is the endpoint to retrieve
// the status of ticks of a habit.
GetHabitStatus(GetHabitStatusRequest) (GetHabitStatusResponse, error);
}
Inspect the service contract showing request and response types for the four habits endpoints. section 10.1









