In this challenge, you will implement a microservice architecture using gRPC concepts for service-to-service communication. You'll create a User service and a Product service that communicate to provide an order management system.
- Understand microservices architecture principles
- Learn gRPC concepts and error handling
- Implement service-to-service communication
- Practice with gRPC interceptors for cross-cutting concerns
- Handle network-based service interactions
Implement the following TODO methods in solution-template.go:
UserServiceServer.GetUser(): Retrieve user by ID with proper error handlingUserServiceServer.ValidateUser(): Check if user exists and is activeProductServiceServer.GetProduct(): Retrieve product by ID with proper error handlingProductServiceServer.CheckInventory(): Check product availability
OrderService.CreateOrder(): Orchestrate user validation, product checking, and order creation
StartUserService(): Set up and start the user service with interceptorsStartProductService(): Set up and start the product service with interceptorsConnectToServices(): Create clients and connect to both services
UserServiceClient.GetUser(): Make gRPC calls to user serviceUserServiceClient.ValidateUser(): Make gRPC calls for user validationProductServiceClient.GetProduct(): Make gRPC calls to product serviceProductServiceClient.CheckInventory(): Make gRPC calls for inventory checking
LoggingInterceptor: Log method calls and execution timeAuthInterceptor: Add authentication metadata to requests
- gRPC Status Codes: Use appropriate status codes (NotFound, PermissionDenied, etc.)
- Service Interfaces: Clean separation between service logic and transport
- Network Communication: Real service-to-service calls
- Error Propagation: Proper error handling across service boundaries
- Interceptors: Cross-cutting concerns like logging and authentication
- Microservices Patterns: Service orchestration and coordination
- Use
status.Errorf()to return proper gRPC errors - Remember to handle both business logic errors and network errors
- Services should validate inputs and return appropriate error codes
- The OrderService orchestrates calls to both User and Product services
- Interceptors wrap all service calls for logging/auth
go test -vThe tests will:
- Start individual services and test their functionality
- Test service-to-service communication through OrderService
- Verify proper error handling for various scenarios
- Check that interceptors work correctly
codes.OK: Successful operationcodes.NotFound: Resource doesn't existcodes.PermissionDenied: User not authorizedcodes.ResourceExhausted: Insufficient inventorycodes.InvalidArgument: Invalid input parameters
Complete all TODO methods to make the tests pass!