System ArchitectureFullstack Architect

Explain the architectural approaches to building APIs for integrating internal and external consumers: when to use REST, gRPC, or GraphQL?

Pass interviews with Hintsage AI assistant

Answer.

The choice of API architectural style depends on the type of consumers, data volume, requirements for interface development speed, and scalability.

  • REST is well-suited for open public APIs when simplicity of use, caching, and routing flexibility are needed.
  • gRPC is used when high performance, strict typing, and bidirectional data streaming are required (for example, for microservices within a data center).
  • GraphQL is convenient for APIs with a rich entity hierarchy when the consumer needs to flexibly choose the composition and structure of the data received.

Example of REST controller (Node.js/Express):

app.get('/api/users/:id', function(req, res) { // ... res.json(user); });

Example of gRPC service definition (protobuf):

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

Example of a GraphQL query:

query { user(id: "123") { id name posts { title } } }

Key features:

  • REST: standardized HTTP methods, ease of scaling, weak typing.
  • gRPC: schema strictness, high performance, support for streaming, suitable for internal services.
  • GraphQL: request only necessary data, reduce the number of requests, complexity in implementing authorization and caching.

Tricky questions.

Can GraphQL be used for any corporate APIs?

Not always! GraphQL is good for complex aggregated data, but for simple CRUD interfaces and high load, REST is often simpler and more effective.

Is gRPC suitable for mobile/web clients?

Usually no, gRPC requires support for HTTP/2 and does not integrate with browsers without special proxies, so it is rarely used on the frontend.

Is REST API always easier to version than others?

Not necessarily. Versioning in GraphQL is handled at the schema level, while REST is usually done through changing URIs or headers, which isn’t always convenient for the evolution of complex data schemas.