☁️ Cloud Architecture Patterns

← Back to Gallery
🎯

Backend for Frontend Pattern

Definition

The Backend for Frontend (BFF) Pattern creates separate backend services for different frontend applications or user experiences. Each BFF is tailored to the specific needs of its frontend, providing optimized APIs and data aggregation rather than forcing all clients to use a generic API.

When to Use It

  • Supporting multiple client types (web, mobile, IoT)
  • Different frontends have significantly different needs
  • You want to optimize APIs for specific client experiences
  • Reducing over-fetching or under-fetching of data
  • Teams are organized by frontend platforms
  • Need for client-specific business logic

Pros & Cons

βœ“ Pros

  • Optimized APIs for each client type
  • Reduced payload size for mobile
  • Frontend teams have more autonomy
  • Easier to evolve client-specific features
  • Better separation of concerns
  • Reduced coupling between clients and services

βœ— Cons

  • Code duplication across BFFs
  • More services to maintain
  • Potential inconsistencies between BFFs
  • Increased operational complexity
  • Risk of logic leaking into BFFs
  • More deployment pipelines

Architecture Diagram

Without BFF (Generic API for all clients):
───────────────────────────────────────────

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Web    β”‚  β”‚  Mobile  β”‚  β”‚   IoT    β”‚
β”‚  Client  β”‚  β”‚   App    β”‚  β”‚  Device  β”‚
β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
     β”‚             β”‚             β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
                   β–Ό
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚  Generic API   β”‚ ◄─ One size fits none
          β”‚   Gateway      β”‚    β€’ Over-fetching
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜    β€’ Under-fetching
                   β”‚            β€’ Complex clients
       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
       β–Ό           β–Ό           β–Ό
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ User   β”‚ β”‚Product β”‚ β”‚ Order  β”‚
   β”‚Service β”‚ β”‚Service β”‚ β”‚Service β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜


With BFF (Tailored APIs):
──────────────────────────

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Web    β”‚      β”‚  Mobile  β”‚      β”‚   IoT    β”‚
β”‚  Client  β”‚      β”‚   App    β”‚      β”‚  Device  β”‚
β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
     β”‚                 β”‚                 β”‚
     β”‚ Rich data       β”‚ Optimized       β”‚ Minimal
     β”‚ GraphQL         β”‚ REST/JSON       β”‚ Binary
     β–Ό                 β–Ό                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Web BFF   β”‚  β”‚ Mobile BFF  β”‚  β”‚   IoT BFF   β”‚
β”‚             β”‚  β”‚             β”‚  β”‚             β”‚
β”‚ β€’ Full data β”‚  β”‚ β€’ Small     β”‚  β”‚ β€’ Status    β”‚
β”‚ β€’ Complex   β”‚  β”‚   payloads  β”‚  β”‚   only      β”‚
β”‚   queries   β”‚  β”‚ β€’ Paginationβ”‚  β”‚ β€’ Commands  β”‚
β”‚ β€’ Admin     β”‚  β”‚ β€’ Caching   β”‚  β”‚ β€’ Telemetry β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚                β”‚                β”‚
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β–Ό           β–Ό           β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚ User   β”‚ β”‚Product β”‚ β”‚ Order  β”‚
        β”‚Service β”‚ β”‚Service β”‚ β”‚Service β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜


Example: Product Page Request
──────────────────────────────

Web BFF Response (Rich):
{
  "product": {...},
  "reviews": [...],
  "recommendations": [...],
  "inventory": {...},
  "pricing": {...},
  "seller": {...}
}

Mobile BFF Response (Optimized):
{
  "product": {
    "id": "123",
    "name": "...",
    "price": 29.99,
    "image": "thumbnail_url"
  },
  "rating": 4.5,
  "inStock": true
}

IoT BFF Response (Minimal):
{
  "id": "123",
  "price": 29.99,
  "available": 1
}

Key Principles:
β€’ Each BFF owned by frontend team
β€’ Business logic stays in services
β€’ BFF handles aggregation & formatting
β€’ Keep BFFs thin (avoid duplication)