SkillSprout
Chapter 10 · Lesson 2
Intermediate
4 min read

Gateway vs Load Balancer, the BFF Pattern and Pitfalls

Overview

A gateway, a reverse proxy and a load balancer all sit in front of servers, so they are easy to mix up. This lesson separates them, introduces the Backend for Frontend (BFF) pattern, and lists the traps that make gateways painful.

Detailed Notes

What is the difference

All three sit between clients and servers, and real products overlap (NGINX can be all three). The useful split:

ComponentMain jobTypical features
Reverse proxyFront servers, hide them, forward requestsTLS termination, compression, basic routing
Load balancerSpread traffic across identical copies of a serviceAlgorithms, health checks, failover
API gatewayManage an API across different servicesAuth, quotas, API keys, aggregation, analytics

Rule of thumb: load balancer = which copy of a service; gateway = which service, and are you allowed. A gateway often forwards to a load balancer sitting in front of each service.

The problem it solves

Different clients want different things. A phone wants small, trimmed responses; a web dashboard wants rich data; a partner wants a stable public API. One shared set of endpoints ends up awkward for all of them. Also, a gateway that does too much becomes a problem of its own.

How it works

Backend for Frontend (BFF): a small backend layer built for one type of client (web, mobile, partners). It calls several services, merges and trims the data for that client, and is owned by that client's team. The shared gateway stays thin (auth, limits, routing) and routes to the right BFF.

The flow: client calls the gateway, the gateway routes to the mobile BFF, the BFF calls several domain services in parallel, merges the results, and returns one tailored response.

A related alternative is GraphQL: one endpoint where clients ask for exactly the fields they need.

Gateway vs service mesh: a gateway handles client-to-system traffic at the edge. A service mesh handles service-to-service traffic inside the system, using small proxies next to each service for encryption, retries and telemetry. Large systems often have both.

Common pitfalls

  • Single point of failure: gateway down means everything is down. Run several instances across zones, or use a managed service.
  • Bloat ("god gateway"): business logic creeps in and every team edits it. Keep it to cross-cutting concerns.
  • Bottleneck: heavy transformations slow every call. Keep policies light and scale horizontally.
  • Shared blast radius: one bad config breaks every API. Roll out changes in stages.
  • Chatty aggregation: fanning out to many services multiplies latency and failure chances. Call in parallel, set timeouts, and return partial results if needed.

A simple example

A restaurant chain has one main entrance (gateway). Inside, there is a kids' menu desk, a bar desk and a takeaway desk (BFFs), each shaping the experience for one kind of visitor. The kitchen (services) is the same for all.

System design example

A video app has web, mobile and TV clients. The edge gateway handles TLS, login and rate limits, then routes to a BFF per client. The mobile BFF fetches profile, watch history and recommendations in parallel, with a 300 ms timeout on recommendations (it returns the rest if they are slow). Each domain service sits behind its own load balancer. A small internal-only system may need only a reverse proxy; add layers only when the problem appears, since each layer adds latency and something to operate.

Summary

  • Load balancer picks a copy of a service; gateway picks the service and enforces policy.
  • A BFF tailors responses for one client type and keeps the gateway thin.
  • Gateway = client-to-system traffic; service mesh = service-to-service traffic.
  • Avoid single points of failure, bloat and chatty aggregation.

Architecture Diagram

Gateway, BFFs and services
Architecture
Clients
Gateway
BFF
Load Balancer
Services

A thin gateway routes to per-client BFFs, which call services behind load balancers.

  1. 1The gateway authenticates, limits and routes.
  2. 2A BFF tailors the response to the client.
  3. 3Load balancers spread traffic across service instances.

Common Interview Questions

Chapter quiz

API Gateway · 5 questions

  1. 1.What is the main purpose of an API gateway?

  2. 2.Which is a typical gateway responsibility?

  3. 3.Authentication answers which question?

  4. 4.What does TLS termination do?

  5. 5.A load balancer differs from a gateway because it:

0 of 5 answered

Finished this lesson?

0 of 91 lessons done · 0% of the course