Microservices Mastery
Lesson 13 of 30 43% of course

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

17 · 8 min · 5/23/2026

Sign in to track progress and bookmarks.

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."

Test your knowledge

Quizzes linked to this course—pass to earn certificates.

Browse all quizzes
Microservices Mastery

On this page

1. Why use specialized gateways? 2. Separation of Concerns 4. Interview Mastery
1. Distributed Systems Fundamentals
Monolith vs Microservices: When to migrate? The 12-Factor App Methodology for Cloud-Native Apps Database Per Service: Handling distributed data consistency
2. Containerization & Orchestration
Docker Essentials: Building efficient .NET images Docker Compose: Orchestrating a multi-service environment Kubernetes Architecture: Pods, Services, and Deployments K8s ConfigMaps & Secrets: Managing environment variables Helm Charts: Packaging your microservices for K8s
3. Service Communication
Synchronous vs Asynchronous Communication: Pros and Cons REST APIs in a Microservices World: Best Practices Mastering gRPC: High-performance binary communication API Gateways: Implementing Ocelot for single-entry access BFF Pattern: Backend-for-Frontend (Mobile vs Web)
4. Event-Driven Architecture
Message Brokers: Introduction to RabbitMQ & Azure Service Bus Pub/Sub Pattern: Implementing MassTransit for .NET The Outbox Pattern: Ensuring 100% data consistency Dead Letter Queues: Handling message failure gracefully Distributed Transactions: The Saga Pattern (State Machines)
5. Resilience & Scalability
Distributed Caching with Redis: Optimizing global state Service Discovery: IdentityServer4 & Consul Load Balancing: Nginx vs Ingress Controllers The Sidecar Pattern: Offloading cross-cutting concerns
6. Observability & Security
Distributed Logging with Serilog & SEQ Distributed Tracing: OpenTelemetry & Jaeger Health Checks: Monitoring system vitals in real-time OAuth2 & OpenID Connect: Centralized Identity (AuthN/AuthZ) Rate Limiting & Throttling: Protecting your services
7. Advanced Cloud Topics
Infrastructure as Code (IaC): Introduction to Terraform CI/CD Pipelines for Microservices (GitHub Actions/Azure DevOps) C# Architect Interview: Microservices & System Design Focus