DEV Community

Cover image for Entities and Batching Cosmo Connect vs Apollo Federation vs GraphQL Federation
Stefan  🚀
Stefan 🚀

Posted on

Entities and Batching Cosmo Connect vs Apollo Federation vs GraphQL Federation

Federation gives teams a way to build one API layer from many services. The three main options—Apollo Federation, GraphQL Federation (Composite Schemas), and Cosmo Connect—share this goal but solve the problem differently.

Apollo Federation

  • Uses GraphQL subgraphs with @key to define entities.
  • The Router batches lookups through the _entities field.
  • Strong composition checks ensure subgraphs join cleanly.
  • Drawback: every subgraph must be a GraphQL server. Connectors exist for REST, but they can leak backend details into the API contract.

GraphQL Federation (Composite Schemas)

  • Driven by the GraphQL Foundation’s Composite Schemas spec.
  • Keeps GraphQL “vanilla” by using @lookup directives instead of _entities.
  • Pros: federation without Apollo-specific extensions.
  • Cons: entity status is less explicit, and batching is not built in. Routers must alias or send multiple requests.

Cosmo Connect

  • Keeps explicit @key directives, but replaces GraphQL subgraphs with gRPC services.
  • You define SDL, generate a proto, and implement RPCs.
  • Two integration models:
  • Router Plugins (managed processes inside the Router).
  • gRPC Services (independent services with full scaling and ownership).
  • The Router handles batching, retries, auth, and rate limits.
  • gRPC contracts are strict and batch-friendly by default.

Batching Compared

  • Apollo Federation: _entities gives built-in batching.
  • GraphQL Federation: @lookup requires manual batching strategies.
  • Cosmo Connect: gRPC RPCs accept lists of keys, batching is automatic.

Conclusion

All three approaches aim to build a unified API layer with entities. Apollo Federation relies on _entities, GraphQL Federation uses @lookup, and Cosmo Connect compiles SDL into strict gRPC contracts. The tradeoffs lie in how entities are defined and how batching is handled.

Developers often ask the same practical questions when starting with Connect. Here are the most common ones:

FAQs

What’s the difference between Apollo Federation and GraphQL Federation? Apollo Federation adds _entities, _Any, and @key. GraphQL Federation avoids these and uses @lookup.

When should I use Cosmo Connect instead of GraphQL subgraphs? If you want federation without GraphQL servers. Connect compiles SDL to gRPC contracts, and the Router manages platform concerns.

Does Cosmo Connect work with REST APIs and SDKs? Yes. Implement RPCs that call REST or SDKs. The Router provides retries, rate limiting, and auth.

How does batching differ across the three? Apollo Federation batches with _entities. GraphQL Federation needs router-side batching. Cosmo Connect includes batch-capable gRPC methods out of the box.

This post is a condensed summary. The full blog with code examples and history is published on the WunderGraph blog.

Top comments (0)