Part 24 · Applications

REST, GraphQL, gRPC and hypermedia

Prerequisites: 01-ecosystem

How does GraphQL avoid repeated owner loads?

GraphQL selection: policies + owners; Field resolvers: owner keys; DataLoader: batch within request; Backing service: bounded lookup. Connections: GraphQL selection to Field resolvers (execute fields); Field resolvers to DataLoader (collect loads); DataLoader to Backing service (batch lookup)
One GraphQL mechanism. REST and gRPC are contract alternatives, not stages of this flow. [S46] [S47] [S62]

Goal & mental model verified

API styles expose different contracts. REST centers resources and HTTP semantics; GraphQL executes a schema-selected field graph; gRPC defines RPC services/messages. Spring HATEOAS helps express links and affordances in representations.

[S46] [S47]

Worked example · design exercise synthesis

A broker dashboard asks GraphQL for policies and owners. Request-scoped DataLoader batching can collect owner IDs, reducing repeated lookups without turning the API into one unrestricted database query.

[S46] [S47] [S62]

Engineering decision synthesis

Choose REST for familiar interoperable resource APIs, GraphQL for client-shaped graphs, and gRPC for typed RPC requirements. Consider client support, evolution, authorization and observability alongside payload size.

[S46] [S47] [S62]

Pitfall & diagnosis synthesis

GraphQL can hide N+1 fetching and expensive query shapes. Changing transport does not supply per-field/resource permissions. Hypermedia links should reflect permitted actions rather than grant authority themselves.

[S46] [S47] [S62]

Improve & validate synthesis

Measure query cost and downstream calls. Enforce workload limits and compatible contract evolution; keep authentication, authorization and deadline behavior explicit for each transport.

[S46] [S47] [S62]
Keep this: Transport changes the contract shape; business rules still need enforcement.
Check yourself: Does DataLoader guarantee one query for the entire request?

No. It batches compatible loads; actual queries depend on keys, resolvers and backing implementation.

Sources & further reading

  1. [S46] GraphQL request execution

    Spring project maintainers · documentation · accessed 2026-10-09 · Documentation retrieved 2026-10-09

    Supports: Schema execution; DataLoader per-request batching

    Read the linked section to validate the mechanism and its version-specific constraints.

  2. [S47] Spring gRPC

    Spring project maintainers · documentation · accessed 2026-10-09 · Documentation retrieved 2026-10-09

    Supports: Spring-friendly gRPC integrations

    Read the linked section to validate the mechanism and its version-specific constraints.

  3. [S62] Spring HATEOAS

    Spring project maintainers · documentation · accessed 2026-10-09 · Documentation retrieved 2026-10-09

    Supports: Representation models; Links and affordances

    Read the linked section to validate the mechanism and its version-specific constraints.