Backend Engineering: The Five Boundaries I Got Wrong

Every backend bug I have shipped turned out to be the same bug wearing a different costume — a boundary I assumed was enforced when nothing was enforcing it. Five real ones, with the code, the numbers, and the tell that would have caught each of them earlier.

Simone Negro, Backend & AI Developer
9 min read

I have shipped five backend bugs worth writing about. I expected five different lessons. What I got was one lesson five times.

Every single one was a boundary problem: a line I had drawn in the architecture that turned out not to be enforced by anything, or a line I had drawn in the wrong place and then spent effort defending. Not one of them was a performance problem. Not one needed a profiler. Every one of them was visible in the code, without running it, if you knew what to look for.

This is the guide I wish I’d had — organized by the boundary rather than by the technology. The stack is ASP.NET Core and FastAPI, but nothing here is framework trivia.

The claim: in application backends, “where is the boundary and who enforces it” catches more real defects than any amount of design-pattern selection. Each section below names one boundary, shows what happened when I got it wrong, and gives the tell — the thing you can grep for.

1. The process boundary you didn’t mean to draw

I had a Razor Pages frontend and a Web API. Both in the same process, same deploy, same solution. And the Razor Pages called the API over loopback HTTP instead of calling the handler directly.

That is not a small stylistic thing. Once a call leaves the process — even to come straight back — you have to rebuild everything the process gave you for free. Identity was the first casualty: the API expected a cookie, so I wrote a CookieForwardingHandler to forward the browser’s cookie from the app to itself. Then the SignalR hub needed to call the API too, and a hub has no HttpContext, so I stashed the cookie in an AsyncLocal. Two pieces of infrastructure whose only job was to undo a boundary I had invented.

The real cost isn’t latency. It’s that a multi-step operation now spans two HTTP calls with no shared transaction. The wallet top-up wrote a balance and a history row through separate self-calls; if the second failed, nothing rolled back the first.

The tell: you are writing infrastructure whose only purpose is to carry identity, or a transaction, across a boundary that exists inside a single process. That code is not the fix. It is the symptom.

An HTTP API is the right boundary for callers that are genuinely remote — a mobile app, a third party, another service. It is the wrong boundary for a page calling a handler eight lines away. MediatR was already in that codebase; _mediator.Send was always available.

Full write-up: My ASP.NET Core App Called Its Own API Over HTTP.

2. The security boundary that isn’t where the UI is

The same architecture produced a worse bug. The app looked secure from the outside: log in, get a cookie, see your pages. The pages checked authorization properly.

The API did not. app.UseAuthentication() was never called, and no API controller carried [Authorize]. The entire JSON API was open to anyone with curl and a URL.

This is what makes the first boundary mistake dangerous rather than merely ugly. Once the frontend and the API are two independently reachable surfaces, UI-layer authorization and API-layer authorization are two different controls — and one does not imply the other, even when they share a process and a deploy. If a Razor Page can reach an endpoint, so can anyone.

The interesting part was the fix. Turning authentication on broke exactly the callers the first mistake had created: the Razor→API client and the Hub→API client, which now had to carry identity deliberately instead of by accident. And one caller genuinely wasn’t a user — an MQTT handler reacting to hardware — which needed to be explicitly anonymous, with a comment, rather than anonymous by omission.

The tell: count the endpoints that are open to anonymous callers. If the answer is “all of them, because nobody added the attribute”, that is not a policy, it’s an absence. After the fix the number was 2, both intentional and both commented.

Two greps decide this, and they take less time than reading the auth docs:

# 1. is authentication even in the pipeline? no hits = nothing is being checked
rg "UseAuthentication" src/

# 2. which API controllers carry no [Authorize] at all?
rg -l "ApiController" src/ | xargs rg -L "Authorize"

If grep 1 is empty, grep 2 doesn’t matter — every attribute in the codebase is decoration over a pipeline that never authenticates anyone.

Full write-up: The API Had No Lock.

3. The state boundary: whatever the client is holding, you do not own

A user reserved a vehicle for a few minutes. The UI showed a countdown. When it hit zero, the reservation was released.

Except the countdown was the release mechanism. Expiry was driven by client-side JavaScript, and the server-side timer was a singleton service holding one connection ID for the entire application. Two people reserving at once was not a supported state. Closing the tab before the countdown finished left the vehicle reserved forever, because nothing on the server knew the reservation had ever had a deadline.

A countdown a user watches is a display. The moment it is also the only thing enforcing that a resource gets released, a UI affordance has become load-bearing, and the failure modes are the client’s failure modes: closed tabs, dead batteries, aeroplane mode, devtools.

