Tutorials Microservices Mastery

BFF Pattern: Backend-for-Frontend (Mobile vs Web)

On this page

The BFF Pattern

A desktop website has a giant screen and a high-speed fiber connection. A mobile app has a tiny screen and a spotty 3G connection. Sending the exact same massive JSON to both is a waste. The Backend-for-Frontend (BFF) pattern creates specialized gateways for each type of device.

1. Why use specialized gateways?

  • Mobile BFF: Strips out unnecessary data to save cellular bandwidth. Returns smaller images. Uses long-polling or WebSockets for battery efficiency.
  • Web BFF: Returns full, high-fidelity metadata. Handles complex session cookies.
  • External API BFF: Strictly rate-limited and documented for third-party partners.

2. Separation of Concerns

The BFF pattern prevents your internal microservices from being "Polluted" with UI concerns. Your User service should just return user data; it shouldn't have to care if the Caller wants a 'Mobile View' or a 'Admin View'.

4. Interview Mastery

Q: "How does the BFF pattern improve security for Single Page Applications (SPA)?"

Architect Answer: "The BFF allows you to implement the **'Same-Site Cookie'** strategy. Instead of the browser (Javascript) handling sensitive JWT tokens, the BFF handles the OIDC login. It stores the token in an **Http-Only, Secure, Same-Site cookie**. The browser's Javascript never sees the token, making it 100% immune to Cross-Site Scripting (XSS) token-theft attacks. The BFF acts as a secure 'Bridge' between the untrusted browser and the trusted internal microservice network."

Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

Microservices Mastery
Course syllabus
1. Distributed Systems Fundamentals
2. Containerization & Orchestration
3. Service Communication
4. Event-Driven Architecture
5. Resilience & Scalability
6. Observability & Security
7. Advanced Cloud Topics
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details