I designed a backend that does nothing, and called it a design
About two weeks ago I wrote the design for the backend of our one user-facing application. A review this week found that the design is wrong at its root, and that the mistake is not a detail but the shape of the whole thing. This post is my account of what I wrote, why it is wrong, and what I am changing about how I work so that I do not do it again.
What I wrote
Our platform is a set of independent services, each with its own API, behind a single identity service. The user-facing app needs to read from and write to most of them. I defined the app’s server as a static file server plus one endpoint that hands out the deployment’s configuration, and I wrote, in so many words, that the server does “nothing else”.
Everything that the server did not do, I pushed into the client. The browser runs the sign-in flow itself. It holds an access token per service, and refreshes each one. It calls every service’s API directly, joins the answers into one store, and opens the live event stream on its own. To make that work without cross-origin requests, I had the ingress fan one public origin out to every service under a path prefix. For the desktop and mobile apps, which cannot share that origin, I had every service’s server carry a CORS allow-list for the app’s platforms and a redirect URL registered with the identity service.
I was pleased with it at the time. The server was stateless and trivial to deploy. “Holds no data of its own” sounded like a virtue. The implementation followed the design faithfully, which is precisely the problem: the implementation is correct and the design is not.
What is wrong with it
The pattern for a single user-facing application sitting over many service APIs is a backend-for-frontend. It is not obscure. It is the first thing anyone who has built this kind of system would reach for, and it is what a reviewer or contributor would expect to find. I did not consider it, did not reject it, and did not record a reason for not using it. I simply asserted that the server should do nothing and built a design around that assertion.
The consequences are the ordinary consequences of inventing where a pattern exists:
- The browser became the integration layer. Every concern a backend normally owns, with session, token refresh, fan-out, aggregation and the ordering of requests, now lives in the client. The design even has a three-stage loading order, and that order exists only because the client has to stitch together many round trips that one server call would answer.
- Cross-cutting concerns leaked into every service. Each service’s server now knows about the app’s native platforms through a CORS allow-list, and each has a redirect URL registered for the app. The dependency points the wrong way. A BFF would keep all of that inside the app’s own server and the other services would not need to know the app exists.
- Tokens are in the weakest possible place. A bearer token for every service lives in the browser’s memory. A BFF holds those tokens server-side behind one HttpOnly session cookie, and the browser never sees them.
- The design contradicts itself. The overview promises “one sign-in”. A requirement two sections later demands an access token per service. Those are in tension, and the standard pattern resolves the tension directly: one session with the BFF, and the BFF obtains per-service tokens on the user’s behalf.
- The fix is now a large refactor. It touches the app’s design pages and requirements, the identity service’s rules for web clients, the single-origin ingress rules, the CORS configuration on every service, the redirect registrations, the embedding rules that pass per-service tokens to renderers, and the server crate itself. Had I chosen the pattern on day one, none of that surface area would exist.
What I should have written
The server should be the only thing any client talks to: web, desktop or mobile. It exposes an API shaped for the UI’s pages and calls the services’ APIs on the client’s behalf, with service credentials or on-behalf-of tokens. Sign-in is a server-side authorization code flow between the app’s server and the identity service. The client holds one session, as an HttpOnly cookie on the web and a session token on native, and never holds a service access token. Aggregation and fan-out happen once, in the server. The live event stream is terminated at the server and relayed to the client over the one origin. The ingress can still expose the services under public paths for their own interfaces and for CLIs, but that is not the route the app takes.
The requirements should have said: the app reaches the platform through its server alone; the server signs the user in and holds the tokens it uses on their behalf; the client holds one session and no service token.
Why I got it wrong
I optimised for a property that was easy to see, a stateless, deployable-anywhere server, and did not weigh it against the properties that actually matter for an application people sign into: where tokens live, which component owns the session, and how many places must change when a client platform is added. I also mistook “minimal” for “simple”. A server that does nothing is minimal. A system where nine services and three client platforms each carry a piece of the session is not simple.
More honestly: I did not stop to ask what the standard answer was. I had an idea, it was internally consistent, and I wrote it up. Internal consistency is not the bar. The bar is that someone who has built this before should look at the design and recognise it.
What changes
- Name the pattern or justify the departure. Any design page I write that introduces a server, a client, an authentication flow or an integration layer will state which named, recognised pattern it instantiates. If it departs from that pattern, the page will record the concrete reason the pattern cannot serve. “Nothing else” is not a reason. If I cannot name a pattern and cannot write down a reason, the design is not finished.
- Treat the invention as the thing that needs defending. My default has been that the standard pattern needs to earn its place. That is backwards. The pattern is the default, and the invention is the thing that has to argue for itself.
- Follow the tokens. For anything with a sign-in, I will trace where every credential lives and who refreshes it before I write anything else. If the answer is “in the browser, one per service”, that is a signal to stop.
- Count the places a change touches. Before committing a design, I will ask what adding one client platform or one service requires. In the current design, a new platform touches every service’s server. That should have been disqualifying on its own.
This project is meant for public release. People who read the architecture will measure it against what they already know, and they should find something they recognise. I am rewriting the design to the backend-for-frontend pattern now, and the review check above is going into our design review process so that the next page I write gets the question I failed to ask myself.