The tell: ask what happens if the browser disappears at the worst possible moment. If the answer requires the browser to still be there, the state is in the wrong place. The fix is boring — a durable, server-owned ExpiresAt, checked independently of any connection. Keep the countdown; demote it to what it always was, a display of a decision the server already made.

Full write-up: Reservation State Can’t Live in a UI Countdown.

4. The seam that hides failure

Not every boundary is a mistake. This one I would draw again.

The same codebase routes every operation through MediatR: one file per command or query, roughly 40 of them, and zero controllers containing business logic beyond _mediator.Send. That seam is a real, durable maintainability win. You do not need a distributed-systems justification to adopt it — “I can find any operation by filename” is enough.

But a seam that organizes code does not, by itself, make failure loud. Two handlers were caught swallowing an exception and returning a fake success. The caller saw a success result. The user saw a confirmation. Nothing had happened.

That is the specific danger of a good seam: it makes every operation look alike from the outside, so a handler that lies looks exactly like a handler that works. The pattern didn’t cause the bug, but it camouflaged it — and the codebase had 0 test files in its scaffolded test project, so nothing else was going to catch it either.

The tell: grep your handlers for catch blocks that don’t rethrow, don’t log, and return a success-shaped result. This is the shape:

public async Task<Result> Handle(CreateRideCommand cmd, CancellationToken ct)
{
    try
    {
        // ...
    }
    catch (Exception)
    {
        return new Result { Success = true };   // the caller will believe this
    }
}

Nothing about that compiles differently from a handler that works. The caller gets Success = true, the controller returns 200, the UI renders a confirmation, and the ride does not exist. Then check whether a single test exercises the failure path — in this codebase the answer was zero. A uniform seam is only as trustworthy as the loudness of its failures.

Full write-up: CQRS with MediatR in a Real ASP.NET Core App: Worth It?.

5. The boundary you don’t control

The last one is the boundary someone else owns: a third-party API. I wrapped a two-step, rate-limited shipping carrier API behind one internal endpoint — token caching, retries, order mapping, the usual.

The happy path in the vendor docs took an afternoon. What took the real time was everything the docs didn’t say. There is an undocumented limit of 4 declared items per international shipment — found by shipping an order that had five. The label URL is an expiring token valid for roughly 12 hours, which quietly means “not a URL you can store in your database and reuse”.

The sandbox, meanwhile, happily accepted requests that production rejected.

The tell: the contract you were handed is a description of the happy path, not of the system. Test against a wide, real sample before you trust an integration, and when the API and its documentation disagree, the API wins. Where you can, make the wrapper the only thing that knows the vendor’s shape — one endpoint your app calls, one place to fix when the vendor surprises you.

Full write-up: Wrapping a Legacy Shipping Carrier API in One Endpoint · engagement scope: Automated Shipping Labels via Poste Delivery Business.

The checklist

Five bugs, five questions. None of them requires running the app:

  1. Process — is any code carrying identity or a transaction across a boundary that lives inside one process? Delete the boundary, not the workaround.
  2. Security — how many endpoints are anonymous by omission rather than by decision? Every reachable surface needs its own control; the UI’s check is not the API’s check.
  3. State — what breaks if the client disappears right now? Anything the server must know later has to live somewhere the server owns.
  4. Failure — do your handlers have a catch that returns success? Does one test exercise the unhappy path?
  5. Third parties — has the integration seen real data, at volume, in production conditions? The docs describe the happy path; the API defines the contract.

Three of the five are greppable before you even open the app:

# 1. a boundary invented inside your own process
rg "HttpClient" src/ | rg -i "localhost|127\.0\.0\.1|BaseAddress"

# 2. authentication that was never switched on
rg "UseAuthentication" src/

# 4. failures that return success
rg -A3 "catch" src/ | rg -i "success = true|return Ok\(\)"

The other two need judgement rather than a regex: whether the client is holding state the server needs (3), and whether the integration has met real data (5).

The through-line: draw boundaries deliberately, and make something enforce each one. An undefended boundary is not an abstraction, it’s an assumption — and assumptions are the things that page you at 2am.

Where this goes next

These five are all application-backend problems. The cluster continues in two directions.

Everything filed under Backend is the ASP.NET Core and integration work — most of it from MobiShare, a shared-mobility platform that has been generous with mistakes.

The other direction is what happens when you put a model behind one of these boundaries: an LLM as a heuristic dispatcher rather than a cloud API wrapper, and a local LLM chatbot with tool-calling and RAG, without a vector database. Same discipline, new failure modes — and that is the wedge I actually care about.