API / Microservices Design Patterns Interview Questions
What is the API Gateway pattern and what responsibilities should it have versus a BFF?
The API Gateway is a single entry point that sits between external clients and the internal microservice topology. Rather than exposing each service's API directly to the internet, all traffic flows through the gateway. It handles cross-cutting concerns so that individual services do not have to implement them repeatedly.
Core gateway responsibilities:
- Request routing — maps an inbound URL/path to the appropriate downstream service endpoint.
- Authentication and authorisation — validates JWT tokens or API keys, optionally enriches the request with user identity claims before forwarding.
- SSL/TLS termination — terminates HTTPS at the gateway; downstream traffic on the internal network may use HTTP or mTLS separately.
- Rate limiting and throttling — enforces per-client request budgets to prevent abuse.
- Request/response transformation — rewrites headers, translates between REST and gRPC, aggregates partial responses.
# Example: Kong or Nginx API Gateway routing rule
/api/orders/* → http://order-service:8080
/api/products/* → http://product-service:8081
/api/customers/*→ http://customer-service:8082
A general-purpose gateway serves all client types (mobile, web, third-party) through a single API surface. The Backend for Frontend (BFF) pattern (Q18) splits this into client-type-specific gateways when different clients have materially different needs — mobile needs smaller payloads and fewer fields; web needs richer aggregated responses. Moving client-specific transformation logic into a BFF prevents the general gateway from accumulating ever-growing, client-specific business logic that makes it fragile and slow to change.
The rule of thumb: use a general gateway for cross-cutting platform concerns (auth, SSL, rate limiting). Use a BFF for client-tailored data shaping and aggregation. The two can coexist — the BFF sits behind the general gateway.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
