Backend for Frontend (BFF) pattern
Trace BFF adoption and naming, then follow this website's architecture and UML through its web proxy, BFF cache, and content service.
· Last updated: 2026-11-05 · 10 min read
Overview
A Backend for Frontend (BFF) is a server layer that exposes an API shaped specifically for one frontend experience. Built and owned by the same team that owns the UI, it takes requests from the screen, calls whichever downstream services are needed, and assembles the exact payload that interface wants.1
Origins and history
2013 · SoundCloud engineering team: Moved away from a single public API shared across web, mobile, and external integrations toward dedicated APIs per client experience. SoundCloud dates this shift to 2013 in its 2021 retrospective.2
Early development at SoundCloud · Nick Fisher: As web tech lead at the time, Fisher coined the name BFF, as Phil Calçado later recorded in his 2015 write-up.3
September 18, 2015 · Phil Calçado: Published the development history and explained why screen responses moved from client assembly into the backend.3
November 18, 2015 · Sam Newman: Described the pattern and team responsibilities using examples from REA and SoundCloud.4
When you only have one website, tailoring the server API to its screens is easy. Trouble starts once mobile apps and third-party integrations join in: even when they read the same underlying tables, a rich desktop view, a stripped-down mobile screen, and an external partner feed need very different payloads, so forcing all three through a single general-purpose API leaves every team waiting in the same bottleneck queue.
Thoughtworks' December 2015 case study on SoundCloud captures that daily friction well. Shipping a new mobile screen meant convincing a separate core-API team to prioritize and build a new endpoint; giving the frontend team its own BFF let them fetch and shape responses on their own schedule.5
How this website's architecture uses a BFF
Personal note: My own website, MAKONEA, also uses a BFF.
On this website, apps/bff-edge sits in front of the web client. When a public post-list request arrives, the BFF validates the locale and query parameters, checks its in-memory cache, and calls content-svc on a miss, leaving visibility filtering and post-list assembly to the content service.
Rendering a blog card takes three things: a title, a short summary, and an estimated reading time. Rather than querying database rows from the browser, the client asks the public list API for a post count and content type; walking through that call shows where each server boundary sits and what each layer owns.
GET /api/public/blog/ko?type=post&limit=10From the browser, the request hits the same-origin Next.js API proxy, which forwards it to the BFF, and the BFF maps it onto /v1/public/posts/ko on the content service. Server-side rendering can call the BFF URL directly, though the UML diagrams below trace the full browser-to-proxy path.
Component structure in UML
In the component diagram, dashed arrows point from caller to dependency: the web app, BFF, and content service run as distinct components, publicCacheStore lives in memory inside the BFF process, and only content-svc touches the database.6
The request sequence in UML
The sequence diagram traces a cache MISS. After content-svc returns the post list, the BFF applies its caching rules and hands the response back through the Next.js proxy; on a cache HIT, the BFF serves the stored payload immediately and never calls content-svc.
Code flow 1: Building query options in the web app
On the web side, fetchPublicBlog packs the locale, content type, and page size into the query string, while withBffBase picks the right base URL for browser versus server execution and withServerFetchTimeout bounds server-side wait time.
export async function fetchPublicBlog(
locale: string,
type?: 'post' | 'project' | 'casual' | 'memo' | 'lab',
init?: FetchInit,
opts: { limit?: number; offset?: number; category?: string; preview?: boolean } = {},
) {
const params = new URLSearchParams();
if (type) params.set('type', type);
if (opts.limit !== undefined) params.set('limit', String(opts.limit));
if (opts.offset !== undefined) params.set('offset', String(opts.offset));
if (opts.category) params.set('category', opts.category);
if (opts.preview) params.set('preview', '1');
const qs = params.toString() ? `?${params.toString()}` : '';
return fetch(withBffBase(`/api/public/blog/${locale}${qs}`), withServerFetchTimeout(withPublicContentTag(init)));
}Code flow 2: Caching and service calls in the BFF
Just before the snippet below runs, the route validates incoming parameters against localeParamSchema and publicPostListQuerySchema. Those validated values, locale, type, category, page offset, and preview flag, form the cache key so distinct queries never collide, and the callback inside forwardWithCache hits the content service only when no cached response is available.
const cacheKey = `list:${locale}:${type ?? 'any'}:${category ?? 'any'}:${offset ?? '0'}:${limit ?? 'default'}:preview=${preview ? '1' : '0'}`;
return await config.forwardWithCache(
'posts',
cacheKey,
BFF_CACHE_TTL.blogList,
async () => {
const res = await config.safeFetch(`${config.contentSvcUrl}/v1/public/posts/${encodeURIComponent(locale)}${qs}`, {
headers: config.withInternalAuthHeaders(),
});
if (!res.ok) {
config.log.warn({
event: 'PublicBlogList_DependencyFailed',
stage: 'CallDependency',
error: res.error.code,
});
return safeJsonErrorResponse('UPSTREAM_ERROR', 502);
}
return res.value;
},
{ validatePayload: requireNonEmptyObjectArrayFieldPayload('posts') },
);If safeFetch reports a network failure, this branch returns UPSTREAM_ERROR with HTTP 502 instead of throwing. withInternalAuthHeaders() attaches service-to-service credentials, and validatePayload verifies the posts array before anything enters the cache.
Code flow 3: Preparing the list response in the content service
Inside content-svc, the repository selects rows where status='published', and the controller code below computes reading time from the markdown body before stripping the body field out of the list response. Reading-time calculation belongs to the content service on this path.
const withReadingTime = result.value.posts.map((post: any) => {
const { content, ...rest } = post;
const readingSource = content || [
post.summary_title,
post.summary_text,
post.description,
post.title,
].filter((value) => typeof value === 'string' && value.trim()).join(' ');
const interactivePreview = preview
? post.content_type === 'lab'
? extractPublicLabPreview(content, post.lab_thumbnail_index)
: extractPublicShaderPreview(content)
: null;
return {
...rest,
...(interactivePreview ? { interactive_preview: interactivePreview } : {}),
reading_time: calculateReadTime(readingSource || ''),
};
});
reply.send({ posts: withReadingTime, total: result.value.total });Response shaping for this route finishes inside content-svc; the BFF's job is input validation, caching, and upstream error translation.
Responsibilities by layer
Part | Responsibility in the public post list path |
|---|---|
Browser and apps/web | Display cards and build query options; provide the API proxy for browser calls. |
apps/bff-edge | Validate inputs and manage public-response caching and content-service calls. |
content-svc | Read published posts; return the list without bodies, reading times, and total count. |
PostgreSQL | Store post status and content. |
- Part
Browser and apps/web
- Responsibility in the public post list path
Display cards and build query options; provide the API proxy for browser calls.
- Part
apps/bff-edge
- Responsibility in the public post list path
Validate inputs and manage public-response caching and content-service calls.
- Part
content-svc
- Responsibility in the public post list path
Read published posts; return the list without bodies, reading times, and total count.
- Part
PostgreSQL
- Responsibility in the public post list path
Store post status and content.
How does a BFF differ from an API Gateway? A gateway handles cross-cutting edge concerns, TLS, auth, rate limiting, routing, across all clients, whereas a BFF shapes payloads for one specific client experience, so a deployment might place several BFFs behind a shared gateway, merge both roles in a smaller setup, or implement the BFF as a GraphQL server with client-specific resolvers.1
Boundaries to maintain in operation
A BFF that starts out stitching a few payloads together can quietly accumulate domain rules over time. SoundCloud's 2021 retrospective warns that when business logic creeps into BFFs sitting above thin CRUD services, those rules get copy-pasted and gradually drift apart across clients; once a shared domain concept appears, extract it into a downstream service and keep the BFF focused on presentation composition.2
Watch cache invalidation and failure semantics at this boundary too. Switching a post from public to private requires coordinated invalidation across both the BFF's JSON cache and the web app's HTML cache, and when a downstream service fails, the BFF must return an explicit error code rather than papering over the outage with a fake empty list.
Deciding whether to introduce a BFF
When does a BFF pay for itself? Whenever web and mobile screens need markedly different payloads or a single view has to fan out across several backend services, whereas if one clean backend API already matches the screen, running an extra BFF service is just operational overhead.
Draw BFF boundaries along user experience and team lines: a single mobile team shipping lockstep iOS and Android apps can share one BFF, while separate teams moving on independent release schedules are better off with their own.4
See also
Footnotes
- Microsoft. Backends for Frontends pattern. Azure Architecture Center. Context and problem; Solution; Problems and considerations. ↩
- Jorge Creixell. Service Architecture at SoundCloud — Part 1: Backends for Frontends. SoundCloud Backstage, 2021-07-29. Backends for Frontends; The Bad. ↩
- Phil Calçado. The Back-end for Front-end Pattern (BFF). 2015-09-18. The challenges with dogfooding; The Back-end for Front-end Pattern (BFF). ↩
- Sam Newman. Pattern: Backends For Frontends. 2015-11-18. Introducing The Backend For Frontend; How Many BFFs?; And Autonomy. ↩
- Lukasz Plotnicki. BFF @ SoundCloud. Thoughtworks, 2015-12-09. Motivation; Solution; Evolution of a BFF. ↩
- Object Management Group. Unified Modeling Language 2.5.1. December 2017. Components; Interactions. ↩