liveBook · Manning

Backend-for-frontend pattern

As explained in Python Concurrency with asyncio

A backend-for-frontend service is a service dedicated to making backend calls and aggregating responses for a particular type of frontend client.

A backend-for-frontend service sits between a frontend client and multiple backend services. It makes the downstream calls, aggregates their responses, and presents one client-specific API. This reduces network round trips and keeps shared aggregation, retry, and failover logic out of web and mobile clients. section 10.2

The pattern helps when a frontend depends on several independent services:

  • Aggregate product, inventory, cart, and favorites data into one storefront response. section 10.3 section 10.3.1
  • Tailor separate backend-for-frontend services to different client types, such as web and mobile interfaces. section 10.2
  • Short-circuit slow or failed dependencies so clients receive usable partial data instead of waiting indefinitely. section 10.3.3

E-commerce product listing

A desktop storefront requests products, inventory, cart count, and favorite count through one API. Product data must arrive within one second; cart, favorites, and inventory are optional. The response can therefore contain product data while representing unavailable counts as null, preserving a usable page during downstream failures. section 10.3.3

Figure 10.1 The backend-for-frontend pattern
10-01

Use the architecture diagram to trace the client-specific service between frontend clients and the downstream microservices it aggregates. section 10.2

How Python Concurrency with asyncio covers it

How deep it goes
Defines the pattern and implements a product listing service with concurrent requests, timeouts, optional data, retries, and circuit breaking.
Examples
Uses an e-commerce product page combining product, inventory, cart, and favorite-service responses.
What it assumes
Assumes familiarity with web applications and services while motivating microservices through monolith deployment and scaling concerns.
What you can do after
Build a resilient aggregated API with asyncio and aiohttp, including bounded waits and partial responses.
How it connects
Connects microservices with concurrency, HTTP retries, and the circuit breaker pattern.

Also explained in

Compare how 4 books explain backend-for-frontend pattern →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Python Concurrency with asyncio. The section links point to the parts of the book it draws on.