What is a gRPC interceptor?
Answer
A gRPC interceptor is middleware that intercepts RPC calls on the client or server side, similar to HTTP middleware. Interceptors allow cross-cutting concerns to be implemented once and applied globally. Server-side interceptors: UnaryInterceptor intercepts unary calls, StreamInterceptor intercepts streaming calls. Common uses: authentication (validate tokens), authorization (check permissions), logging (log request/response/duration), rate limiting, request validation, distributed tracing (inject trace IDs), and caching. In Go: grpc.NewServer(grpc.UnaryInterceptor(myInterceptor)). Client-side interceptors (called dialers) intercept outgoing calls — useful for adding auth tokens, retrying failed calls, or adding tracing headers. Multiple interceptors are chained using interceptor chain utilities like grpc_middleware.ChainUnaryServer(...interceptors).