markdown共有ツール

REST vs gRPC vs GraphQL: Choosing an API Style#

Interviewers often ask which API style you would use between services or for a client app. Each has a sweet spot.

REST over HTTP and JSON#

Resources with URLs, standard verbs (GET, POST, PUT, DELETE), status codes, and JSON bodies.
Strengths: universal tooling, easy to debug with curl, HTTP caching and CDNs work naturally, great for public APIs.
Weaknesses: over-fetching or under-fetching (several round trips to assemble a screen), loosely defined contracts unless you add OpenAPI, verbose JSON.

gRPC#

Remote procedure calls defined in Protocol Buffers, sent over HTTP/2.
Strengths: compact binary encoding, generated type-safe clients in many languages, built-in deadlines, streaming in both directions, strong schema evolution rules via field numbers. Excellent for internal service-to-service calls with high traffic.
Weaknesses: not browser-native (needs gRPC-Web or a proxy), harder to inspect by hand, HTTP caching does not apply, load balancers must understand long-lived HTTP/2 connections.

GraphQL#

Clients send a query describing exactly the fields they need; one endpoint resolves it from many backends.
Strengths: one round trip per screen, no over-fetching, strongly typed schema, ideal for many different front ends evolving quickly.
Weaknesses: caching is harder (mostly POST to one URL), expensive queries need depth limits and cost analysis, N+1 resolver problems need batching (data loaders), and authorization must be enforced per field.

A practical split#

  • Public developer API: REST with OpenAPI.
  • Internal microservice calls with tight latency budgets: gRPC.
  • Backend-for-frontend serving web and mobile apps with varied screens: GraphQL or a REST BFF.

Many companies use all three: GraphQL at the edge, gRPC inside, REST for partners.

Interview tip#

Do not argue that one style is best. Pick based on the consumer (browser, partner, internal service), the latency budget and how fast the client's data needs change, and say why.

Linkjob AI (https://www.linkjob.ai/) - I'm on the team; we build an AI assistant for technical interviews.