Sobes.tech
Senior

Can you describe how you designed and implemented REST and gRPC APIs for internal and external platform services?

sobes.tech AI

Answer from AI

When designing REST and gRPC APIs for internal and external platform services, I based my approach on separation of responsibilities and requirements for performance and ease of integration.

For REST API:

  • Used clear resource-oriented design with understandable URLs and HTTP methods (GET, POST, PUT, DELETE).
  • Applied JSON standards for data exchange, ensuring validation and error handling with understandable status codes.
  • For external services, added authentication (e.g., OAuth2 or JWT) and rate limiting.

For gRPC API:

  • Defined services and methods in protobuf with clear message types.
  • Used gRPC for high-performance communication between internal services, where speed and binary protocol are important.
  • Implemented streaming where large data transfer or persistent connection is needed.

Example of a simple gRPC service in Go:

syntax = "proto3";

service UserService {
  rpc GetUser (UserRequest) returns (UserResponse);
}

message UserRequest {
  string user_id = 1;
}

message UserResponse {
  string name = 1;
  string email = 2;
}

In Go, I implement a server with a GetUser handler that receives user_id and returns user data.

This approach allows using REST for external clients with a convenient and understandable interface, and gRPC for internal services with high performance and strict typing.