RealComposer
Architecture Comparison

API Composition (BFF) vs API Gateway

Direct Answer

An API gateway sits in front of your services to route, authenticate, and rate-limit requests, usually passing each request to one backend. An API composition layer, often called a Backend for Frontend, calls several upstream APIs in parallel and returns one merged, client-shaped response. Gateways solve traffic management; composition solves chatty clients and payload shape. Many teams run both.

API composition (BFF)

One endpoint per screen or client that fans out to several APIs, merges the results, and returns only the fields that client needs.

API gateway

A front door that routes each request to a backend service and applies auth, quotas, and logging.

Side-by-Side Comparison

DimensionAPI composition (BFF)API gateway
Primary jobMerge and reshape responses for a clientRoute, authenticate, and throttle traffic
Calls per client requestMany upstream calls, in parallelUsually one backend per route
Response shapeTailored to the screenWhatever the backend returns
Third-party APIsFirst-class, with vaulted credentialsPossible, but focused on your own services
Effect on mobile latencyRemoves sequential round tripsNeutral; client still makes each call

Choose API composition (BFF) when

  • A single screen needs data from several APIs.
  • Mobile clients suffer from network waterfalls.
  • You integrate third-party APIs more than internal services.

Choose API gateway when

  • You expose many internal microservices and need one policy layer.
  • Your main problem is auth, quotas, and routing, not response shape.

Frequently Asked Questions

Can an API gateway do composition?

Some gateways support basic aggregation plugins, but they are built for routing and policy. Complex merging, field mapping, and per-client shaping are easier in a dedicated composition layer.

Should the BFF sit behind or in front of the gateway?

Commonly in front: clients call the BFF, which calls internal services through the gateway and third-party APIs directly with injected secrets.

Recipes That Apply This Pattern

Sources & Definitions Used in This Answer

Try the edge approach on your own APIs

Clone a recipe, add your upstream keys to the vault, and call one endpoint from your client.

BROWSE RECIPES